]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: document option --max-depth
authorToon Claes <toon@iotcl.com>
Wed, 26 Nov 2025 06:09:44 +0000 (07:09 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 26 Nov 2025 16:46:55 +0000 (08:46 -0800)
Option --max-depth is supported by git-last-modified(1), because it was
added to the diff machinery in a1dfa5448d (diff: teach tree-diff a
max-depth parameter, 2025-08-07).

This option is useful for everyday use of the git-last-modified(1)
command, so document it's existence in the man page and `-h` output.

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 cd4a5040b03da0d3fc94218df6b6275700114224..8409daebe992caee24a10b8b518d075a1aafc0c1 100644 (file)
@@ -9,7 +9,8 @@ git-last-modified - EXPERIMENTAL: Show when files were last modified
 SYNOPSIS
 --------
 [synopsis]
-git last-modified [--recursive] [--show-trees] [-z] [<revision-range>] [[--] <path>...]
+git last-modified [--recursive] [--show-trees] [--max-depth=<depth>] [-z]
+       [<revision-range>] [[--] <path>...]
 
 DESCRIPTION
 -----------
@@ -32,6 +33,12 @@ OPTIONS
        Show tree entries even when recursing into them. It has no effect
        without `--recursive`.
 
+`--max-depth=<depth>`::
+       For each pathspec given on the command line, descend at most `<depth>`
+       levels of directories. A negative value means no limit.
+       Setting a positive value implies `--recursive`.
+       Cannot be combined with wildcards in the pathspec.
+
 `-z`::
        Terminate each line with a _NUL_ rather than a newline.
 
index 9206bbdc1dffdec42e8b385e80b6cf08dc3b4697..ccb7ff66d486f7058598d1828c901c64ace8834e 100644 (file)
@@ -25,6 +25,7 @@
 
 #define LAST_MODIFIED_INIT { \
        .line_termination = '\n', \
+       .max_depth = -1, \
 }
 
 struct last_modified_entry {
@@ -60,6 +61,7 @@ struct last_modified {
        bool recursive;
        bool show_trees;
        int line_termination;
+       int max_depth;
 
        const char **all_paths;
        size_t all_paths_nr;
@@ -487,6 +489,12 @@ static int last_modified_init(struct last_modified *lm, struct repository *r,
        lm->rev.diffopt.flags.recursive = lm->recursive;
        lm->rev.diffopt.flags.tree_in_recursive = lm->show_trees;
 
+       if (lm->max_depth >= 0) {
+               lm->rev.diffopt.flags.recursive = 1;
+               lm->rev.diffopt.max_depth = lm->max_depth;
+               lm->rev.diffopt.max_depth_valid = 1;
+       }
+
        argc = setup_revisions(argc, argv, &lm->rev, NULL);
        if (argc > 1) {
                error(_("unknown last-modified argument: %s"), argv[1]);
@@ -515,7 +523,7 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
        struct last_modified lm = LAST_MODIFIED_INIT;
 
        const char * const last_modified_usage[] = {
-               N_("git last-modified [--recursive] [--show-trees] [-z] "
+               N_("git last-modified [--recursive] [--show-trees] [--max-depth=<depth>] [-z] "
                   "[<revision-range>] [[--] <path>...]"),
                NULL
        };
@@ -525,6 +533,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_INTEGER_F(0, "max-depth", &lm.max_depth,
+                       N_("maximum tree depth to recurse"), PARSE_OPT_NONEG),
                OPT_SET_INT('z', NULL, &lm.line_termination,
                        N_("lines are separated with NUL character"), '\0'),
                OPT_END()