git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 4/4] strbuf: move env-using functions to environment.c

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 1, 2023, 04:37 UTC
Message-ID
<xmqqy1fit7gj.fsf@gitster.g>
In-Reply-To
<4097385820973b30a78f2e45741444a3f6eee98d.1698791220.git.jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
Show 22 quoted lines
> diff --git a/environment.h b/environment.h
> index e5351c9dd9..f801dbe36e 100644
> --- a/environment.h
> +++ b/environment.h
> @@ -229,4 +229,18 @@ extern const char *excludes_file;
>   */
>  int print_sha1_ellipsis(void);
>  
> +/**
> + * Add a formatted string prepended by a comment character and a
> + * blank to the buffer.
> + */
> +__attribute__((format (printf, 2, 3)))
> +void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...);
> +
> +/**
> + * Add a NUL-terminated string to the buffer. Each line will be prepended
> + * by a comment character and a blank.
> + */
> +void strbuf_add_commented_lines(struct strbuf *out,
> +				const char *buf, size_t size);
> +
What's your plans for globals kept in ident.c for example?

The reason why I ask is because I do not quite see how making the use of the global comment-line-char variable hidden like this patch does would help your libification effort. There are many settings that are reasonably expected to be used by many places, and if you want to avoid them, it appears to me that your only way forward after applying this patch would be to recreate the implementation the public git has in environment.[ch] in your version of Git. You'd have to do something similar for what is in ident.c for the same reason.

The relative size of the logic necessary to split the original into lines and prefix the comment prefix character (which is much larger) and the idea that there is a system wide setting of what the comment prefix character should be (which is miniscule) makes me wonder if this is going in the right direction.

Thanks.
Previous: Jonathan Tan
Message 21 of 21 in “Avoid passing global comment_line_char repeatedly”
  1. 0/2 Avoid passing global comment_line_char repeatedlyJunio C Hamano, Oct 30, 2023
  2. 1/2 strbuf_commented_addf(): drop the comment_line_char parameterJunio C Hamano, Oct 30, 2023
  3. 2/2 strbuf_add_commented_lines(): drop the comment_line_char parameterJunio C Hamano, Oct 30, 2023
  4. Dragan SimicOct 30, 2023
  5. Phillip WoodOct 30, 2023
  6. 0/3 Avoid passing global comment_line_char repeatedlyJonathan Tan, Oct 30, 2023
  7. 1/3 strbuf: make add_lines() publicJonathan Tan, Oct 30, 2023
  8. Junio C HamanoOct 30, 2023
  9. Junio C HamanoOct 31, 2023
  10. 2/3 strbuf_commented_addf(): drop the comment_line_char parameterJonathan Tan, Oct 30, 2023
  11. Junio C HamanoOct 31, 2023
  12. Jonathan TanOct 31, 2023
  13. Junio C HamanoOct 31, 2023
  14. 3/3 strbuf_add_commented_lines(): drop the comment_line_char parameterJonathan Tan, Oct 30, 2023
  15. 0/4 Avoid passing global comment_line_char repeatedlyJonathan Tan, Oct 31, 2023
  16. 1/4 strbuf_commented_addf(): drop the comment_line_char parameterJonathan Tan, Oct 31, 2023
  17. 2/4 strbuf_add_commented_lines(): drop the comment_line_char parameterJonathan Tan, Oct 31, 2023
  18. 3/4 strbuf: make add_lines() publicJonathan Tan, Oct 31, 2023
  19. Junio C HamanoNov 1, 2023
  20. 4/4 strbuf: move env-using functions to environment.cJonathan Tan, Oct 31, 2023
  21. Junio C HamanoNov 1, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.