]> git.neil.brown.name Git - wiggle.git/commitdiff
merge: Remove noise from --show-wiggles output.
authorNeilBrown <neilb@suse.de>
Fri, 1 Mar 2013 05:02:15 +0000 (16:02 +1100)
committerNeilBrown <neilb@suse.de>
Fri, 1 Mar 2013 05:02:15 +0000 (16:02 +1100)
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 <neilb@suse.de>
merge2.c
tests/simple/show-wiggle-3/Wmerge [new file with mode: 0644]
tests/simple/show-wiggle-3/new [new file with mode: 0644]
tests/simple/show-wiggle-3/new2 [new file with mode: 0644]
tests/simple/show-wiggle-3/orig [new file with mode: 0644]

index 26ea70eb9b82addca1a66e2bc36a0880191b3265..fffa3ee03d515957f4d441b8158511721bd5f1d0 100644 (file)
--- 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 (file)
index 0000000..f12e600
--- /dev/null
@@ -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 (file)
index 0000000..62809cb
--- /dev/null
@@ -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 (file)
index 0000000..c039f20
--- /dev/null
@@ -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 (file)
index 0000000..105f7f7
--- /dev/null
@@ -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.