git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/3] Teach git-diff-tree(1) option --max-depth

From
Toon Claes <toon@iotcl.com>
Date
Jul 29, 2025, 18:57 UTC
Message-ID
<20250729-toon-max-depth-v1-0-c177e39c40fb@iotcl.com>

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@sigill.intra.peff.net/ [2]: https://lore.kernel.org/git/20160831054201.ldlwptlmcndjmfwu@sigill.intra.peff.net/ [3]: https://lore.kernel.org/git/Y+%2FmnnJUz75yfWCN@coredump.intra.peff.net/ [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

Next: Toon Claes
Message 1 of 16 in “Teach git-diff-tree(1) option --max-depth”
  1. 0/3 Teach git-diff-tree(1) option --max-depthToon Claes, Jul 29, 2025
  2. 1/3 combine-diff: zero memory used for callback filepairsToon Claes, Jul 29, 2025
  3. 2/3 within_depth: fix return for empty pathToon Claes, Jul 29, 2025
  4. Patrick SteinhardtJul 30, 2025
  5. Toon ClaesAug 6, 2025
  6. Patrick SteinhardtAug 7, 2025
  7. 3/3 diff: teach tree-diff a max-depth parameterToon Claes, Jul 29, 2025
  8. Patrick SteinhardtJul 30, 2025
  9. Toon ClaesAug 6, 2025
  10. Patrick SteinhardtAug 7, 2025
  11. 0/3 Teach git-diff-tree(1) option --max-depthToon Claes, Aug 7, 2025
  12. 1/3 combine-diff: zero memory used for callback filepairsToon Claes, Aug 7, 2025
  13. 2/3 within_depth: fix return for empty pathToon Claes, Aug 7, 2025
  14. 3/3 diff: teach tree-diff a max-depth parameterToon Claes, Aug 7, 2025
  15. Junio C HamanoAug 14, 2025
  16. Patrick SteinhardtAug 15, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.