diff: fix bug with -I and overlapping hunks

Problem reported by Vincent Lefevre in <http://bugs.gnu.org/16864>.
* src/context.c (find_hunk): Threshold is CONTEXT only if
the second change is ignorable.
* tests/ignore-matching-lines: New test.
* tests/Makefile.am (TESTS): Add it.
This commit is contained in:
Paul Eggert 2014-02-24 21:38:02 -08:00
parent 9b48bf3d3e
commit c26334b7df
3 changed files with 51 additions and 4 deletions

View File

@ -402,9 +402,8 @@ find_hunk (struct change *start)
lin top0, top1;
lin thresh;
/* Threshold distance is 2 * CONTEXT + 1 between two non-ignorable
changes, but only CONTEXT if one is ignorable. Watch out for
integer overflow, though. */
/* Threshold distance is CONTEXT if the second change is ignorable,
2 * CONTEXT + 1 otherwise. Watch out for integer overflow. */
lin non_ignorable_threshold =
(LIN_MAX - 1) / 2 < context ? LIN_MAX : 2 * context + 1;
lin ignorable_threshold = context;
@ -416,7 +415,7 @@ find_hunk (struct change *start)
top1 = start->line1 + start->inserted;
prev = start;
start = start->link;
thresh = (prev->ignore || (start && start->ignore)
thresh = (start && start->ignore
? ignorable_threshold
: non_ignorable_threshold);
/* It is not supposed to matter which file we check in the end-test.

View File

@ -7,6 +7,7 @@ TESTS = \
excess-slash \
help-version \
function-line-vs-leading-space \
ignore-matching-lines \
label-vs-func \
new-file \
no-dereference \

47
tests/ignore-matching-lines Executable file
View File

@ -0,0 +1,47 @@
#!/bin/sh
# --ignore-matching-lines
# Bug reported by Vincent Lefevre in <http://bugs.gnu.org/16864>.
. "${srcdir=.}/init.sh"; path_prepend_ ../src
fail=0
cat <<'EOF' >a
1a
2
3a
4
5
6
EOF
cat <<'EOF' >b
1b
2
3b
4
5
6
7
EOF
cat <<'EOF' >exp
@@ -1,6 +1,7 @@
-1a
+1b
2
-3a
+3b
4
5
6
+7
EOF
diff -u --ignore-matching-lines 3 a b >out 2>err
test $? = 1 || fail=1
sed 1,2d out >outtail || framework_failure+
compare exp outtail || fail=1
Exit $fail