last-modified: document option '-z'

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>

Toon Claes committed Jan 20, 2026 at 22:47 UTC 209574de2d2ab0a264522c8c44c3eebb6d03ec43
2 files changed +27 -5
Documentation/git-last-modified.adoc
+20 -1
@@ -9,7 +9,7 @@ git-last-modified - EXPERIMENTAL: Show when files were last modified
9 SYNOPSIS
10 --------
11 [synopsis]
12 -git last-modified [--recursive] [--show-trees]
12 +git last-modified [--recursive] [--show-trees] [-z]
13 [<revision-range>] [[--] <pathspec>...]
14
15 DESCRIPTION
@@ -33,6 +33,9 @@ OPTIONS
33 Show tree entries even when recursing into them. It has no effect
34 without `--recursive`.
35
36 +`-z`::
37 + Terminate each line with a _NUL_ character rather than a newline.
38 +
39 `<revision-range>`::
40 Only traverse commits in the specified revision range. When no
41 `<revision-range>` is specified, it defaults to `HEAD` (i.e. the whole
@@ -45,6 +48,22 @@ OPTIONS
48 If no _<pathspec>_ is given, all files and subdirectories are included.
49 See linkgit:gitglossary[7] for details on pathspec syntax.
50
51 +OUTPUT
52 +------
53 +
54 +The output is in the format:
55 +
56 +------------
57 + <oid> TAB <path> LF
58 +------------
59 +
60 +If a path contains any special characters, the path is C-style quoted. To
61 +avoid quoting, pass option `-z` to terminate each line with a NUL.
62 +
63 +------------
64 + <oid> TAB <path> NUL
65 +------------
66 +
67 SEE ALSO
68 --------
69 linkgit:git-blame[1],
builtin/last-modified.c
+7 -4
@@ -55,6 +55,7 @@ struct last_modified {
55 struct rev_info rev;
56 bool recursive;
57 bool show_trees;
58 + bool nul_termination;
59
60 const char **all_paths;
61 size_t all_paths_nr;
@@ -165,10 +166,10 @@ static void last_modified_emit(struct last_modified *lm,
166 putchar('^');
167 printf("%s\t", oid_to_hex(&commit->object.oid));
168
168 - if (lm->rev.diffopt.line_termination)
169 - write_name_quoted(path, stdout, '\n');
170 - else
169 + if (lm->nul_termination)
170 printf("%s%c", path, '\0');
171 + else
172 + write_name_quoted(path, stdout, '\n');
173 }
174
175 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,
511 struct last_modified lm = { 0 };
512
513 const char * const last_modified_usage[] = {
513 - N_("git last-modified [--recursive] [--show-trees]\n"
514 + N_("git last-modified [--recursive] [--show-trees] [-z]\n"
515 " [<revision-range>] [[--] <pathspec>...]"),
516 NULL
517 };
@@ -520,6 +521,8 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
521 N_("recurse into subtrees")),
522 OPT_BOOL('t', "show-trees", &lm.show_trees,
523 N_("show tree entries when recursing into subtrees")),
524 + OPT_BOOL('z', NULL, &lm.nul_termination,
525 + N_("lines are separated with NUL character")),
526 OPT_END()
527 };
528