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, Thomas Rast wrote:

> Thomas Rast wrote:
> > Johannes Schindelin wrote:
> > > If a hunk header '@@ -2 +1,0 @@' is found that logically should be
> > > '@@ -2 +2,0 @@', diff_words got confused.
> > [...]
> > > This might be a libxdiff issue, though.
> > 
> > Looks like it's just bug-for-bug compatible with diff.  At least my
> > GNU diffutils 2.8.7 show the same behaviour.
> 
> I think the culprit is in
> 
>   commit ca557afff9f7dad7a8739cd193ac0730d872e282
>   Author: Davide Libenzi <davidel@xxxxxxxxxxxxxxx>
>   Date:   Mon Apr 3 18:47:55 2006 -0700
> 
>       Clean-up trivially redundant diff.
> 
>       Also corrects the line numbers in unified output when using
>       zero lines context.
> [...]
> diff --git a/xdiff/xutils.c b/xdiff/xutils.c
> [...]
>   @@ -244,7 +257,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
>           memcpy(buf, "@@ -", 4);
>           nb += 4;
> 
>   -       nb += xdl_num_out(buf + nb, c1 ? s1: 0);
>   +       nb += xdl_num_out(buf + nb, c1 ? s1: s1 - 1);

Junio mentioned some POSIX document in which this behavior is actually 
required.  So I'll fix my code thusly:

-- snipsnap --
diff --git a/diff.c b/diff.c
index 3709651..219a242 100644
--- a/diff.c
+++ b/diff.c
@@ -353,30 +353,20 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
 			&minus_first, &minus_len, &plus_first, &plus_len))
 		return;
 
-	minus_begin = diff_words->minus.orig[minus_first].begin;
-	minus_end = minus_len == 0 ? minus_begin :
-		diff_words->minus.orig[minus_first + minus_len - 1].end;
-	plus_begin = diff_words->plus.orig[plus_first].begin;
-	plus_end = plus_len == 0 ? plus_begin :
-		diff_words->plus.orig[plus_first + plus_len - 1].end;
+	/* POSIX requires that first be decremented by one if len == 0... */
+	if (minus_len) {
+		minus_begin = diff_words->minus.orig[minus_first].begin;
+		minus_end =
+			diff_words->minus.orig[minus_first + minus_len - 1].end;
+	} else
+		minus_begin = minus_end =
+			diff_words->minus.orig[minus_first].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 (plus_len) {
+		plus_begin = diff_words->plus.orig[plus_first].begin;
+		plus_end = diff_words->plus.orig[plus_first + plus_len - 1].end;
+	} else
+		plus_begin = plus_end = diff_words->plus.orig[plus_first].end;
 
 	if (diff_words->current_plus != plus_begin)
 		fwrite(diff_words->current_plus,
-- 
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