From 15f78a1970a6d2c5cd41123864c44cb694b46d14 Mon Sep 17 00:00:00 2001
From: Paul Eggert
Date: Mon, 24 Feb 2014 21:38:02 -0800
Subject: [PATCH 1/2] diff: fix bug with -I and overlapping hunks
Problem reported by Vincent Lefevre in .
* 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.
---
src/context.c | 7 +++----
tests/Makefile.am | 1 +
tests/ignore-matching-lines | 47 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 51 insertions(+), 4 deletions(-)
create mode 100755 tests/ignore-matching-lines
diff --git a/src/context.c b/src/context.c
index dd79f89..42f1eed 100644
--- a/src/context.c
+++ b/src/context.c
@@ -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.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index dd2d514..005d9f0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -7,6 +7,7 @@ TESTS = \
excess-slash \
help-version \
function-line-vs-leading-space \
+ ignore-matching-lines \
label-vs-func \
new-file \
no-dereference \
diff --git a/tests/ignore-matching-lines b/tests/ignore-matching-lines
new file mode 100755
index 0000000..5db9ba3
--- /dev/null
+++ b/tests/ignore-matching-lines
@@ -0,0 +1,47 @@
+#!/bin/sh
+# --ignore-matching-lines
+
+# Bug reported by Vincent Lefevre in .
+
+. "${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
--
1.8.5.3