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

Re: [PATCH v2] diff: ensure consistent diff behavior with -I<regex> across output formats

From
Lidong Yan <yldhome2d2@gmail.com>
Date
Aug 5, 2025, 09:23 UTC
Message-ID
<F21E21EC-4894-4396-A126-8F6638731762@gmail.com>
In-Reply-To
<xmqqzfcfd7pp.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 16 quoted lines
> 
> But I think the refactoring of diff_flush() codepath would may
> involve some new mode (perhaps DIFF_FORMAT_DRYRUN or something) that
> 
> (1) does not produce any output, like DIFF_FORMAT_NO_OUTPUT, so
>     that we do not need to play with /dev/null like Peff's
>     illustration.
> 
> (2) knows that the caller is only interested in each path having
>     any change worth reporting, so that it can short-circuit once a
>     change is found for each path.
> 
> So, just before you want to decide showing name or name-status,
> you'd do this extra diff_flush() that is run only to learn if each
> path has changes (with various "ignore" criteria) in the dry-run
> mode, and it can do as much short-cut as it needs to.

I’m proposing to add a .diff_optimize field to struct diff_options, which would support three modes: DIFF_OPT_NONE, DIFF_OPT_DRY_RUN, and DIFF_OPT_BUFFER. The appropriate value would be determined before calling diff_flush(), potentially in repo_diff_setup().

DIFF_OPT_NONE will be the code Peff provide, DIFF_OPT_DRY_RUN will optimize for --quiet, --name, --name-status, etc, so that we can return early if we found any change. DIFF_OPT_BUFFER will first emit changes and context around changes into a buffer (so there would be a map from file pair to change buffer), then operations after the buffer is built will use the buffer instead of calling xdl_diff().

However, I’m concerned that DIFF_OPT_BUFFER could lead to high memory usage in Git, and I’m not entirely sure if this trade-off is justified.

Thanks, Lidong

Previous: Junio C HamanoNext: Junio C Hamano
Message 24 of 35 in “git-diff: --ignore-matching-lines has no effect on the output when --name-only is used”
  1. hi@arnes.spaceJul 23, 2025
  2. Lidong YanJul 23, 2025
  3. Junio C HamanoJul 23, 2025
  4. Lidong YanJul 24, 2025
  5. Eric SunshineJul 24, 2025
  6. Lidong YanJul 24, 2025
  7. hi@arnes.spaceJul 25, 2025
  8. hi@arnes.spaceJul 25, 2025
  9. Lidong YanJul 25, 2025
  10. hi@arnes.spaceJul 25, 2025
  11. Jeff KingJul 25, 2025
  12. Junio C HamanoJul 25, 2025
  13. diff: ensure consistent diff behavior with -I<regex> across output formatsLidong Yan, Jul 29, 2025
  14. Junio C HamanoJul 30, 2025
  15. Jeff KingAug 2, 2025
  16. Lidong YanAug 3, 2025
  17. Junio C HamanoAug 3, 2025
  18. Junio C HamanoAug 4, 2025
  19. Jeff KingAug 4, 2025
  20. diff: ensure consistent diff behavior with -I<regex> across output formatsLidong Yan, Aug 3, 2025
  21. Junio C HamanoAug 4, 2025
  22. Lidong YanAug 4, 2025
  23. Junio C HamanoAug 4, 2025
  24. Lidong YanAug 5, 2025
  25. Junio C HamanoAug 5, 2025
  26. diff: ensure consistent diff behavior with ignore optionsLidong Yan, Aug 6, 2025
  27. Junio C HamanoAug 6, 2025
  28. Lidong YanAug 7, 2025
  29. Junio C HamanoAug 6, 2025
  30. Lidong YanAug 7, 2025
  31. diff: ensure consistent diff behavior with ignore optionsLidong Yan, Aug 7, 2025
  32. Junio C HamanoAug 7, 2025
  33. Lidong YanAug 8, 2025
  34. diff: ensure consistent diff behavior with ignore optionsLidong Yan, Aug 8, 2025
  35. Johannes SchindelinOct 16, 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.