]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: document option '-z'
authorToon Claes <toon@iotcl.com>
Tue, 20 Jan 2026 21:47:09 +0000 (22:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Jan 2026 22:13:04 +0000 (14:13 -0800)
The command git-last-modified(1) already recognizes the option '-z', and
similar to many other commands this will make the output NUL-terminated
instead of using newlines. Although, this option is missing from the
documentation, so add it.

In addition to that, to have '-z' also appear in the help output of `git
last-modified -h`, move the handling of '-z' to parse_options() in
builtin/last-modified.c itself.

Before, the parsing of option '-z' was done by diff_opt_parse(), which
is called by setup_revisions(). That would fill in `struct
diff_options::line_termination`, but that field was not used by the diff
machinery itself. Thus it makes more sense to have the handling of that
option completely in builtin/last-modified.c.

Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-last-modified.adoc
builtin/last-modified.c

index 7c3fd844b8eca5b31dfb9cfc06a642e517b1fd25..3760fd33a1826fd9c487f25adcfae699c4b00966 100644 (file)
@@ -9,7 +9,7 @@ git-last-modified - EXPERIMENTAL: Show when files were last modified
 SYNOPSIS
 --------
 [synopsis]
-git last-modified [--recursive] [--show-trees]
+git last-modified [--recursive] [--show-trees] [-z]
                  [<revision-range>] [[--] <pathspec>...]
 
 DESCRIPTION
@@ -33,6 +33,9 @@ OPTIONS
        Show tree entries even when recursing into them. It has no effect
        without `--recursive`.
 
+`-z`::
+       Terminate each line with a _NUL_ character rather than a newline.
+
 `<revision-range>`::
        Only traverse commits in the specified revision range. When no
        `<revision-range>` is specified, it defaults to `HEAD` (i.e. the whole
@@ -45,6 +48,22 @@ OPTIONS
        If no _<pathspec>_ is given, all files and subdirectories are included.
        See linkgit:gitglossary[7] for details on pathspec syntax.
 
+OUTPUT
+------
+
+The output is in the format:
+
+------------
+ <oid> TAB <path> LF
+------------
+
+If a path contains any special characters, the path is C-style quoted. To
+avoid quoting, pass option `-z` to terminate each line with a NUL.
+
+------------
+ <oid> TAB <path> NUL
+------------
+
 SEE ALSO
 --------
 linkgit:git-blame[1],
index 781495f597652eb9644c544256fb6f2467eb644a..46423b527e44a1e42b03fd70c7f4b7bc6d2272c1 100644 (file)
@@ -55,6 +55,7 @@ struct last_modified {
        struct rev_info rev;
        bool recursive;
        bool show_trees;
+       bool nul_termination;
 
        const char **all_paths;
        size_t all_paths_nr;
@@ -165,10 +166,10 @@ static void last_modified_emit(struct last_modified *lm,
                putchar('^');
        printf("%s\t", oid_to_hex(&commit->object.oid));
 
-       if (lm->rev.diffopt.line_termination)
-               write_name_quoted(path, stdout, '\n');
-       else
+       if (lm->nul_termination)
                printf("%s%c", path, '\0');
+       else
+               write_name_quoted(path, stdout, '\n');
 }
 
 static void mark_path(const char *path, const struct object_id *oid,
@@ -510,7 +511,7 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
        struct last_modified lm = { 0 };
 
        const char * const last_modified_usage[] = {
-               N_("git last-modified [--recursive] [--show-trees]\n"
+               N_("git last-modified [--recursive] [--show-trees] [-z]\n"
                   "                  [<revision-range>] [[--] <pathspec>...]"),
                NULL
        };
@@ -520,6 +521,8 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
                         N_("recurse into subtrees")),
                OPT_BOOL('t', "show-trees", &lm.show_trees,
                         N_("show tree entries when recursing into subtrees")),
+               OPT_BOOL('z', NULL, &lm.nul_termination,
+                        N_("lines are separated with NUL character")),
                OPT_END()
        };