freenode
Languages & Toolchains

Git RFC proposes external hunk providers for smarter diffs

A long-running process protocol would let tools like Difftastic decide which lines changed while Git keeps formatting, blame, and log -L.

Git may gain a way for external, language-aware diff tools to supply change regions without surrendering control of how those changes are shown. Michael Montalbo has posted an RFC series that adds diff..process, a long-running subprocess protocol so a tool can say which lines differ while Git still owns patch formatting, color, word diff, function context, blame, stat summaries, and git log -L.

Today's external diff driver, diff..command, replaces Git's entire patch output with the program's own text. Display features that post-process Git's diff cannot run on that output, and blame, --stat, and line-range history never consult the driver at all, so they keep using the builtin line matcher. Language-aware tools such as Difftastic can produce better matching than that algorithm, but users who wire them in through the existing command interface lose Git's surrounding machinery and cannot share the better matching with blame or log -L.

The proposed process driver follows the existing filter process model: pkt-line over stdin and stdout, capability negotiation, one subprocess per Git invocation. The tool receives both file versions (and, when the content is a raw blob, the blob object names for caching) and returns old and new line ranges. Git validates those hunks, feeds them into its xdiff pipeline, and treats an empty successful reply as "no changes," which then flows through patch output, exit codes, --stat, blame attribution, and line-range tracking. Malformed replies warn and fall back to the builtin algorithm for that file; an abort falls back and stops further requests for the session.

Bypass paths are explicit. --no-ext-diff turns the process off along with command-style external diffs, format-patch always uses the builtin algorithm so generated patches stay portable, and an explicit --diff-algorithm choice also skips the process. Documentation spells out which features consult the tool and which do not (pickaxe, patch-id, merge, range-diff, and combined diffs among them), including known asymmetries such as summary formats seeing raw blobs while patch output may see textconv-transformed content.

Git maintainer Junio C Hamano flagged that the series conflicts with another in-flight line-log topic. Montalbo said he would rebase and make the two work together. The work remains an RFC; it is not yet in a released Git.