]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo: add -z as an alias for --format=nul to git-repo-structure
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Thu, 4 Dec 2025 20:10:12 +0000 (17:10 -0300)
committerJunio C Hamano <gitster@pobox.com>
Fri, 5 Dec 2025 02:39:19 +0000 (11:39 +0900)
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>
Documentation/git-repo.adoc
builtin/repo.c
t/t1901-repo-structure.sh

index f24514deaa4cd7c088dcbf79c0f1b86eeb9100bb..c4a78277df61c0c48549ab072d37e73b3211a49b 100644 (file)
@@ -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
 ---------
index cc97dd1836fb9f22153e419b51f8615d4d0a6ded..0dd41b17783ed113a4c2e0ff36a8b67eb7b962e5 100644 (file)
@@ -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()
        };
index 36a71a144e3f747a68b9afa11a08e305915c5437..df7d4ea52485da137b6b0a5359fb3ccc3b10c786 100755 (executable)
@@ -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
        )