Skip to content

Commit 209574d

Browse files
To1negitster
authored andcommitted
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>
1 parent b143f0f commit 209574d

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

Documentation/git-last-modified.adoc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-last-modified - EXPERIMENTAL: Show when files were last modified
99
SYNOPSIS
1010
--------
1111
[synopsis]
12-
git last-modified [--recursive] [--show-trees]
12+
git last-modified [--recursive] [--show-trees] [-z]
1313
[<revision-range>] [[--] <pathspec>...]
1414

1515
DESCRIPTION
@@ -33,6 +33,9 @@ OPTIONS
3333
Show tree entries even when recursing into them. It has no effect
3434
without `--recursive`.
3535

36+
`-z`::
37+
Terminate each line with a _NUL_ character rather than a newline.
38+
3639
`<revision-range>`::
3740
Only traverse commits in the specified revision range. When no
3841
`<revision-range>` is specified, it defaults to `HEAD` (i.e. the whole
@@ -45,6 +48,22 @@ OPTIONS
4548
If no _<pathspec>_ is given, all files and subdirectories are included.
4649
See linkgit:gitglossary[7] for details on pathspec syntax.
4750

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+
4867
SEE ALSO
4968
--------
5069
linkgit:git-blame[1],

builtin/last-modified.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct last_modified {
5555
struct rev_info rev;
5656
bool recursive;
5757
bool show_trees;
58+
bool nul_termination;
5859

5960
const char **all_paths;
6061
size_t all_paths_nr;
@@ -165,10 +166,10 @@ static void last_modified_emit(struct last_modified *lm,
165166
putchar('^');
166167
printf("%s\t", oid_to_hex(&commit->object.oid));
167168

168-
if (lm->rev.diffopt.line_termination)
169-
write_name_quoted(path, stdout, '\n');
170-
else
169+
if (lm->nul_termination)
171170
printf("%s%c", path, '\0');
171+
else
172+
write_name_quoted(path, stdout, '\n');
172173
}
173174

174175
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,
510511
struct last_modified lm = { 0 };
511512

512513
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"
514515
" [<revision-range>] [[--] <pathspec>...]"),
515516
NULL
516517
};
@@ -520,6 +521,8 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
520521
N_("recurse into subtrees")),
521522
OPT_BOOL('t', "show-trees", &lm.show_trees,
522523
N_("show tree entries when recursing into subtrees")),
524+
OPT_BOOL('z', NULL, &lm.nul_termination,
525+
N_("lines are separated with NUL character")),
523526
OPT_END()
524527
};
525528

0 commit comments

Comments
 (0)