Skip to content

Commit 9bfaf78

Browse files
To1negitster
authored andcommitted
last-modified: document option '--max-depth'
Option --max-depth is supported by git-last-modified(1), because it was added to the diff machinery in a1dfa54 (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. 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. This prepares for the change in default behavior in the next commit. Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 209574d commit 9bfaf78

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

Documentation/git-last-modified.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-last-modified - EXPERIMENTAL: Show when files were last modified
99
SYNOPSIS
1010
--------
1111
[synopsis]
12-
git last-modified [--recursive] [--show-trees] [-z]
12+
git last-modified [--recursive] [--show-trees] [--max-depth=<depth>] [-z]
1313
[<revision-range>] [[--] <pathspec>...]
1414

1515
DESCRIPTION
@@ -33,6 +33,12 @@ OPTIONS
3333
Show tree entries even when recursing into them. It has no effect
3434
without `--recursive`.
3535

36+
`--max-depth=<depth>`::
37+
For each pathspec given on the command line, traverse at most `<depth>`
38+
levels into subtrees. A negative value means no limit.
39+
The default is 0, which shows all paths matching the pathspec
40+
without descending into subtrees.
41+
3642
`-z`::
3743
Terminate each line with a _NUL_ character rather than a newline.
3844

builtin/last-modified.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct last_modified {
5656
bool recursive;
5757
bool show_trees;
5858
bool nul_termination;
59+
int max_depth;
5960

6061
const char **all_paths;
6162
size_t all_paths_nr;
@@ -483,6 +484,12 @@ static int last_modified_init(struct last_modified *lm, struct repository *r,
483484
lm->rev.diffopt.flags.recursive = lm->recursive;
484485
lm->rev.diffopt.flags.tree_in_recursive = lm->show_trees;
485486

487+
if (lm->max_depth >= 0) {
488+
lm->rev.diffopt.flags.recursive = 1;
489+
lm->rev.diffopt.max_depth = lm->max_depth;
490+
lm->rev.diffopt.max_depth_valid = 1;
491+
}
492+
486493
argc = setup_revisions(argc, argv, &lm->rev, NULL);
487494
if (argc > 1) {
488495
error(_("unknown last-modified argument: %s"), argv[1]);
@@ -511,7 +518,7 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
511518
struct last_modified lm = { 0 };
512519

513520
const char * const last_modified_usage[] = {
514-
N_("git last-modified [--recursive] [--show-trees] [-z]\n"
521+
N_("git last-modified [--recursive] [--show-trees] [--max-depth=<depth>] [-z]\n"
515522
" [<revision-range>] [[--] <pathspec>...]"),
516523
NULL
517524
};
@@ -521,11 +528,19 @@ int cmd_last_modified(int argc, const char **argv, const char *prefix,
521528
N_("recurse into subtrees")),
522529
OPT_BOOL('t', "show-trees", &lm.show_trees,
523530
N_("show tree entries when recursing into subtrees")),
531+
OPT_INTEGER_F(0, "max-depth", &lm.max_depth,
532+
N_("maximum tree depth to recurse"), PARSE_OPT_NONEG),
524533
OPT_BOOL('z', NULL, &lm.nul_termination,
525534
N_("lines are separated with NUL character")),
526535
OPT_END()
527536
};
528537

538+
/*
539+
* Set the default of a max-depth to "unset". This will change in a
540+
* subsequent commit.
541+
*/
542+
lm.max_depth = -1;
543+
529544
argc = parse_options(argc, argv, prefix, last_modified_options,
530545
last_modified_usage,
531546
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);

0 commit comments

Comments
 (0)