Skip to contentSkip to conversation

repo: add -z as an alias for --format=nul to git-repo-structure

PATCH Superseded Lucas Seiki Oshiro 4 participants 15 messages Nov 30, 2025 – Dec 18, 2025 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 repo: add -z as an alias for --format=nul to git-repo-structure

Other Git commands that have nul-terminated output, such as git-config, git-status, git-ls-files, and git-repo-info have a flag -z for using the null character as the record separator.

Add the -z flag to git-repo-structure as an alias for --format=nul, making it consistent with the behavior of the other commands.

---

Hello, again!

Since git-repo-info and git-repo-structure share the same format parser, this could be done by only copying the OPT_CALLBACK_F from repo_info.

I'm cc'ing Justin here, as he was the author of git-repo-structure.

This patch is based on top of master b31ab939fe (The fourth batch, 2025-11-26) with lo/repo-info-all merged.

 Documentation/git-repo.adoc | 5 +++--
 builtin/repo.c              | 6 +++++-
 t/t1901-repo-structure.sh   | 6 ++++++
 3 files changed, 14 insertions(+), 3 deletions(-)
Documentation/git-repo.adoc +3 -2
index 70f0a6d2e4..8820954f7e 100644
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [synopsis]
 git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
-git repo structure [--format=(table|keyvalue|nul)]
+git repo structure [--format=(table|keyvalue|nul)] [-z]
 
 DESCRIPTION
 -----------
@@ -44,7 +44,7 @@ supported:
 +
 `-z` is an alias for `--format=nul`.
 
-`structure [--format=(table|keyvalue|nul)]`::
+`structure [--format=(table|keyvalue|nul)] [-z]`::
 	Retrieve statistics about the current repository structure. The
 	following kinds of information are reported:
 +
@@ -72,6 +72,7 @@ supported:
 	the delimiter between the key and value instead of '='. Unlike the
 	`keyvalue` format, values containing "unusual" characters are never
 	quoted.
+`-z` is an alias for `--format=nul`.
 
 INFO KEYS
 ---------
builtin/repo.c +5 -1
index 2a653bd3ea..1c06207a39 100644
@@ -16,7 +16,7 @@
 
 static const char *const repo_usage[] = {
 	"git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
-	"git repo structure [--format=(table|keyvalue|nul)]",
+	"git repo structure [--format=(table|keyvalue|nul)] [-z]",
 	NULL
 };
 
@@ -529,6 +529,10 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
 			       N_("output format"),
 			       PARSE_OPT_NONEG, parse_format_cb),
+		OPT_CALLBACK_F('z', NULL, &format, NULL,
+			       N_("synonym for --format=nul"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+			       parse_format_cb),
 		OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
 		OPT_END()
 	};
t/t1901-repo-structure.sh +6 -0
index 36a71a144e..5a50acf345 100755
@@ -101,6 +101,12 @@ test_expect_success 'keyvalue and nul format' '
 		tr "\n=" "\0\n" <expect >expect_nul &&
 		git repo structure --format=nul >out 2>err &&
 
+		test_cmp expect_nul out &&
+		test_line_count = 0 err &&
+
+		# Check -z
+		git repo structure --format=nul >out 2>err &&
+
 		test_cmp expect_nul out &&
 		test_line_count = 0 err
 	)
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

Documentation/git-repo.adoc SYNOPSIS · line 12

Quoted 2 lines · Lucas Seiki Oshiro
Documentation/git-repo.adoc +1 -1
-git repo structure [--format=(table|keyvalue|nul)]
+git repo structure [--format=(table|keyvalue|nul)] [-z]

It's a minor thing but I wonder if this should be more like

git repo structure [--format=(table|keyvalue|nul) | -z]

t/t1901-repo-structure.sh test_expect_success 'keyvalue and nul format' ' · line 108

Quoted 13 lines
t/t1901-repo-structure.sh +5 -0
index 36a71a144e..5a50acf345 100755
@@ -101,6 +101,12 @@ test_expect_success 'keyvalue and nul format' '
 		tr "\n=" "\0\n" <expect >expect_nul &&
 		git repo structure --format=nul >out 2>err &&
 
+		test_cmp expect_nul out &&
+		test_line_count = 0 err &&
+
+		# Check -z
+		git repo structure --format=nul >out 2>err &&

Didn't you want to check "-z", not "--format=nul"? In addition, perhaps test

# "-z", as a synonym to "--format=nul", participates in the # usual "last one wins" rule.
git repo structure --format=table -z >out 2>err &&

as well, or is it too obvious (by knowing how parse-options API is used) that it is pointless to test?

Quoted 3 lines
t/t1901-repo-structure.sh +0 -0
 		test_cmp expect_nul out &&
 		test_line_count = 0 err
 	)
#2 lore raw
Quoted 8 lines · Junio C Hamano

Documentation/git-repo.adoc SYNOPSIS · line 12

Quoted 2 lines · Lucas Seiki Oshiro
Documentation/git-repo.adoc +1 -1
-git repo structure [--format=(table|keyvalue|nul)]
+git repo structure [--format=(table|keyvalue|nul)] [-z]

It's a minor thing but I wonder if this should be more like

git repo structure [--format=(table|keyvalue|nul) | -z]

This discussion rings a bell -- didn't we already discuss this for git repo info? Yup, indeed [1]. Initial versions of git repo info -z` also had it formatted like the above, but the discussion eventually led to a version that is the same as the one proposed in this patch here.

I think this ultimately stems from [2], where you argue that it _is_ possible to say git repo info --format=table -z, and the last option wins. It's the same for git repo structure, so I'd argue we should be consistent.

[1]: <[email protected]> [2]: <[email protected]>

Quoted 17 lines

t/t1901-repo-structure.sh test_expect_success 'keyvalue and nul format' ' · line 108

Quoted 13 lines
t/t1901-repo-structure.sh +5 -0
index 36a71a144e..5a50acf345 100755
@@ -101,6 +101,12 @@ test_expect_success 'keyvalue and nul format' '
 		tr "\n=" "\0\n" <expect >expect_nul &&
 		git repo structure --format=nul >out 2>err &&
 
+		test_cmp expect_nul out &&
+		test_line_count = 0 err &&
+
+		# Check -z
+		git repo structure --format=nul >out 2>err &&

Didn't you want to check "-z", not "--format=nul"? In addition, perhaps test

Quoted 6 lines

# "-z", as a synonym to "--format=nul", participates in the # usual "last one wins" rule.
git repo structure --format=table -z >out 2>err &&

as well, or is it too obvious (by knowing how parse-options API is used) that it is pointless to test?

I think it wouldn't be pointless given the above -- we should verify that the last one wins, regardless of whether you use the alias or the long option.

Patrick

#3 lore raw
Quoted 5 lines

I think this ultimately stems from [2], where you argue that it _is_ possible to say git repo info --format=table -z, and the last option wins. It's the same for git repo structure, so I'd argue we should be consistent.

Yeah, I agree. I'm also ok with [--format ... | -z], but given that this argument parsing git-repo-stucture is the same from git-repo-info, it wouldn't make sense that their synopses differ.

#4 lore raw
In reply to Patrick Steinhardt
Quoted 4 lines · Patrick Steinhardt

I think this ultimately stems from [2], where you argue that it _is_ possible to say git repo info --format=table -z, and the last option wins. It's the same for git repo structure, so I'd argue we should be consistent.

I do not think so; [2] was about the explicit "--format=nul and -z are incompatible" code. Even without this '-z" thing, if you have

    [--opt=(a|b|c)]

I _think_ our intention is to allow "git cmd --opt=a --opt=b" from the user and let the last one win. If you add "-z",

    [--format=(table|keyvalue|nul)] [-z]
    [--format=(table|keyvalue|nul) | -z]

I think both would mean the same thing; I just was wonering if grouping them together in one bracket makes it more obvious that these are all options to control the output format.

There was also an inquiry about writing it like

    [(--format=(table|keyvalue|nul) | -z)]

or even

    [(--format=(table|keyvalue|nul) | -z)...]

as these can be repeated and let the last-one-wins rule decide the final outcome, but we do not do that. I thought the final comment on this was in

https://lore.kernel.org/git/6186055.lOV4Wx5bFT@cayenne/

where the message said

    In fact the correct formatting is:

    [--format=(keyvalue|nul) | -z] [<key>...]

    As stated in "CodingGuidelines:

     Use spacing around "|" token(s), but not immediately after opening or
     before closing a [] or () pair:
       Do: [-q | --quiet]
       Don't: [-q|--quiet]

     Don't use spacing around "|" tokens when they're used to separate the
     alternate arguments of an option:
        Do: --track[=(direct|inherit)]
        Don't: --track[=(direct | inherit)]

and that was where the thread ended, I think.

Quoted 2 lines

[1]: <[email protected]> [2]: <[email protected]>

#5 lore raw
Quoted 4 lines

I thought the final comment on this was in

https://lore.kernel.org/git/6186055.lOV4Wx5bFT@cayenne/

Actually, the final comment was [1], after the version where I use [--format=...] [-z].

But actually, I don't have a strong opinion on using | -z vs using [-z], since both work here, but if | -z looks clearer, I can change it in the next version. However, I'll do that for both repo-info and repo-structure, since --format is parsed by the same function in both of them.

[1]: <[email protected] <mailto:[email protected]>>

#6 lore raw
In reply to Lucas Seiki Oshiro
Quoted 8 lines · Lucas Seiki Oshiro

Other Git commands that have nul-terminated output, such as git-config, git-status, git-ls-files, and git-repo-info have a flag -z for using the null character as the record separator.

Add the -z flag to git-repo-structure as an alias for --format=nul, making it consistent with the behavior of the other commands.

Quoted 8 lines

---

Hello, again!

Since git-repo-info and git-repo-structure share the same format parser, this could be done by only copying the OPT_CALLBACK_F from repo_info.

I'm cc'ing Justin here, as he was the author of git-repo-structure.

Thanks Lucas, looks like you beat me to this change. :)

Quoted 2 lines

This patch is based on top of master b31ab939fe (The fourth batch, 2025-11-26) with lo/repo-info-all merged.

Any reason this isn't just based on master? It looks like this patch should apply just fine as I don't see any dependencies.

Quoted 28 lines
 Documentation/git-repo.adoc | 5 +++--
 builtin/repo.c              | 6 +++++-
 t/t1901-repo-structure.sh   | 6 ++++++
 3 files changed, 14 insertions(+), 3 deletions(-)
Documentation/git-repo.adoc +2 -2
index 70f0a6d2e4..8820954f7e 100644
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [synopsis]
 git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
-git repo structure [--format=(table|keyvalue|nul)]
+git repo structure [--format=(table|keyvalue|nul)] [-z]
 
 DESCRIPTION
 -----------
@@ -44,7 +44,7 @@ supported:
 +
 `-z` is an alias for `--format=nul`.
 
-`structure [--format=(table|keyvalue|nul)]`::
+`structure [--format=(table|keyvalue|nul)] [-z]`::
 	Retrieve statistics about the current repository structure. The
 	following kinds of information are reported:
 +

Documentation/git-repo.adoc supported: · line 75

Quoted 4 lines
Documentation/git-repo.adoc +1 -0
@@ -72,6 +72,7 @@ supported:
 	the delimiter between the key and value instead of '='. Unlike the
 	`keyvalue` format, values containing "unusual" characters are never
 	quoted.
+`-z` is an alias for `--format=nul`.

If we want to match the format in the section prior, we should add a '+' character on the prior line to separate the sections. With how it is written now, this line will just be appeneded to the previous section.

Quoted 16 lines
Documentation/git-repo.adoc +0 -0
 INFO KEYS
 ---------
builtin/repo.c +1 -1
index 2a653bd3ea..1c06207a39 100644
@@ -16,7 +16,7 @@
 
 static const char *const repo_usage[] = {
 	"git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
-	"git repo structure [--format=(table|keyvalue|nul)]",
+	"git repo structure [--format=(table|keyvalue|nul)] [-z]",
 	NULL
 };
 

builtin/repo.c static int cmd_repo_structure(int argc, const char **argv, const char *prefix, · line 535

Quoted 7 lines
builtin/repo.c +4 -0
@@ -529,6 +529,10 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
 			       N_("output format"),
 			       PARSE_OPT_NONEG, parse_format_cb),
+		OPT_CALLBACK_F('z', NULL, &format, NULL,
+			       N_("synonym for --format=nul"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+			       parse_format_cb),

Reusing the same parse_format_cb() makes sense and also matches what we do with git-repo-info. Looks good.

Quoted 8 lines
builtin/repo.c +0 -0
 		OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
 		OPT_END()
 	};
t/t1901-repo-structure.sh +0 -0
index 36a71a144e..5a50acf345 100755

t/t1901-repo-structure.sh test_expect_success 'keyvalue and nul format' ' · line 108

Quoted 8 lines
t/t1901-repo-structure.sh +5 -0
@@ -101,6 +101,12 @@ test_expect_success 'keyvalue and nul format' '
 		tr "\n=" "\0\n" <expect >expect_nul &&
 		git repo structure --format=nul >out 2>err &&
 
+		test_cmp expect_nul out &&
+		test_line_count = 0 err &&
+
+		# Check -z
+		git repo structure --format=nul >out 2>err &&

Did you mean to use the -z option here?

-Justin

#7 lore raw

Hi!

Quoted 5 lines
Quoted 2 lines

This patch is based on top of master b31ab939fe (The fourth batch, 2025-11-26) with lo/repo-info-all merged.

Any reason this isn't just based on master? It looks like this patch should apply just fine as I don't see any dependencies.

Yesterday, lo/repo-info-all wasn't merged yet to master :-)

Quoted 2 lines

Reusing the same parse_format_cb() makes sense and also matches what we do with git-repo-info. Looks good.

Yes, this callback is used by both subcommands, this was a really straightforward change.

Quoted 1 line

Did you mean to use the -z option here?

Ooops, yes, sorry. I'll fix it.

#8 lore raw

v2 cover repo: add -z as an alias for --format=nul to git-repo-structure

In reply to Lucas Seiki Oshiro

Hi!

The main objective of this patchset is to add -z to git-repo-structure as an alias for --format=nul. I'm including two other related patches here:

- a patch removing an extra line in the documentation, which was leaking an + to the generated files

- a patch replacing [--format=...] [-z] by [--format=... | -z] in git-repo-info's synopsis

Lucas Seiki Oshiro (3):
repo: remove blank line from Documentation/git-repo.adoc
repo: use [--format=... | -z] instead of [-z] in git-repo-info
synopsis
repo: add -z as an alias for --format=nul to git-repo-structure

 Documentation/git-repo.adoc | 11 ++++++-----
 builtin/repo.c              |  8 ++++++--
 t/t1901-repo-structure.sh   |  7 +++++++
 3 files changed, 19 insertions(+), 7 deletions(-)

Range-diff against v1:

-:  ---------- > 1:  bfd4ff5db0 repo: remove blank line from Documentation/git-repo.adoc
-:  ---------- > 2:  e5eac8713c repo: use [--format=... | -z] instead of [-z] in git-repo-info synopsis
1:  f051cd41de ! 3:  0ccec7037d repo: add -z as an alias for --format=nul to git-repo-structure
    @@ Documentation/git-repo.adoc
     @@ Documentation/git-repo.adoc: SYNOPSIS
      --------
      [synopsis]
    - git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
    + git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
     -git repo structure [--format=(table|keyvalue|nul)]
    -+git repo structure [--format=(table|keyvalue|nul)] [-z]
    ++git repo structure [--format=(table|keyvalue|nul) | -z]
      
      DESCRIPTION
      -----------
    @@ Documentation/git-repo.adoc: supported:
      `-z` is an alias for `--format=nul`.
      
     -`structure [--format=(table|keyvalue|nul)]`::
    -+`structure [--format=(table|keyvalue|nul)] [-z]`::
    ++`structure [--format=(table|keyvalue|nul) | -z]`::
      	Retrieve statistics about the current repository structure. The
      	following kinds of information are reported:
      +
    @@ Documentation/git-repo.adoc: supported:
      	the delimiter between the key and value instead of '='. Unlike the
      	`keyvalue` format, values containing "unusual" characters are never
      	quoted.
    +++
     +`-z` is an alias for `--format=nul`.
      
      INFO KEYS
    @@ builtin/repo.c
     @@
      
      static const char *const repo_usage[] = {
    - 	"git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
    + 	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
     -	"git repo structure [--format=(table|keyvalue|nul)]",
    -+	"git repo structure [--format=(table|keyvalue|nul)] [-z]",
    ++	"git repo structure [--format=(table|keyvalue|nul) | -z]",
      	NULL
      };
      
    @@ t/t1901-repo-structure.sh: test_expect_success 'keyvalue and nul format' '
     +		test_cmp expect_nul out &&
     +		test_line_count = 0 err &&
     +
    -+		# Check -z
    -+		git repo structure --format=nul >out 2>err &&
    ++		# "-z", as a synonym to "--format=nul", participates in the
    ++		# usual "last one wins" rule.
    ++		git repo structure --format=table -z >out 2>err &&
     +
      		test_cmp expect_nul out &&
      		test_line_count = 0 err
Signature · 1 line
2.50.1 (Apple Git-155)
#9 lore raw

PATCH v2 1/3 repo: remove blank line from Documentation/git-repo.adoc

There was an extra blank line in git-repo-structure documentation, which led to an unwawnted '+' character after generating an HTML or PDF from that page. This can be seen, for example, in Git 2.52.0 online docs [1].

Remove that extra line.

[1] https://git-scm.com/docs/git-repo/2.52.0

---
 Documentation/git-repo.adoc | 1 -
 1 file changed, 1 deletion(-)
Documentation/git-repo.adoc +0 -1
index 70f0a6d2e4..5d9c7641c2 100644
@@ -50,7 +50,6 @@ supported:
 +
 * Reference counts categorized by type
 * Reachable object counts categorized by type
-
 +
 The output format can be chosen through the flag `--format`. Three formats are
 supported:
Signature · 1 line
2.50.1 (Apple Git-155)
#10 lore raw

PATCH v2 2/3 repo: use [--format=... | -z] instead of [-z] in git-repo-info synopsis

In reply to Lucas Seiki Oshiro

The flag -z is only an alias for --format=null and even though --format and -z can be used together and repeated, only the last one is considered.

Replace [-z] in the synopsis of git-repo-info by [--format=... | -z], expliciting that the use of one of those flags replace the other.

---
 Documentation/git-repo.adoc | 4 ++--
 builtin/repo.c              | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
Documentation/git-repo.adoc +2 -2
index 5d9c7641c2..f24514deaa 100644
@@ -8,7 +8,7 @@ git-repo - Retrieve information about the repository
 SYNOPSIS
 --------
 [synopsis]
-git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]
+git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
 git repo structure [--format=(table|keyvalue|nul)]
 
 DESCRIPTION
@@ -19,7 +19,7 @@ THIS COMMAND IS EXPERIMENTAL. THE BEHAVIOR MAY CHANGE.
 
 COMMANDS
 --------
-`info [--format=(keyvalue|nul)] [-z] [--all | <key>...]`::
+`info [--format=(keyvalue|nul) | -z] [--all | <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).
builtin/repo.c +1 -1
index 2a653bd3ea..cc97dd1836 100644
@@ -15,7 +15,7 @@
 #include "utf8.h"
 
 static const char *const repo_usage[] = {
-	"git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]",
+	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
 	"git repo structure [--format=(table|keyvalue|nul)]",
 	NULL
 };
Signature · 1 line
2.50.1 (Apple Git-155)
#11 lore raw

PATCH v2 3/3 repo: add -z as an alias for --format=nul to git-repo-structure

In reply to Lucas Seiki Oshiro

Other Git commands that have nul-terminated output, such as git-config, git-status, git-ls-files, and git-repo-info have a flag -z for using the null character as the record separator.

Add the -z flag to git-repo-structure as an alias for --format=nul, making it consistent with the behavior of the other commands.

---
 Documentation/git-repo.adoc | 6 ++++--
 builtin/repo.c              | 6 +++++-
 t/t1901-repo-structure.sh   | 7 +++++++
 3 files changed, 16 insertions(+), 3 deletions(-)
Documentation/git-repo.adoc +4 -2
index f24514deaa..c4a78277df 100644
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [synopsis]
 git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
-git repo structure [--format=(table|keyvalue|nul)]
+git repo structure [--format=(table|keyvalue|nul) | -z]
 
 DESCRIPTION
 -----------
@@ -44,7 +44,7 @@ supported:
 +
 `-z` is an alias for `--format=nul`.
 
-`structure [--format=(table|keyvalue|nul)]`::
+`structure [--format=(table|keyvalue|nul) | -z]`::
 	Retrieve statistics about the current repository structure. The
 	following kinds of information are reported:
 +
@@ -71,6 +71,8 @@ supported:
 	the delimiter between the key and value instead of '='. Unlike the
 	`keyvalue` format, values containing "unusual" characters are never
 	quoted.
++
+`-z` is an alias for `--format=nul`.
 
 INFO KEYS
 ---------
builtin/repo.c +5 -1
index cc97dd1836..0dd41b1778 100644
@@ -16,7 +16,7 @@
 
 static const char *const repo_usage[] = {
 	"git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
-	"git repo structure [--format=(table|keyvalue|nul)]",
+	"git repo structure [--format=(table|keyvalue|nul) | -z]",
 	NULL
 };
 
@@ -529,6 +529,10 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
 		OPT_CALLBACK_F(0, "format", &format, N_("format"),
 			       N_("output format"),
 			       PARSE_OPT_NONEG, parse_format_cb),
+		OPT_CALLBACK_F('z', NULL, &format, NULL,
+			       N_("synonym for --format=nul"),
+			       PARSE_OPT_NONEG | PARSE_OPT_NOARG,
+			       parse_format_cb),
 		OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
 		OPT_END()
 	};
t/t1901-repo-structure.sh +7 -0
index 36a71a144e..df7d4ea524 100755
@@ -101,6 +101,13 @@ test_expect_success 'keyvalue and nul format' '
 		tr "\n=" "\0\n" <expect >expect_nul &&
 		git repo structure --format=nul >out 2>err &&
 
+		test_cmp expect_nul out &&
+		test_line_count = 0 err &&
+
+		# "-z", as a synonym to "--format=nul", participates in the
+		# usual "last one wins" rule.
+		git repo structure --format=table -z >out 2>err &&
+
 		test_cmp expect_nul out &&
 		test_line_count = 0 err
 	)
Signature · 1 line
2.50.1 (Apple Git-155)
#12 lore raw

t/t1901-repo-structure.sh test_expect_success 'keyvalue and nul format' ' · line 104

Quoted 9 lines · Lucas Seiki Oshiro
t/t1901-repo-structure.sh +2 -0
index 36a71a144e..df7d4ea524 100755
@@ -101,6 +101,13 @@ test_expect_success 'keyvalue and nul format' '
 		tr "\n=" "\0\n" <expect >expect_nul &&
 		git repo structure --format=nul >out 2>err &&
+		test_cmp expect_nul out &&
+		test_line_count = 0 err &&

Not limited to this step, but I have a couple of comments.

* Instead of munging the expected file so that it contains a NUL, and compare the actual output with it, munge the NUL terminated outout to make it text and compare with the expected file in text format. This matters when tests start to fail as test_cmp will show the "diff" output when it fails, and comparing NUL terminated files, which are "binary" in the eyes of the "diff" utility.

* I see your -z output is "<key> LF <value> NUL", but was there a particular reason why "<key> NUL <value> NUL" was not chosen? Unless there is a compelling reason not to, it would be a lot more future-proof to use NUL for both, primarily because it would allow future developers to include arbitrary non-NUL bytes in the <key> part in the future (and we wouldn't know what end-user controlled substring they may want to add).

Quoted 8 lines
t/t1901-repo-structure.sh +5 -0
+
+		# "-z", as a synonym to "--format=nul", participates in the
+		# usual "last one wins" rule.
+		git repo structure --format=table -z >out 2>err &&
+
 		test_cmp expect_nul out &&
 		test_line_count = 0 err
 	)
#13 lore raw

Hi, Junio!

Quoted 4 lines

* Instead of munging the expected file so that it contains a NUL, and compare the actual output with it, munge the NUL terminated outout to make it text and compare with the expected file in text format.

Ok! I'll do that in the next version.

Quoted 2 lines

* I see your -z output is "<key> LF <value> NUL", but was there a particular reason why "<key> NUL <value> NUL" was not chosen?

This was a suggestions by Phillip Wood [1]. We've chosen this format following the format of git-config.

[1] https://lore.kernel.org/git/[email protected]/

#14 lore raw
In reply to Lucas Seiki Oshiro
Quoted 10 lines · Lucas Seiki Oshiro

Hi!

The main objective of this patchset is to add -z to git-repo-structure as an alias for --format=nul. I'm including two other related patches here:

- a patch removing an extra line in the documentation, which was leaking an + to the generated files

- a patch replacing [--format=...] [-z] by [--format=... | -z] in git-repo-info's synopsis

This version looks good to me, thanks!

Patrick