From a25ea5bf02ad12620e78a4d7b8d3603d0b1240ea Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 1 Mar 2013 16:02:15 +1100 Subject: [PATCH] merge: Remove noise from --show-wiggles output. When --show-wiggles is used with whole files (current, orig, new) and extraneous text in orig/new (Which isn't a change, so should be ignored) is treated as a wiggle and causes a conflict to be shown. Obviously not good. So insist that any show-wiggle conflict contains at leas a Changed or a Conflict. Also allow Changed and Unmatched to be 'near' each other, not only on the same line, to signal a wiggle. Current 'near' measure is 3 lines. Signed-off-by: NeilBrown --- merge2.c | 42 +++++++++++++++++++++++-------- tests/simple/show-wiggle-3/Wmerge | 15 +++++++++++ tests/simple/show-wiggle-3/new | 10 ++++++++ tests/simple/show-wiggle-3/new2 | 10 ++++++++ tests/simple/show-wiggle-3/orig | 9 +++++++ 5 files changed, 76 insertions(+), 10 deletions(-) create mode 100644 tests/simple/show-wiggle-3/Wmerge create mode 100644 tests/simple/show-wiggle-3/new create mode 100644 tests/simple/show-wiggle-3/new2 create mode 100644 tests/simple/show-wiggle-3/orig diff --git a/merge2.c b/merge2.c index 26ea70e..fffa3ee 100644 --- a/merge2.c +++ b/merge2.c @@ -108,10 +108,8 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf, * a newline. * * If 'show_wiggles' is set we treat wiggles like conflicts. - * A 'wiggle' is implied by any Extraneous text being ignored, - * or any line that has both Changed and Unmatched content. - * (Unmatched content where nothing is changed is common and not - * really a 'wiggle'). + * A 'wiggle' is implied by any Extraneous text or Unmatched + * text which is close (+/- 3 lines) to a Changed text. * * A hunk header is never considered part of a conflict. It * thereby can serve as a separator between conflicts. @@ -127,18 +125,23 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf, int cnt = 0; int changed = 0; int unmatched = 0; + int extraneous = 0; for (i = 0; m[i].type != End; i++) m[i].in_conflict = 0; for (i = 0; m[i].type != End; i++) { if (m[i].type == Changed && !m[i].ignored) - changed = 1; + changed = 3; if (m[i].type == Unmatched) - unmatched = 1; + unmatched = 3; + if (m[i].type == Extraneous && bf.list[m[i].b].start[0]) + /* hunk headers don't imply wiggles, other + * extraneous text does. + */ + extraneous = 3; if ((m[i].type == Conflict && m[i].ignored == 0) || - (show_wiggles && ((changed && unmatched) - || m[i].type == Extraneous))) { + (show_wiggles && changed && (unmatched || extraneous))) { /* We have a conflict (or wiggle) here. * First search backwards for an Unchanged marking * things as in_conflict. Then find the @@ -302,10 +305,29 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf, } } i = j - 1; + + while (--j >= 0 && m[j].in_conflict) { + if ((m[j].type == Changed || m[j].type == Unchanged) + && m[j].hi >= m[j].lo) { + m[j].hi = m[j].al; + j++; + break; + } + if (m[j].type == Changed || m[j].type == Conflict) + goto out; + } + /* False alarm, no real conflict/wiggle here */ + while (j <= i) + m[j++].in_conflict = 0; + out:; } if (m[i].al > 0 && ends_line(af.list[m[i].a+m[i].al-1])) { - unmatched = 0; - changed = 0; + if (unmatched) + unmatched--; + if (changed) + changed--; + if (extraneous) + extraneous--; } } return cnt; diff --git a/tests/simple/show-wiggle-3/Wmerge b/tests/simple/show-wiggle-3/Wmerge new file mode 100644 index 0000000..f12e600 --- /dev/null +++ b/tests/simple/show-wiggle-3/Wmerge @@ -0,0 +1,15 @@ +This is a test for show-merge +mode of wiggle where there +are other extraneous sections of text +that should not cause an extra wiggle + + +<<<<<<< +Here is a line +||||||| +Here was a line +======= +Here will be a line +>>>>>>> + +There is nothing else. diff --git a/tests/simple/show-wiggle-3/new b/tests/simple/show-wiggle-3/new new file mode 100644 index 0000000..62809cb --- /dev/null +++ b/tests/simple/show-wiggle-3/new @@ -0,0 +1,10 @@ +This is a test for show-merge +mode of wiggle where there +are other extraneous sections of text +that should not cause an extra wiggle + + +Here was a line + +There is nothing else. +At least, not much. diff --git a/tests/simple/show-wiggle-3/new2 b/tests/simple/show-wiggle-3/new2 new file mode 100644 index 0000000..c039f20 --- /dev/null +++ b/tests/simple/show-wiggle-3/new2 @@ -0,0 +1,10 @@ +This is a test for show-merge +mode of wiggle where there +are other extraneous sections of text +that should not cause an extra wiggle + + +Here will be a line + +There is nothing else. +At least, not much. diff --git a/tests/simple/show-wiggle-3/orig b/tests/simple/show-wiggle-3/orig new file mode 100644 index 0000000..105f7f7 --- /dev/null +++ b/tests/simple/show-wiggle-3/orig @@ -0,0 +1,9 @@ +This is a test for show-merge +mode of wiggle where there +are other extraneous sections of text +that should not cause an extra wiggle + + +Here is a line + +There is nothing else. -- 2.39.5