Re: [PATCH replacement for take 3 4/4] color-words: take an optional regular expression describing words

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Thu, 15 Jan 2009, Johannes Schindelin wrote:

> On Thu, 15 Jan 2009, Thomas Rast wrote:
> 
> > Johannes Schindelin wrote:
> > > 	This basically contains the fix I sent earlier.
> > 
> > Unfortunately I found another case where it breaks.  It even comes
> > with a fairly neat test case:
> > 
> >   $ g diff --no-index test_a test_b
> >   diff --git 1/test_a 2/test_b
> >   index 289cb9d..2d06f37 100644
> >   --- 1/test_a
> >   +++ 2/test_b
> >   @@ -1 +1 @@
> >   -(:
> >   +(
> 
> The diff of the words would look like this:
> 
> diff --git a/a1 b/a2
> index 8309acb..2d06f37 100644
> --- a/a1
> +++ b/a2
> @@ -2 +1,0 @@
> -:
> 
> 
> Notice the "+1,0"?  I fully expected this to be "+2,0", but apparently I 
> was mistaken...
> 
> Can anybody explain to me why this is so?

[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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux