Skip to content

pr-2320/gremat/feat/diff-highlight-support-range-diff-output-v1

tagged this 24 Nov 08:49
From: gremat <gremat@nextron-systems.com>

The output of "git range-diff" is a diff of diffs: each line carries
an outer marker (how the patch changed between versions) followed by
an inner marker (what the patch itself does), and the whole thing is
indented by four columns below a commit pair header such as

    1:  abc1234 ! 1:  def5678 subject

diff-highlight currently does not highlight anything in such output.
It neither strips the indentation nor recognizes the "@@" hunk header
that range-diff colors differently, and even when a removed/added
pair is found, is_pair_interesting() rejects it because the common
prefix contains the second marker.

Teach diff-highlight to:

  - recognize the range-diff commit pair header, and strip the
    four-column indentation of the following lines the same way we
    strip a --graph prefix;

  - accept color codes between "@@" and the following space when
    looking for a hunk header;

  - accept either the outer or the inner marker as the one forming a
    removed/added pair in is_pair_interesting();

  - pair up lines that share the same outer marker but form a
    removed/added pair in the inner diff (e.g. "+-old" and "++new",
    when a new version of a patch starts modifying a line), falling
    back to that when the outer hunk cannot be paired line by line.

Apart from the more lenient hunk header match, non-range-diff input is
not affected, as the new behavior is guarded
by the range-diff header having been seen.

Signed-off-by: gremat <gremat@nextron-systems.com>

Submitted-As: https://lore.kernel.org/git/pull.2320.git.1795510197963.gitgitgadget@gmail.com
Assets 2
Loading