Hi,
On Thu, 15 Jan 2009, Johannes Schindelin wrote:
[PATCH to be squashed into the word regex patch] Fix for strange '@@ -2 +1,0 @@' hunk header
If a hunk header '@@ -2 +1,0 @@' is found that logically should be
'@@ -2 +2,0 @@', diff_words got confused.
It would bee squashed into 4/4.
This might be a libxdiff issue, though.
Not sure yet.
---
diff.c | 18 ++++++++++++++++++
t/t4034-diff-words.sh | 16 ++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/diff.c b/diff.c
index c5f7c57..3709651 100644
--- a/diff.c
+++ b/diff.c
@@ -360,6 +360,24 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
plus_end = plus_len == 0 ? plus_begin :
diff_words->plus.orig[plus_first + plus_len - 1].end;
+ /*
+ * since this is a --unified=0 diff, it can result in a single hunk
+ * with a header like this: @@ -2 +1,0 @@
+ *
+ * This breaks the assumption that minus_first == plus_first.
+ *
+ * So we have to fix it: whenever we reach the end of pre and post
+ * texts, but nothing was added, we need to shift the plus part
+ * to the end of the buffer.
+ *
+ * It is only necessary for the plus part, as we show the common
+ * words from that buffer.
+ */
+ if (plus_len == 0 && minus_first + minus_len
+ == diff_words->minus.orig_nr)
+ plus_begin = plus_end =
+ diff_words->plus.orig[diff_words->plus.orig_nr - 1].end;
+
if (diff_words->current_plus != plus_begin)
fwrite(diff_words->current_plus,
plus_begin - diff_words->current_plus, 1,
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 07e48d1..817fba6 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -135,6 +135,22 @@ test_expect_success 'test parsing words for newline' '
word_diff --color-words="a+"
+'
+
+echo '(:' > pre
+echo '(' > post
+
+cat > expect <<\EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index 289cb9d..2d06f37 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<BROWN>@@ -1 +1 @@<RESET>
+(<RED>:<RESET>
+EOF
+
+test_expect_success 'test when words are only removed at the end' '
+
word_diff --color-words=.
'
--
1.6.1.300.gbc493
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html