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. Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lucas Seiki Oshiro committed Dec 4, 2025 at 17:10 UTC 76c0704bdf6ee8ac0be11830cb6ae8d08cc587a8
3 files changed +16 -3
Documentation/git-repo.adoc
+4 -2
@@ -9,7 +9,7 @@ SYNOPSIS
9 --------
10 [synopsis]
11 git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]
12 -git repo structure [--format=(table|keyvalue|nul)]
12 +git repo structure [--format=(table|keyvalue|nul) | -z]
13
14 DESCRIPTION
15 -----------
@@ -44,7 +44,7 @@ supported:
44 +
45 `-z` is an alias for `--format=nul`.
46
47 -`structure [--format=(table|keyvalue|nul)]`::
47 +`structure [--format=(table|keyvalue|nul) | -z]`::
48 Retrieve statistics about the current repository structure. The
49 following kinds of information are reported:
50 +
@@ -71,6 +71,8 @@ supported:
71 the delimiter between the key and value instead of '='. Unlike the
72 `keyvalue` format, values containing "unusual" characters are never
73 quoted.
74 ++
75 +`-z` is an alias for `--format=nul`.
76
77 INFO KEYS
78 ---------
builtin/repo.c
+5 -1
@@ -16,7 +16,7 @@
16
17 static const char *const repo_usage[] = {
18 "git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]",
19 - "git repo structure [--format=(table|keyvalue|nul)]",
19 + "git repo structure [--format=(table|keyvalue|nul) | -z]",
20 NULL
21 };
22
@@ -529,6 +529,10 @@ static int cmd_repo_structure(int argc, const char **argv, const char *prefix,
529 OPT_CALLBACK_F(0, "format", &format, N_("format"),
530 N_("output format"),
531 PARSE_OPT_NONEG, parse_format_cb),
532 + OPT_CALLBACK_F('z', NULL, &format, NULL,
533 + N_("synonym for --format=nul"),
534 + PARSE_OPT_NONEG | PARSE_OPT_NOARG,
535 + parse_format_cb),
536 OPT_BOOL(0, "progress", &show_progress, N_("show progress")),
537 OPT_END()
538 };
t/t1901-repo-structure.sh
+7
@@ -101,6 +101,13 @@ test_expect_success 'keyvalue and nul format' '
101 tr "\n=" "\0\n" <expect >expect_nul &&
102 git repo structure --format=nul >out 2>err &&
103
104 + test_cmp expect_nul out &&
105 + test_line_count = 0 err &&
106 +
107 + # "-z", as a synonym to "--format=nul", participates in the
108 + # usual "last one wins" rule.
109 + git repo structure --format=table -z >out 2>err &&
110 +
111 test_cmp expect_nul out &&
112 test_line_count = 0 err
113 )