Please consider these patches authored by Peff. They add option `--max-depth` to the diff machinery. During the process to upstream the git-blame-tree(1), later named git-last-modified(1), various times[1][2][3] the topic was raised to add option `--max-depth` to the diff machinery. In this patch series this change is added as a separate patch series. The patches were originally written by Peff[4] and I'm crediting him as the author. I've taken the patches almost verbatim from his fork on GitHub, with some minor tweaks in the commit messages. Because only tiny changes were made, I've kept his Signed-off-by trailers, but I can remove if disagreed on. The goal of the option `--max-depth` is to stop recursively traversing the tree if the given depth is reached from the pathspec. These patches add `max_depth` and `max_depth_valid` to `struct diff_options`. This is different from what git-grep(1) does, which uses `max_depth` on `struct pathspec` instead. At the moment I'm on the fence whether this is an issue: while it probably makes sense to consolidate them into the same structs, it does not really make sense to reuse these the struct fields if they are used in two separate code paths. [1]: https://lore.kernel.org/git/20130318121243.GC14789@xxxxxxxxxxxxxxxxxxxxx/ [2]: https://lore.kernel.org/git/20160831054201.ldlwptlmcndjmfwu@xxxxxxxxxxxxxxxxxxxxx/ [3]: https://lore.kernel.org/git/Y+%2FmnnJUz75yfWCN@xxxxxxxxxxxxxxxxxxxxxxx/ [4]: https://github.com/peff/git/tree/jk/diff-max-depth --- Jeff King (3): combine-diff: zero memory used for callback filepairs within_depth: fix return for empty path diff: teach tree-diff a max-depth parameter Documentation/diff-options.adoc | 28 +++++++++++ combine-diff.c | 2 +- diff-lib.c | 5 ++ diff.c | 19 +++++++ diff.h | 9 ++++ dir.c | 2 +- t/meson.build | 1 + t/t4072-diff-max-depth.sh | 109 ++++++++++++++++++++++++++++++++++++++++ tree-diff.c | 78 ++++++++++++++++++++++++++-- 9 files changed, 248 insertions(+), 5 deletions(-) --- --- base-commit: e813a0200a7121b97fec535f0d0b460b0a33356c change-id: 20250724-toon-max-depth-25d3c19e2607 Thanks -- Toon