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

Re: [RFC PATCH 2/3] strbuf_commented_addf(): drop the comment_line_char parameter

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 31, 2023, 05:19 UTC
Message-ID
<xmqqh6m74bdo.fsf@gitster.g>
In-Reply-To
<bb01336233b30d46960d6eb15f036e6346a9cd2b.1698696798.git.jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
Show 10 quoted lines
> From: Junio C Hamano <gitster@pobox.com>
>
> All the callers of this function supply the global variable
> comment_line_char as an argument to its second parameter.  Remove
> the parameter to allow us in the future to change the reference to
> the global variable with something else, like a function call.
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
> ---
Show 26 quoted lines
> diff --git a/environment.c b/environment.c
> index bb3c2a96a3..d9f64cffa0 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -416,3 +416,21 @@ int print_sha1_ellipsis(void)
>  	}
>  	return cached_result;
>  }
> +
> +void strbuf_commented_addf(struct strbuf *sb,
> +			   const char *fmt, ...)
> +{
> +	va_list params;
> +	struct strbuf buf = STRBUF_INIT;
> +	int incomplete_line = sb->len && sb->buf[sb->len - 1] != '\n';
> +
> +	va_start(params, fmt);
> +	strbuf_vaddf(&buf, fmt, params);
> +	va_end(params);
> +
> +	strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_line_char);
> +	if (incomplete_line)
> +		sb->buf[--sb->len] = '\0';
> +
> +	strbuf_release(&buf);
> +}

This moving of the helper function does not belong to the "fix commented_addf() not to take the comment_line_char" step.

The series should be restructured to have the two patches from me first, and then your moving some stuff to environment.c, probably.

Previous: Jonathan TanNext: Jonathan Tan
Message 11 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.