From: Thomas Rast <trast@student.ethz.ch>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org, "Santi Béjar" <santi@agolina.net>,
"Junio C Hamano" <junio@pobox.com>,
"Teemu Likonen" <tlikonen@iki.fi>
Subject: Re: [PATCH replacement for take 3 4/4] color-words: take an optional regular expression describing words
Date: Thu, 15 Jan 2009 11:40:16 +0100 [thread overview]
Message-ID: <200901151140.20215.trast@student.ethz.ch> (raw)
In-Reply-To: <200901150930.38100.trast@student.ethz.ch>
[-- Attachment #1: Type: text/plain, Size: 3984 bytes --]
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@xmailserver.org>
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);
if (c1 != 1) {
memcpy(buf + nb, ",", 1);
@@ -256,7 +269,7 @@ int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,
memcpy(buf + nb, " +", 2);
nb += 2;
- nb += xdl_num_out(buf + nb, c2 ? s2: 0);
+ nb += xdl_num_out(buf + nb, c2 ? s2: s2 - 1);
if (c2 != 1) {
memcpy(buf + nb, ",", 1);
Note how (for some reason I don't quite understand yet) "correcting"
the offsets involves subtracting 1 if there were no changes on that
side.
But skipping ahead to the end doesn't work if there are several such
instances where nothing was added. So I think it must be fixed as
follows.
---- 8< ----
diff --git a/diff.c b/diff.c
index 4174d88..d7bbf74 100644
--- a/diff.c
+++ b/diff.c
@@ -361,8 +361,9 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
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 @@
+ * libxdiff subtracts one from the offset if the corresponding
+ * length is 0. (This can only happen because we use
+ * --unified=0.)
*
* This breaks the assumption that minus_first == plus_first.
*
@@ -373,10 +374,9 @@ static void fn_out_diff_words_aux(void *priv, char *line, unsigned long len)
* 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)
+ if (plus_len == 0)
plus_begin = plus_end =
- diff_words->plus.orig[diff_words->plus.orig_nr - 1].end;
+ diff_words->plus.orig[plus_first + plus_len].end;
if (diff_words->current_plus != plus_begin)
fwrite(diff_words->current_plus,
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 744221b..875b464 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -156,4 +156,40 @@ test_expect_success 'test when words are only removed at the end' '
'
+echo 'abcd(Xefghijklmn(YZopqrst' > pre
+echo 'abcd(efghijklmn(opqrst' > post
+
+cat > expect <<\EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index 434ff54..c4bb9f1 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<BROWN>@@ -1 +1 @@<RESET>
+abcd(<RED>X<RESET>efghijklmn(<RED>YZ<RESET>opqrst
+EOF
+
+test_expect_success 'no added words' '
+
+ word_diff --color-words=.
+
+'
+
+echo 'abcd(efghijklmn(opqrst' > pre
+echo 'abcd(Xefghijklmn(YZopqrst' > post
+
+cat > expect <<\EOF
+<WHITE>diff --git a/pre b/post<RESET>
+<WHITE>index c4bb9f1..434ff54 100644<RESET>
+<WHITE>--- a/pre<RESET>
+<WHITE>+++ b/post<RESET>
+<BROWN>@@ -1 +1 @@<RESET>
+abcd(<GREEN>X<RESET>efghijklmn(<GREEN>YZ<RESET>opqrst
+EOF
+
+test_expect_success 'no removed words' '
+
+ word_diff --color-words=.
+
+'
+
test_done
--
1.6.1.283.g653b2
--
Thomas Rast
trast@{inf,student}.ethz.ch
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2009-01-15 10:41 UTC|newest]
Thread overview: 109+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-11 19:58 [PATCH 0/4] refactor the --color-words to make it more hackable Johannes Schindelin
2009-01-11 19:59 ` [PATCH 1/4] Add color_fwrite(), a function coloring each line individually Johannes Schindelin
2009-01-11 22:43 ` Junio C Hamano
2009-01-11 23:49 ` Johannes Schindelin
2009-01-11 23:49 ` [PATCH v2 " Johannes Schindelin
2009-01-12 1:27 ` Jakub Narebski
2009-01-11 19:59 ` [PATCH 2/4] color-words: refactor word splitting and use ALLOC_GROW() Johannes Schindelin
2009-01-11 19:59 ` [PATCH 3/4] color-words: refactor to allow for 0-character word boundaries Johannes Schindelin
2009-01-11 23:08 ` Junio C Hamano
2009-01-11 23:38 ` Johannes Schindelin
2009-01-12 8:47 ` Thomas Rast
2009-01-12 9:36 ` Junio C Hamano
2009-01-11 20:00 ` [PATCH 4/4] color-words: take an optional regular expression describing words Johannes Schindelin
2009-01-11 21:53 ` [PATCH 0/4] refactor the --color-words to make it more hackable Thomas Rast
2009-01-11 23:02 ` Johannes Schindelin
2009-01-12 6:25 ` Thomas Rast
2009-01-14 13:00 ` Santi Béjar
2009-01-14 17:49 ` [PATCH take 3 0/4] color-words improvements Johannes Schindelin
2009-01-14 17:50 ` [PATCH 1/4] Add color_fwrite_lines(), a function coloring each line individually Johannes Schindelin
2009-01-14 17:50 ` [PATCH 2/4] color-words: refactor word splitting and use ALLOC_GROW() Johannes Schindelin
2009-01-14 17:51 ` [PATCH 3/4] color-words: change algorithm to allow for 0-character word boundaries Johannes Schindelin
2009-01-14 18:08 ` Johannes Schindelin
2009-01-14 17:51 ` [PATCH 4/4] color-words: take an optional regular expression describing words Johannes Schindelin
2009-01-14 19:55 ` Thomas Rast
2009-01-14 18:54 ` [PATCH take 3 0/4] color-words improvements Teemu Likonen
2009-01-14 18:57 ` Teemu Likonen
2009-01-14 19:28 ` Johannes Schindelin
2009-01-14 19:32 ` Johannes Schindelin
2009-01-14 20:44 ` [PATCH replacement for take 3 3/4] color-words: change algorithm to allow for 0-character word boundaries Johannes Schindelin
2009-01-14 20:46 ` [PATCH replacement for take 3 4/4] color-words: take an optional regular expression describing words Johannes Schindelin
2009-01-15 0:32 ` Thomas Rast
2009-01-15 1:12 ` Johannes Schindelin
2009-01-15 1:36 ` Johannes Schindelin
2009-01-15 8:30 ` Thomas Rast
2009-01-15 10:40 ` Thomas Rast [this message]
2009-01-15 12:54 ` Johannes Schindelin
2009-01-14 19:58 ` [PATCH take 3 0/4] color-words improvements Thomas Rast
2009-01-14 22:06 ` Johannes Schindelin
2009-01-14 22:11 ` Thomas Rast
2009-01-14 22:24 ` Boyd Stephen Smith Jr.
2009-01-15 4:56 ` Teemu Likonen
2009-01-15 12:41 ` Johannes Schindelin
2009-01-15 13:03 ` Teemu Likonen
2009-01-15 13:27 ` Thomas Rast
2009-01-15 18:15 ` Junio C Hamano
2009-01-15 19:25 ` Johannes Schindelin
2009-01-16 0:10 ` Santi Béjar
2009-01-16 1:37 ` Junio C Hamano
2009-01-16 1:42 ` Boyd Stephen Smith Jr.
2009-01-16 1:55 ` Johannes Schindelin
2009-01-16 9:02 ` Santi Béjar
2009-01-16 11:57 ` Johannes Schindelin
2009-01-16 12:01 ` Santi Béjar
2009-01-16 12:40 ` Johannes Schindelin
2009-01-16 19:04 ` Thomas Rast
2009-01-16 21:09 ` Johannes Schindelin
2009-01-17 16:29 ` [PATCH v4 0/7] customizable --color-words Thomas Rast
2009-01-17 16:29 ` [PATCH v4 1/7] Add color_fwrite_lines(), a function coloring each line individually Thomas Rast
2009-01-17 16:29 ` [PATCH v4 2/7] color-words: refactor word splitting and use ALLOC_GROW() Thomas Rast
2009-01-17 16:29 ` [PATCH v4 3/7] color-words: change algorithm to allow for 0-character word boundaries Thomas Rast
2009-01-17 16:29 ` [PATCH v4 4/7] color-words: take an optional regular expression describing words Thomas Rast
2009-01-17 16:29 ` [PATCH v4 5/7] color-words: enable REG_NEWLINE to help user Thomas Rast
2009-01-17 16:29 ` [PATCH v4 6/7] color-words: expand docs with precise semantics Thomas Rast
2009-01-17 16:29 ` [PATCH v4 7/7] color-words: make regex configurable via attributes Thomas Rast
2009-01-18 15:05 ` [PATCH v4 0/7] customizable --color-words Santi Béjar
2009-01-18 15:29 ` Santi Béjar
2009-01-19 22:47 ` Santi Béjar
2009-01-19 23:35 ` Johannes Schindelin
2009-01-20 2:17 ` [PATCH] Add tests for diff.color-words configuration option Boyd Stephen Smith Jr.
2009-01-20 3:45 ` [PATCH] diff: Support diff.color-words config option Boyd Stephen Smith Jr.
2009-01-20 6:59 ` Junio C Hamano
2009-01-20 17:42 ` Markus Heidelberg
2009-01-20 17:58 ` Boyd Stephen Smith Jr.
2009-01-20 21:08 ` Johannes Schindelin
2009-01-21 10:27 ` Junio C Hamano
2009-01-21 19:37 ` Markus Heidelberg
2009-01-20 10:02 ` Johannes Schindelin
2009-01-20 16:52 ` Boyd Stephen Smith Jr.
2009-01-20 17:14 ` Johannes Schindelin
2009-01-20 17:09 ` Junio C Hamano
2009-01-20 17:28 ` Johannes Schindelin
2009-01-20 20:27 ` Junio C Hamano
2009-01-20 21:02 ` Johannes Schindelin
2009-01-21 3:46 ` [PATCH] color-words: " Boyd Stephen Smith Jr.
2009-01-21 4:59 ` [PATCH] Change the spelling of "wordregex" Boyd Stephen Smith Jr.
2009-01-21 8:26 ` Johannes Schindelin
2009-01-21 9:22 ` Thomas Rast
2009-01-21 15:33 ` Boyd Stephen Smith Jr.
2009-01-21 8:25 ` [PATCH] color-words: Support diff.color-words config option Johannes Schindelin
2009-01-21 16:09 ` Boyd Stephen Smith Jr.
2009-01-21 10:27 ` [PATCH] color-words: Support diff.wordregex " Junio C Hamano
2009-01-20 14:38 ` [PATCH] diff: Support diff.color-words " Jakub Narebski
2009-01-20 9:58 ` [PATCH] Add tests for diff.color-words configuration option Johannes Schindelin
2009-01-20 16:34 ` Boyd Stephen Smith Jr.
2009-01-20 16:54 ` Johannes Schindelin
2009-01-16 16:11 ` [PATCH take 3 0/4] color-words improvements Boyd Stephen Smith Jr.
2009-01-14 19:46 ` [PATCH] color-words: make regex configurable via attributes Thomas Rast
2009-01-14 20:12 ` Johannes Schindelin
2009-01-14 20:17 ` Thomas Rast
2009-01-14 22:26 ` [PATCH 1/4] color-words: fix quoting in t4034 Thomas Rast
2009-01-14 22:41 ` Johannes Schindelin
2009-01-14 22:26 ` [PATCH 2/4] color-words: enable REG_NEWLINE to help user Thomas Rast
2009-01-14 22:26 ` [PATCH 3/4] color-words: expand docs with precise semantics Thomas Rast
2009-01-14 22:26 ` [PATCH 4/4] color-words: make regex configurable via attributes Thomas Rast
2009-01-15 1:33 ` Johannes Schindelin
2009-01-15 1:43 ` Johannes Schindelin
2009-01-14 20:04 ` [PATCH take 3 0/4] color-words improvements Thomas Rast
2009-01-14 21:07 ` Johannes Schindelin
2009-01-14 22:37 ` Thomas Rast
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200901151140.20215.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=junio@pobox.com \
--cc=santi@agolina.net \
--cc=tlikonen@iki.fi \
/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.
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 NNTP newsgroup(s).