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

Re: [PATCH v4 1/2] repo: factor out field printing to dedicated function

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 17, 2025, 18:48 UTC
Message-ID
<xmqqldk4ijgd.fsf@gitster.g>
In-Reply-To
<20251117151844.14802-2-lucasseikioshiro@gmail.com>
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
> Move the field printing in git-repo-info to a new function called
> `print_field`, allowing it to be called by functions other than
> `print_fields`.
Missing:
    Also change its use of quote_c_style() helper to output directly to
    the standard output stream, instead of taking a result in a strbuf
    and then printing it outselves.
The patch text looks great.
Show 66 quoted lines
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> ---
>  builtin/repo.c | 34 ++++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/builtin/repo.c b/builtin/repo.c
> index 9d4749f79b..f9fb418494 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -85,13 +85,29 @@ static get_value_fn *get_value_fn_for_key(const char *key)
>  	return found ? found->get_value : NULL;
>  }
>  
> +static void print_field(enum output_format format, const char *key,
> +			const char *value)
> +{
> +	switch (format) {
> +	case FORMAT_KEYVALUE:
> +		printf("%s=", key);
> +		quote_c_style(value, NULL, stdout, 0);
> +		putchar('\n');
> +		break;
> +	case FORMAT_NUL_TERMINATED:
> +		printf("%s\n%s%c", key, value, '\0');
> +		break;
> +	default:
> +		BUG("not a valid output format: %d", format);
> +	}
> +}
> +
>  static int print_fields(int argc, const char **argv,
>  			struct repository *repo,
>  			enum output_format format)
>  {
>  	int ret = 0;
>  	struct strbuf valbuf = STRBUF_INIT;
> -	struct strbuf quotbuf = STRBUF_INIT;
>  
>  	for (int i = 0; i < argc; i++) {
>  		get_value_fn *get_value;
> @@ -105,25 +121,11 @@ static int print_fields(int argc, const char **argv,
>  		}
>  
>  		strbuf_reset(&valbuf);
> -		strbuf_reset(&quotbuf);
> -
>  		get_value(repo, &valbuf);
> -
> -		switch (format) {
> -		case FORMAT_KEYVALUE:
> -			quote_c_style(valbuf.buf, &quotbuf, NULL, 0);
> -			printf("%s=%s\n", key, quotbuf.buf);
> -			break;
> -		case FORMAT_NUL_TERMINATED:
> -			printf("%s\n%s%c", key, valbuf.buf, '\0');
> -			break;
> -		default:
> -			BUG("not a valid output format: %d", format);
> -		}
> +		print_field(format, key, valbuf.buf);
>  	}
>  
>  	strbuf_release(&valbuf);
> -	strbuf_release(&quotbuf);
>  	return ret;
>  }
Previous: Lucas Seiki OshiroNext: Lucas Seiki Oshiro
Message 17 of 30 in “repo: add --all to git-repo-info”
  1. repo: add --all to git-repo-infoLucas Seiki Oshiro, Sep 15, 2025
  2. Junio C HamanoSep 15, 2025
  3. Patrick SteinhardtSep 16, 2025
  4. Junio C HamanoSep 16, 2025
  5. Patrick SteinhardtSep 17, 2025
  6. 0/2 repo: add --all to git-repo-infoLucas Seiki Oshiro, Oct 26, 2025
  7. 1/2 repo: factor out field printing to dedicated functionLucas Seiki Oshiro, Oct 26, 2025
  8. Eric SunshineOct 26, 2025
  9. Eric SunshineOct 26, 2025
  10. Junio C HamanoOct 27, 2025
  11. Eric SunshineOct 27, 2025
  12. 2/2 repo: add --all to git-repo-infoLucas Seiki Oshiro, Oct 26, 2025
  13. Eric SunshineOct 27, 2025
  14. Eric SunshineOct 27, 2025
  15. 0/2 repo: add --all to git-repo-infoLucas Seiki Oshiro, Nov 17, 2025
  16. 1/2 repo: factor out field printing to dedicated functionLucas Seiki Oshiro, Nov 17, 2025
  17. Junio C HamanoNov 17, 2025
  18. 2/2 repo: add --all to git-repo-infoLucas Seiki Oshiro, Nov 17, 2025
  19. Junio C HamanoNov 17, 2025
  20. Lucas Seiki OshiroNov 18, 2025
  21. Junio C HamanoNov 18, 2025
  22. Lucas Seiki OshiroNov 20, 2025
  23. Eric SunshineNov 19, 2025
  24. Junio C HamanoNov 19, 2025
  25. Junio C HamanoNov 17, 2025
  26. 0/2 repo: add --all to git-repo-infoLucas Seiki Oshiro, Nov 18, 2025
  27. 1/2 repo: factor out field printing to dedicated functionLucas Seiki Oshiro, Nov 18, 2025
  28. 2/2 repo: add --all to git-repo-infoLucas Seiki Oshiro, Nov 18, 2025
  29. Junio C HamanoNov 18, 2025
  30. Eric SunshineNov 19, 2025

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.