From: Jeff King <peff@peff.net>
To: Brian Henderson <henderson.bj@gmail.com>
Cc: git@vger.kernel.org, e@80x24.org, gitster@pobox.com
Subject: [PATCH 3/3] diff-highlight: avoid highlighting combined diffs
Date: Wed, 31 Aug 2016 01:05:38 -0400 [thread overview]
Message-ID: <20160831050538.53fki52cvwlmkd6y@sigill.intra.peff.net> (raw)
In-Reply-To: <20160831050229.cabhfzqcpcpvkugl@sigill.intra.peff.net>
The algorithm in diff-highlight only understands how to look
at two sides of a diff; it cannot correctly handle combined
diffs with multiple preimages. Often highlighting does not
trigger at all for these diffs because the line counts do
not match up. E.g., if we see:
- ours
-theirs
++resolved
we would not bother highlighting; it naively looks like a
single line went away, and then a separate hunk added
another single line.
But of course there are exceptions. E.g., if the other side
deleted the line, we might see:
- ours
++resolved
which looks like we dropped " ours" and added "+resolved".
This is only a small highlighting glitch (we highlight the
space and the "+" along with the content), but it's also the
tip of the iceberg. Even if we learned to find the true
content here (by noticing we are in a 3-way combined diff
and marking _two_ characters from the front of the line as
uninteresting), there are other more complicated cases where
we really do need to handle a 3-way hunk.
Let's just punt for now; we can recognize combined diffs by
the presence of extra "@" symbols in the hunk header, and
treat them as non-diff content.
Signed-off-by: Jeff King <peff@peff.net>
---
contrib/diff-highlight/diff-highlight | 2 +-
contrib/diff-highlight/t/t9400-diff-highlight.sh | 37 ++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/contrib/diff-highlight/diff-highlight b/contrib/diff-highlight/diff-highlight
index 9280c88..81bd804 100755
--- a/contrib/diff-highlight/diff-highlight
+++ b/contrib/diff-highlight/diff-highlight
@@ -36,7 +36,7 @@ $SIG{PIPE} = 'DEFAULT';
while (<>) {
if (!$in_hunk) {
print;
- $in_hunk = /^$GRAPH*$COLOR*\@/;
+ $in_hunk = /^$GRAPH*$COLOR*\@\@ /;
}
elsif (/^$GRAPH*$COLOR*-/) {
push @removed, $_;
diff --git a/contrib/diff-highlight/t/t9400-diff-highlight.sh b/contrib/diff-highlight/t/t9400-diff-highlight.sh
index 7d034aa..64dd9f7 100755
--- a/contrib/diff-highlight/t/t9400-diff-highlight.sh
+++ b/contrib/diff-highlight/t/t9400-diff-highlight.sh
@@ -254,4 +254,41 @@ test_expect_success 'diff-highlight works with the --graph option' '
test_cmp graph.exp graph.act
'
+# Most combined diffs won't meet diff-highlight's line-number filter. So we
+# create one here where one side drops a line and the other modifies it. That
+# should result in a diff like:
+#
+# - modified content
+# ++resolved content
+#
+# which naively looks like one side added "+resolved".
+test_expect_success 'diff-highlight ignores combined diffs' '
+ echo "content" >file &&
+ git add file &&
+ git commit -m base &&
+
+ >file &&
+ git commit -am master &&
+
+ git checkout -b other HEAD^ &&
+ echo "modified content" >file &&
+ git commit -am other &&
+
+ test_must_fail git merge master &&
+ echo "resolved content" >file &&
+ git commit -am resolved &&
+
+ cat >expect <<-\EOF &&
+ --- a/file
+ +++ b/file
+ @@@ -1,1 -1,0 +1,1 @@@
+ - modified content
+ ++resolved content
+ EOF
+
+ git show -c | "$DIFF_HIGHLIGHT" >actual.raw &&
+ sed -n "/^---/,\$p" <actual.raw >actual &&
+ test_cmp expect actual
+'
+
test_done
--
2.10.0.rc2.125.gcfb3d08
next prev parent reply other threads:[~2016-08-31 5:05 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-30 15:11 [PATCH 0/3] diff-highlight: add support for git log --graph output Brian Henderson
2016-07-30 15:11 ` [PATCH 1/3] diff-highlight: add some tests Brian Henderson
2016-08-10 8:56 ` Eric Wong
2016-08-15 16:20 ` Brian Henderson
2016-08-15 16:25 ` Junio C Hamano
2016-08-17 15:31 ` [PATCH v2 0/3] diff-highlight: add support for git log --graph output Brian Henderson
2016-08-19 21:19 ` Eric Wong
2016-08-19 21:23 ` Jeff King
2016-08-17 15:31 ` [PATCH v2 1/3] diff-highlight: add some tests Brian Henderson
2016-08-17 19:09 ` Junio C Hamano
2016-08-19 14:42 ` Brian Henderson
2016-08-19 14:51 ` Jeff King
2016-08-19 15:13 ` Brian Henderson
2016-08-19 17:08 ` [PATCH v3 0/3] diff-highlight: add support for git log --graph output Brian Henderson
2016-08-19 17:08 ` [PATCH v3 1/3] diff-highlight: add some tests Brian Henderson
2016-08-19 18:10 ` Junio C Hamano
2016-08-19 19:30 ` Brian Henderson
2016-08-19 20:56 ` Eric Wong
2016-08-19 20:18 ` [PATCH] " Brian Henderson
2016-08-19 20:44 ` Junio C Hamano
2016-08-19 21:04 ` Jeff King
2016-08-19 22:31 ` Junio C Hamano
2016-08-22 15:55 ` Brian Henderson
2016-08-23 4:12 ` Jeff King
2016-08-29 17:33 ` [PATCH v4 0/3] diff-highlight: add support for --graph option Brian Henderson
2016-08-29 17:33 ` [PATCH v4 1/3] diff-highlight: add some tests Brian Henderson
2016-08-29 17:33 ` [PATCH v4 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-08-29 17:33 ` [PATCH v4 3/3] diff-highlight: add support for " Brian Henderson
2016-08-29 21:37 ` [PATCH v4 0/3] diff-highlight: add support for --graph option Junio C Hamano
2016-08-30 14:07 ` Brian Henderson
2016-08-30 14:07 ` [PATCH v4 1/3] diff-highlight: add some tests Brian Henderson
2016-08-30 14:07 ` [PATCH v4 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-08-30 14:07 ` [PATCH v4 3/3] diff-highlight: add support for " Brian Henderson
2016-08-31 5:02 ` [PATCH v4 0/3] diff-highlight: add support for --graph option Jeff King
2016-08-31 5:02 ` [PATCH 1/3] diff-highlight: ignore test cruft Jeff King
2016-08-31 5:03 ` [PATCH 2/3] diff-highlight: add multi-byte tests Jeff King
2016-08-31 5:05 ` Jeff King [this message]
2016-08-30 8:11 ` [PATCH v4 0/3] diff-highlight: add support for --graph option Jeff King
2016-08-19 21:05 ` [PATCH] diff-highlight: add some tests Junio C Hamano
2016-08-19 17:08 ` [PATCH v3 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-08-19 18:25 ` Junio C Hamano
2016-08-19 17:08 ` [PATCH v3 3/3] diff-highlight: add support for " Brian Henderson
2016-08-19 18:27 ` Junio C Hamano
2016-08-17 15:31 ` [PATCH v2 2/3] diff-highlight: add failing test for handling " Brian Henderson
2016-08-17 19:18 ` Junio C Hamano
2016-08-17 15:31 ` [PATCH v2 3/3] diff-highlight: add support for " Brian Henderson
2016-08-19 14:37 ` Jeff King
2016-08-15 16:40 ` [PATCH 1/3] diff-highlight: add some tests Lars Schneider
2016-08-16 20:48 ` Junio C Hamano
2016-08-24 9:38 ` Lars Schneider
2016-07-30 15:11 ` [PATCH 2/3] diff-highlight: add failing test for handling --graph output Brian Henderson
2016-07-30 15:11 ` [PATCH 3/3] diff-highlight: add support for " Brian Henderson
2016-08-01 17:16 ` Junio C Hamano
2016-08-04 15:02 ` [PATCH] diff-highlight: Add comment for our assumption about " Brian Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160831050538.53fki52cvwlmkd6y@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=e@80x24.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=henderson.bj@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).