aboutsummaryrefslogtreecommitdiffstats
path: root/diff-lib.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2025-08-07 22:52:58 +0200
committerJunio C Hamano <gitster@pobox.com>2025-08-07 15:29:35 -0700
commita1dfa5448d583bbfd1ec45642a4495ad499970c9 (patch)
treec57bd65d0f3e6013e0d808fbecaa0244c42672f2 /diff-lib.c
parentwithin_depth: fix return for empty path (diff)
downloadgit-a1dfa5448d583bbfd1ec45642a4495ad499970c9.tar.gz
git-a1dfa5448d583bbfd1ec45642a4495ad499970c9.zip
diff: teach tree-diff a max-depth parameter
When you are doing a tree-diff, there are basically two options: do not recurse into subtrees at all, or recurse indefinitely. While most callers would want to always recurse and see full pathnames, some may want the efficiency of looking only at a particular level of the tree. This is currently easy to do for the top-level (just turn off recursion), but you cannot say "show me what changed in subdir/, but do not recurse". This patch adds a max-depth parameter which is measured from the closest pathspec match, so that you can do: git log --raw --max-depth=1 -- a/b/c and see the raw output for a/b/c/, but not those of a/b/c/d/ (instead of the raw output you would see for a/b/c/d). Co-authored-by: Toon Claes <toon@iotcl.com> Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff-lib.c')
-rw-r--r--diff-lib.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/diff-lib.c b/diff-lib.c
index 244468dd1a..b8f8f3bc31 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -115,6 +115,9 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
uint64_t start = getnanotime();
struct index_state *istate = revs->diffopt.repo->index;
+ if (revs->diffopt.max_depth_valid)
+ die(_("max-depth is not supported for worktree diffs"));
+
diff_set_mnemonic_prefix(&revs->diffopt, "i/", "w/");
refresh_fsmonitor(istate);
@@ -560,6 +563,8 @@ static int diff_cache(struct rev_info *revs,
opts.dst_index = NULL;
opts.pathspec = &revs->diffopt.pathspec;
opts.pathspec->recursive = 1;
+ if (revs->diffopt.max_depth_valid)
+ die(_("max-depth is not supported for index diffs"));
init_tree_desc(&t, &tree->object.oid, tree->buffer, tree->size);
return unpack_trees(1, &t, &opts);