[PATCH 0/5] [RFC] diff: add diff.<driver>.process for external hunk providers
- From
Michael Montalbo via GitGitGadget <gitgitgadget@gmail.com>
- Date
- May 22, 2026, 02:11 UTC
- Message-ID
- <pull.2120.git.1779415884.gitgitgadget@gmail.com>
This series adds diff.<driver>.process, a long-running subprocess protocol that lets external tools provide hunks to git's diff and blame pipelines.
Over the past 18 years, git's diff pipeline accumulated many features that operate on hunks: word diff, function context, color-moved, indent heuristic, blame. External tools can replace the pipeline entirely (diff.<driver>.command) or select among builtin algorithms (diff.<driver>.algorithm), but there is no way for a tool to provide line-change information into the pipeline. Tools that understand code structure (tree-sitter parsers, format-aware analyzers, tools like Difftastic and Mergiraf) must bypass git's pipeline and lose access to everything downstream.
The protocol follows filter.<driver>.process: pkt-line over stdin/stdout, capability negotiation, one tool invocation per git command. The tool receives file pairs and returns hunk descriptors that git feeds into the standard xdiff pipeline. All output features work normally.
Zero hunks with status=success means the tool considers the files equivalent. git diff shows no output for the file, and git blame skips the commit, attributing lines to earlier commits.
On error or tool crash, git falls back silently to the builtin diff algorithm. The feature is opt-in via diff.<driver>.process and .gitattributes; unconfigured files are unaffected.
The series includes git diff-process-normalize, a built-in tool that compares files line by line ignoring whitespace (same logic as "git diff -w" via xdiff_compare_lines):
[diff "cdiff"]
process = git diff-process-normalizeA whitespace-only boolean flag could serve this specific case. The subprocess protocol is more general, allowing any tool to participate without further changes to git.
Michael Montalbo (5): xdiff: support external hunks via xpparam_t userdiff: add diff.<driver>.process config diff: add long-running diff process via diff.<driver>.process blame: consult diff process for zero-hunk detection diff-process-normalize: add built-in whitespace normalizer
Documentation/config/diff.adoc | 10 + Documentation/gitattributes.adoc | 58 +++++ Makefile | 2 + blame.c | 43 +++- builtin.h | 1 + builtin/diff-process-normalize.c | 143 ++++++++++ diff-process.c | 203 +++++++++++++++ diff-process.h | 28 ++ diff.c | 25 ++ git.c | 1 + t/t4080-diff-process.sh | 430 +++++++++++++++++++++++++++++++ userdiff.c | 7 + userdiff.h | 2 + xdiff-interface.c | 7 +- xdiff/xdiff.h | 13 + xdiff/xdiffi.c | 98 ++++++- 16 files changed, 1063 insertions(+), 8 deletions(-) create mode 100644 builtin/diff-process-normalize.c create mode 100644 diff-process.c create mode 100644 diff-process.h create mode 100755 t/t4080-diff-process.sh
base-commit: 94f057755b7941b321fd11fec1b2e3ca5313a4e0 Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2120%2Fmmontalbo%2Fmm%2Fstructural-diff-backend-clean-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2120/mmontalbo/mm/structural-diff-backend-clean-v1 Pull-Request: https://github.com/gitgitgadget/git/pull/2120
-- gitgitgadget