]> git.ipfire.org Git - thirdparty/git.git/commit
xdiff: support external hunks via xpparam_t
authorMichael Montalbo <mmontalbo@gmail.com>
Sun, 26 Jul 2026 18:51:21 +0000 (18:51 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 26 Jul 2026 21:03:54 +0000 (14:03 -0700)
commita410047a823fd80b9f7f176354faeabf6e8fbbd3
treeae2c963e8a24a9b0945628c231334c6686bf7387
parent7bb612a02b96eeeafd77846a8117aac5ec093712
xdiff: support external hunks via xpparam_t

Add two new xpparam_t fields (external_hunks, external_hunks_nr)
that let callers supply pre-computed hunks.  When set, xdl_diff()
populates the changed[] arrays from these hunks instead of running
the diff algorithm, then continues through compaction and emission
as usual.

Validate supplied hunks before use.  Out-of-bounds line numbers,
overlapping or out-of-order hunks, and misaligned unchanged runs are
treated as a malformed tool response: xdl_populate_hunks_from_external()
warns, returns -1, and xdl_diff() falls back to the builtin diff
algorithm for that file.  The run of unchanged lines between two hunks
(and before the first and after the last) must be the same length on
both sides; xdl_build_script() walks the two files in lockstep over
unchanged lines, so a balanced total is not enough.  Non-negative
counts and 1-based starts are instead caller preconditions, checked
with BUG(), since the caller normalizes hunks before this point.

On rejection xdl_diff() frees the environment it prepared and falls
through to xdl_do_diff(), which prepares a fresh one for the builtin
pass.

Skip trim_common_tail() in xdi_diff() when external hunks are
present, since external hunks reference line numbers in the
original content.

Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
xdiff-interface.c
xdiff/xdiff.h
xdiff/xdiffi.c
xdiff/xprepare.c
xdiff/xprepare.h