]> git.ipfire.org Git - thirdparty/git.git/commit - xdiff-interface.c
diff: fix "multiple regexp" semantics to find hunk header comment
authorJunio C Hamano <gitster@pobox.com>
Sat, 20 Sep 2008 07:52:11 +0000 (00:52 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sat, 20 Sep 2008 07:52:11 +0000 (00:52 -0700)
commit3d8dccd74aa29a9019c4e8b52e75a40189e6f5cb
tree909f000e201535f714e52bef7cf142ddb25a62eb
parent1883a0d3b7ad7c9de1ac790bda6f1a6181237439
diff: fix "multiple regexp" semantics to find hunk header comment

When multiple regular expressions are concatenated with "\n", they were
traditionally AND'ed together, and only a line that matches _all_ of them
is taken as a match.  This however is unwieldy when multiple regexp
feature is used to specify alternatives.

This fixes the semantics to take the first match.  A nagative pattern, if
matches, makes the line to fail as before.  A match with a positive
pattern will be the final match, and what it captures in $1 is used as the
hunk header comment.

We could write alternatives using "|" in ERE, but the machinery can only
use captured $1 as the hunk header comment (or $0 if there is no match in
$1), so you cannot write:

    "junk ( A | B ) | garbage ( C | D )"

and expect both "junk" and "garbage" to get stripped with the existing
code.  With this fix, you can write it as:

    "junk ( A | B ) \n garbage ( C | D )"

and the way capture works would match the user expectation more
naturally.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff.c
xdiff-interface.c