]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: handle and document NUL termination
authorToon Claes <toon@iotcl.com>
Wed, 26 Nov 2025 06:09:43 +0000 (07:09 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Nov 2025 16:46:54 +0000 (08:46 -0800)
When option `-z` is provided to git-last-modified(1), each line is
separated with a NUL instead of a newline. Document this properly and
handle parsing of the option in the builtin itself.

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 602843e09598a52bf6a8d506f3359f08e9bd39ce..cd4a5040b03da0d3fc94218df6b6275700114224 100644 (file)
@@ -9,7 +9,7 @@ git-last-modified - EXPERIMENTAL: Show when files were last modified
 SYNOPSIS
 --------
 [synopsis]
-git last-modified [--recursive] [--show-trees] [<revision-range>] [[--] <path>...]
+git last-modified [--recursive] [--show-trees] [-z] [<revision-range>] [[--] <path>...]
 
 DESCRIPTION
 -----------
@@ -32,6 +32,9 @@ OPTIONS
        Show tree entries even when recursing into them. It has no effect
        without `--recursive`.
 
+`-z`::
+       Terminate each line with a _NUL_ 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
@@ -44,6 +47,22 @@ OPTIONS
        Without an optional path parameter, all files and subdirectories
        in path traversal the are included in the output.
 
+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 b0ecbdc5400d137b7e147c8f91f43210cf8236e0..9206bbdc1dffdec42e8b385e80b6cf08dc3b4697 100644 (file)
 #define PARENT1 (1u<<16) /* used instead of SEEN */
 #define PARENT2 (1u<<17) /* used instead of BOTTOM, BOUNDARY */
 
+#define LAST_MODIFIED_INIT { \
+       .line_termination = '\n', \
+}
+
 struct last_modified_entry {
        struct hashmap_entry hashent;
        struct object_id oid;
@@ -55,6 +59,7 @@ struct last_modified {
        struct rev_info rev;
        bool recursive;
        bool show_trees;
+       int line_termination;
 
        const char **all_paths;
        size_t all_paths_nr;
@@ -165,7 +170,7 @@ 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)
+       if (lm->line_termination)
                write_name_quoted(path, stdout, '\n');
        else
                printf("%s%c", path, '\0');
@@ -507,10 +512,10 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
                      struct repository *repo)
 {
        int ret;
-       struct last_modified lm = { 0 };
+       struct last_modified lm = LAST_MODIFIED_INIT;
 
        const char * const last_modified_usage[] = {
-               N_("git last-modified [--recursive] [--show-trees] "
+               N_("git last-modified [--recursive] [--show-trees] [-z] "
                   "[<revision-range>] [[--] <path>...]"),
                NULL
        };
@@ -520,6 +525,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_SET_INT('z', NULL, &lm.line_termination,
+                       N_("lines are separated with NUL character"), '\0'),
                OPT_END()
        };