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>
This commit is contained in:
Jeff King
2025-08-07 22:52:58 +02:00
committed by Junio C Hamano
parent 2a43e0e550
commit a1dfa5448d
7 changed files with 257 additions and 3 deletions

8
diff.h
View File

@@ -404,6 +404,14 @@ struct diff_options {
struct strmap *additional_path_headers;
int no_free;
/*
* The value '0' is a valid max-depth (for no recursion), and value '-1'
* also (for unlimited recursion), so the extra "valid" flag is used to
* determined whether the user specified option --max-depth.
*/
int max_depth;
int max_depth_valid;
};
unsigned diff_filter_bit(char status);