diff options
| author | Toon Claes <toon@iotcl.com> | 2026-01-20 22:47:11 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-01-20 14:13:04 -0800 |
| commit | 9dcc09bed13aba0dc93d253f18ee2c7da5970c0c (patch) | |
| tree | 55052106e323114eca79e2501a5de8f039a4870b /builtin | |
| parent | 9bfaf78cb28b26ab0538e2edd2229547d6be962f (diff) | |
| download | git-9dcc09bed13aba0dc93d253f18ee2c7da5970c0c.tar.xz | |
last-modified: change default max-depth to 0
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>
Diffstat (limited to 'builtin')
| -rw-r--r-- | builtin/last-modified.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/builtin/last-modified.c b/builtin/last-modified.c index 797c1bb88b..e27f36b624 100644 --- a/builtin/last-modified.c +++ b/builtin/last-modified.c @@ -53,7 +53,6 @@ define_commit_slab(active_paths_for_commit, struct bitmap *); struct last_modified { struct hashmap paths; struct rev_info rev; - bool recursive; bool show_trees; bool nul_termination; int max_depth; @@ -481,14 +480,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->max_depth >= 0; argc = setup_revisions(argc, argv, &lm->rev, NULL); if (argc > 1) { @@ -524,8 +519,8 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix, }; struct option last_modified_options[] = { - OPT_BOOL('r', "recursive", &lm.recursive, - N_("recurse into subtrees")), + OPT_SET_INT('r', "recursive", &lm.max_depth, + N_("recurse into subtrees"), -1), 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, @@ -535,12 +530,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); |
