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

Re: [GSoC PATCH 1/2] repo: add the flag -z as an alias for --format=nul

From
Karthik Nayak <karthik.188@gmail.com>
Date
Aug 21, 2025, 10:12 UTC
Message-ID
<CAOLa=ZQZCUsa7M0mh1oCq8hhBZS05=jw4y2Lr1r3rPe0-ajbhw@mail.gmail.com>
In-Reply-To
<20250820144247.79197-2-lucasseikioshiro@gmail.com>
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> writes:
Show 27 quoted lines
> Other Git commands that have nul-terminated output (e.g. git-config,
> git-status, git-ls-files) have a flag `-z` for using the null character
> as the record separator.
>
> Add the `-z` flag to git-repo-info as an alias for `--format=nul`,
> making it consistent with the behavior of the other commands.
>
> Mentored-by: Karthik Nayak <karthik.188@gmail.com>
> Mentored-by: Patrick Steinhardt <ps@pks.im>
> Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
> ---
>  Documentation/git-repo.adoc |  6 ++++--
>  builtin/repo.c              | 17 ++++++++++++-----
>  t/t1900-repo.sh             | 12 ++++++++++++
>  3 files changed, 28 insertions(+), 7 deletions(-)
>
> diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
> index 2870828d93..f2dc71193c 100644
> --- a/Documentation/git-repo.adoc
> +++ b/Documentation/git-repo.adoc
> @@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
>  SYNOPSIS
>  --------
>  [synopsis]
> -git repo info [--format=(keyvalue|nul)] [<key>...]
> +git repo info [--format=(keyvalue|nul)|-z] [<key>...]
>
Nit: Perhaps we can leave a space around '|' to make it easier to read?
Show 88 quoted lines
>  DESCRIPTION
>  -----------
> @@ -18,7 +18,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
>
>  COMMANDS
>  --------
> -`info [--format=(keyvalue|nul)] [<key>...]`::
> +`info [--format=(keyvalue|nul)|-z] [<key>...]`::
>  	Retrieve metadata-related information about the current repository. Only
>  	the requested data will be returned based on their keys (see "INFO KEYS"
>  	section below).
> @@ -40,6 +40,8 @@ supported:
>  	between the key and the value and using a NUL character after each value.
>  	This format is better suited for being parsed by another applications than
>  	`keyvalue`. Unlike in the `keyvalue` format, the values are never quoted.
> ++
> +`-z` is an alias for `--format=nul`.
>
>  INFO KEYS
>  ---------
> diff --git a/builtin/repo.c b/builtin/repo.c
> index 8c6e7f42ab..b2ec66e454 100644
> --- a/builtin/repo.c
> +++ b/builtin/repo.c
> @@ -9,7 +9,7 @@
>  #include "shallow.h"
>
>  static const char *const repo_usage[] = {
> -	"git repo info [--format=(keyvalue|nul)] [<key>...]",
> +	"git repo info [--format=(keyvalue|nul)|-z] [<key>...]",
>  	NULL
>  };
>
> @@ -115,20 +115,27 @@ static int print_fields(int argc, const char **argv,
>  static int repo_info(int argc, const char **argv, const char *prefix,
>  		     struct repository *repo)
>  {
> -	const char *format_str = "keyvalue";
> +	const char *format_str = NULL;
>  	enum output_format format;
> +	int format_nul = 0;
>  	struct option options[] = {
>  		OPT_STRING(0, "format", &format_str, N_("format"),
>  			   N_("output format")),
> +		OPT_BOOL('z', NULL, &format_nul, N_("alias for --format=nul")),
>  		OPT_END()
>  	};
>
>  	argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
>
> -	if (!strcmp(format_str, "keyvalue"))
> -		format = FORMAT_KEYVALUE;
> -	else if (!strcmp(format_str, "nul"))
> +	die_for_incompatible_opt2(!!format_nul, "-z",
> +				  !!format_str, "--format");
> +
> +	format_str = format_str ? format_str : "keyvalue";
> +
> +	if (format_nul || !strcmp(format_str, "nul"))
>  		format = FORMAT_NUL_TERMINATED;
> +	else if (!strcmp(format_str, "keyvalue"))
> +		format = FORMAT_KEYVALUE;
>  	else
>  		die(_("invalid format '%s'"), format_str);
>
> diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
> index a69c715357..3df55dcc79 100755
> --- a/t/t1900-repo.sh
> +++ b/t/t1900-repo.sh
> @@ -92,4 +92,16 @@ test_expect_success 'git-repo-info aborts when requesting an invalid format' '
>  	test_cmp expect actual
>  '
>
> +test_expect_success '-z uses nul-terminated format' '
> +	printf "layout.bare\nfalse\0layout.shallow\nfalse\0" >expected &&
> +	git repo info -z layout.bare layout.shallow >actual &&
> +	test_cmp expected actual
> +'
> +
> +test_expect_success 'git repo info fails when using --format and -z' '
> +	echo "fatal: options ${SQ}-z${SQ} and ${SQ}--format${SQ} cannot be used together" >expected &&
> +	test_must_fail git repo info -z --format=keyvalue 2>actual &&
> +	test_cmp expected actual
> +'
> +
>  test_done
> --
> 2.39.5 (Apple Git-154)
The rest looks good.
Previous: Lucas Seiki OshiroNext: Junio C Hamano
Message 3 of 37 in “repo: add -z and objects.format”
  1. 0/2 repo: add -z and objects.formatLucas Seiki Oshiro, Aug 20, 2025
  2. 1/2 repo: add the flag -z as an alias for --format=nulLucas Seiki Oshiro, Aug 20, 2025
  3. Karthik NayakAug 21, 2025
  4. Junio C HamanoAug 21, 2025
  5. Karthik NayakAug 21, 2025
  6. Patrick SteinhardtAug 21, 2025
  7. Lucas Seiki OshiroAug 21, 2025
  8. Junio C HamanoAug 21, 2025
  9. Lucas Seiki OshiroAug 21, 2025
  10. Junio C HamanoAug 21, 2025
  11. Jean-Noël AVILAAug 21, 2025
  12. Junio C HamanoAug 21, 2025
  13. 2/2 repo: add the field objects.formatLucas Seiki Oshiro, Aug 20, 2025
  14. Patrick SteinhardtAug 21, 2025
  15. Junio C HamanoAug 21, 2025
  16. Lucas Seiki OshiroAug 26, 2025
  17. Karthik NayakAug 21, 2025
  18. Junio C HamanoAug 21, 2025
  19. Patrick SteinhardtAug 21, 2025
  20. Lucas Seiki OshiroAug 21, 2025
  21. Patrick SteinhardtAug 21, 2025
  22. Junio C HamanoAug 21, 2025
  23. Lucas Seiki OshiroAug 26, 2025
  24. 0/2 repo: add -z and objects.formatLucas Seiki Oshiro, Aug 26, 2025
  25. 1/2 repo: add the flag -z as an alias for --format=nulLucas Seiki Oshiro, Aug 26, 2025
  26. Junio C HamanoAug 28, 2025
  27. Lucas Seiki OshiroSep 1, 2025
  28. 2/2 repo: add the field objects.formatLucas Seiki Oshiro, Aug 26, 2025
  29. 0/2 repo: add -z and objects.formatLucas Seiki Oshiro, Sep 1, 2025
  30. 1/2 repo: add the flag -z as an alias for --format=nulLucas Seiki Oshiro, Sep 1, 2025
  31. Junio C HamanoSep 2, 2025
  32. Lucas Seiki OshiroSep 2, 2025
  33. 2/2 repo: add the field objects.formatLucas Seiki Oshiro, Sep 1, 2025
  34. 0/2 repo: add -z and objects.formatLucas Seiki Oshiro, Sep 4, 2025
  35. 1/2 repo: add the flag -z as an alias for --format=nulLucas Seiki Oshiro, Sep 4, 2025
  36. 2/2 repo: add the field objects.formatLucas Seiki Oshiro, Sep 4, 2025
  37. Junio C HamanoSep 4, 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.