]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: change default max-depth to 0
authorToon Claes <toon@iotcl.com>
Fri, 16 Jan 2026 13:22:53 +0000 (14:22 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Jan 2026 18:27:20 +0000 (10:27 -0800)
By default git-last-modified(1) doesn't recurse into subtrees. So when
the pathspec contained a path in a subtree, the command would only print
the commit information about the parent tree of the path, like:

    $ git last-modified -- path/file
    aaa0aab1bbb2bcc3ccc4ddd5dde6eee7eff8fff9 path

Change the default behavior to give commit information about the exact
path instead:

    $ git last-modified -- path/file
    aaa0aab1bbb2bcc3ccc4ddd5dde6eee7eff8fff9 path/file

To achieve this, the default max-depth is changed to 0 and recursive is
always enabled.

The handling of option '-r' is modified to disable a max-depth,
resulting in the behavior of this option to remain unchanged.

No existing tests were modified, because there didn't exist any tests
covering the example above. But more tests are added to cover this now.

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
t/t8020-last-modified.sh

index a3992db3f2a2e491c5abe26dff20bda1e79a02b7..57136baf3b0cf4f6c1845ae20782b86cf1790b26 100644 (file)
@@ -27,6 +27,7 @@ OPTIONS
 `--recursive`::
        Instead of showing tree entries, step into subtrees and show all entries
        inside them recursively.
+       This is identical as setting `--max-depth=-1`.
 
 `-t`::
 `--show-trees`::
@@ -36,7 +37,7 @@ OPTIONS
 `--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`.
+       The default depth is 0.
        Cannot be combined with wildcards in the pathspec.
 
 `-z`::
index f6cbff30e7e5c3cf6df9299b6c4a00a51016b5d7..d8988e15c13cf3a18bba3bf34be1da4b8b65559e 100644 (file)
@@ -481,14 +481,10 @@ static int last_modified_init(struct last_modified *lm, struct repository *r,
        lm->rev.no_commit_id = 1;
        lm->rev.diff = 1;
        lm->rev.diffopt.flags.no_recursive_diff_tree_combined = 1;
-       lm->rev.diffopt.flags.recursive = lm->recursive;
+       lm->rev.diffopt.flags.recursive = 1;
        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;
-       }
+       lm->rev.diffopt.max_depth = lm->max_depth;
+       lm->rev.diffopt.max_depth_valid = !lm->recursive && lm->max_depth >= 0;
 
        argc = setup_revisions(argc, argv, &lm->rev, NULL);
        if (argc > 1) {
@@ -535,12 +531,6 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
                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);
index a4c1114ee28f7fca858e425c0eeb69f3f5c98d0f..43f38937baf6345acea1c6efb1a616a0833b30e8 100755 (executable)
@@ -85,6 +85,41 @@ test_expect_success 'last-modified subdir recursive' '
        EOF
 '
 
+test_expect_success 'last-modified subdir non-recursive' '
+       check_last_modified a <<-\EOF
+       3 a
+       EOF
+'
+
+test_expect_success 'last-modified path in subdir non-recursive' '
+       check_last_modified a/file <<-\EOF
+       2 a/file
+       EOF
+'
+
+test_expect_success 'last-modified subdir with wildcard non-recursive' '
+       check_last_modified a/* <<-\EOF
+       3 a/b
+       2 a/file
+       EOF
+'
+
+test_expect_success 'last-modified with negative max-depth' '
+       check_last_modified --max-depth=-1 <<-\EOF
+       3 a/b/file
+       2 a/file
+       1 file
+       EOF
+'
+
+test_expect_success 'last-modified with max-depth of 1' '
+       check_last_modified --max-depth=1 <<-\EOF
+       3 a/b
+       2 a/file
+       1 file
+       EOF
+'
+
 test_expect_success 'last-modified from non-HEAD commit' '
        check_last_modified HEAD^ <<-\EOF
        2 a