From: Thomas Rast <trast@student.ethz.ch>
To: Johannes Sixt <j6t@kdbg.org>
Cc: Junio C Hamano <gitster@pobox.com>, <git@vger.kernel.org>
Subject: [PATCH 3/3] diff: tweak a _copy_ of diff_options with word-diff
Date: Wed, 14 Mar 2012 19:24:09 +0100 [thread overview]
Message-ID: <b7d30afe65910ffe614a894db65386477778c4da.1331749299.git.trast@student.ethz.ch> (raw)
In-Reply-To: <3bb99e938624ae674674b304c24c48b9dc05871b.1331749299.git.trast@student.ethz.ch>
When using word diff, the code sets the word_regex from various
defaults if it was not set already. The problem is that it does this
on the original diff_options, which will also be used in subsequent
diffs.
This means that when the word_regex is not given on the command line,
only the first diff for which a setting for word_regex (either from
attributes or diff.wordRegex) ever takes effect. This value then
propagates to the rest of the diff runs and in particular prevents
further attribute lookups.
Fix the problem of changing diff state once and for all, by working
with a _copy_ of the diff_options.
Noticed-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
diff.c | 5 ++++-
t/t4034-diff-words.sh | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index aac86d3..c6104b9 100644
--- a/diff.c
+++ b/diff.c
@@ -1010,11 +1010,13 @@ static const char *userdiff_word_regex(struct diff_filespec *one)
}
static void init_diff_words_data(struct emit_callback *ecbdata,
- struct diff_options *o,
+ struct diff_options *orig_opts,
struct diff_filespec *one,
struct diff_filespec *two)
{
int i;
+ struct diff_options *o = xmalloc(sizeof(struct diff_options));
+ memcpy(o, orig_opts, sizeof(struct diff_options));
ecbdata->diff_words =
xcalloc(1, sizeof(struct diff_words_data));
@@ -1054,6 +1056,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
{
if (ecbdata->diff_words) {
diff_words_flush(ecbdata);
+ free (ecbdata->diff_words->opt);
free (ecbdata->diff_words->minus.text.ptr);
free (ecbdata->diff_words->minus.orig);
free (ecbdata->diff_words->plus.text.ptr);
diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh
index 69e81f3..c04756e 100755
--- a/t/t4034-diff-words.sh
+++ b/t/t4034-diff-words.sh
@@ -364,7 +364,7 @@ test_expect_success 'setup history with two files' '
git commit -mmodified -a
'
-test_expect_failure 'wordRegex for the first file does not apply to the second' '
+test_expect_success 'wordRegex for the first file does not apply to the second' '
echo "a diff=tex" >.gitattributes &&
git config diff.tex.wordRegex "[a-z]+|." &&
cat >expect <<-\EOF &&
--
1.7.10.rc0.286.gd2cb29
next prev parent reply other threads:[~2012-03-14 18:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-14 18:24 [PATCH v2 1/3] Demonstrate a bug in --word-diff where diff.*.wordregex is "sticky" Thomas Rast
2012-03-14 18:24 ` [PATCH 2/3] diff: refactor the word-diff setup from builtin_diff_cmd Thomas Rast
2012-03-14 19:26 ` Junio C Hamano
2012-03-14 18:24 ` Thomas Rast [this message]
2012-03-14 19:38 ` [PATCH 3/3] diff: tweak a _copy_ of diff_options with word-diff Junio C Hamano
2012-03-14 19:24 ` [PATCH v2 1/3] Demonstrate a bug in --word-diff where diff.*.wordregex is "sticky" Junio C Hamano
2012-03-14 19:50 ` [PATCH v3 " Johannes Sixt
2012-03-14 21:03 ` Stefano Lattarini
2012-03-14 21:38 ` Junio C Hamano
2012-03-14 21:53 ` Johannes Sixt
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=b7d30afe65910ffe614a894db65386477778c4da.1331749299.git.trast@student.ethz.ch \
--to=trast@student.ethz.ch \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
/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).