Skip to content

Commit 6440d34

Browse files
trastgitster
authored andcommitted
diff: tweak a _copy_ of diff_options with word-diff
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 <[email protected]> Signed-off-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77d1a52 commit 6440d34

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,13 @@ static const char *userdiff_word_regex(struct diff_filespec *one)
10081008
}
10091009

10101010
static void init_diff_words_data(struct emit_callback *ecbdata,
1011-
struct diff_options *o,
1011+
struct diff_options *orig_opts,
10121012
struct diff_filespec *one,
10131013
struct diff_filespec *two)
10141014
{
10151015
int i;
1016+
struct diff_options *o = xmalloc(sizeof(struct diff_options));
1017+
memcpy(o, orig_opts, sizeof(struct diff_options));
10161018

10171019
ecbdata->diff_words =
10181020
xcalloc(1, sizeof(struct diff_words_data));
@@ -1052,6 +1054,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)
10521054
{
10531055
if (ecbdata->diff_words) {
10541056
diff_words_flush(ecbdata);
1057+
free (ecbdata->diff_words->opt);
10551058
free (ecbdata->diff_words->minus.text.ptr);
10561059
free (ecbdata->diff_words->minus.orig);
10571060
free (ecbdata->diff_words->plus.text.ptr);

t/t4034-diff-words.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ test_expect_success 'setup history with two files' '
365365
git commit -mmodified -a
366366
'
367367
368-
test_expect_failure 'wordRegex for the first file does not apply to the second' '
368+
test_expect_success 'wordRegex for the first file does not apply to the second' '
369369
echo "*.tex diff=tex" >.gitattributes &&
370370
git config diff.tex.wordRegex "[a-z]+|." &&
371371
cat >expect <<-\EOF &&

0 commit comments

Comments
 (0)