]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: add option '--max-depth' to help output
authorToon Claes <toon@iotcl.com>
Fri, 16 Jan 2026 13:22:52 +0000 (14:22 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Jan 2026 18:27:20 +0000 (10:27 -0800)
In previous commit option '--max-depth' was added to the documentation.
To have it also appear in the help output of `git last-modified -h`,
move the handling of '--max-depth' to parse_options() in
builtin/last-modified.c itself.

It enables us to change default behavior in a subsequent commit.

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

index 630687b81f68a447749b41b525021ff9ed5d2cc5..f6cbff30e7e5c3cf6df9299b6c4a00a51016b5d7 100644 (file)
@@ -56,6 +56,7 @@ struct last_modified {
        bool recursive;
        bool show_trees;
        bool null_termination;
+       int max_depth;
 
        const char **all_paths;
        size_t all_paths_nr;
@@ -483,6 +484,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]);
@@ -521,11 +528,19 @@ 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_BOOL('z', NULL, &lm.null_termination,
                        N_("lines are separated with NUL character")),
                OPT_END()
        };
 
+       /*
+        * Set the default of a max-depth to "unset". This will change in a
+        * subsequent commit.
+        */
+       lm.max_depth = -1;
+
        argc = parse_options(argc, argv, prefix, last_modified_options,
                             last_modified_usage,
                             PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);