]> git.neil.brown.name Git - wiggle.git/commitdiff
vpatch: allow changes to be ignored as well as conflict.
authorNeilBrown <neilb@suse.de>
Thu, 15 Nov 2012 02:45:51 +0000 (13:45 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 15 Nov 2012 02:45:51 +0000 (13:45 +1100)
Because sometimes a 'change' that is found is really a conflict.

Signed-off-by: NeilBrown <neilb@suse.de>
merge2.c
vpatch.c
wiggle.h

index 8520082bf55b2af7865670fab2c6afc0ed66401b..92f5c22ca97635c0f4a86dab62bd5342e3405b42 100644 (file)
--- a/merge2.c
+++ b/merge2.c
@@ -132,11 +132,11 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf,
                m[i].in_conflict = 0;
 
        for (i = 0; m[i].type != End; i++) {
-               if (m[i].type == Changed)
+               if (m[i].type == Changed && !m[i].ignored)
                        changed = 1;
                if (m[i].type == Unmatched)
                        unmatched = 1;
-               if ((m[i].type == Conflict && m[i].conflict_ignored == 0) ||
+               if ((m[i].type == Conflict && m[i].ignored == 0) ||
                    (show_wiggles && ((changed && unmatched)
                                        || m[i].type == Extraneous))) {
                        /* We have a conflict (or wiggle) here.
@@ -159,7 +159,7 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                if (!m[j].in_conflict) {
                                        m[j].in_conflict = 1;
                                        m[j].lo = 0;
-                               } else if (m[j].type == Changed) {
+                               } else if (m[j].type == Changed && !m[i].ignored) {
                                        /* This can no longer form a border */
                                        m[j].hi = -1;
                                        /* We merge these conflicts and stop searching */
@@ -172,7 +172,8 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                                        newlines++;
                                }
 
-                               if (m[j].type == Unchanged || m[j].type == Changed) {
+                               if (m[j].type == Unchanged ||
+                                   (m[j].type == Changed && !m[i].ignored)) {
                                        /* If we find enough newlines in this section,
                                         * then we only really need 1, but would rather
                                         * it wasn't the first one.  'firstk' allows us
@@ -204,7 +205,8 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                        else
                                                /* no start-of-line found... */
                                                m[j].hi = -1;
-                                       if (m[j].hi > 0 && m[j].type == Changed) {
+                                       if (m[j].hi > 0 &&
+                                           (m[j].type == Changed && !m[j].ignored)) {
                                                /* this can only work if start is
                                                 * also a line break */
                                                if (is_cutpoint(m[j], af,bf,cf))
@@ -230,7 +232,8 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                                if (ends_line(bf.list[m[j].b+k]))
                                                        newlines++;
                                }
-                               if (m[j].type == Unchanged || m[j].type == Changed) {
+                               if (m[j].type == Unchanged ||
+                                   (m[j].type == Changed && !m[j].ignored)) {
                                        m[j].hi = m[j].al;
                                        if (words) {
                                                m[j].lo = 0;
@@ -279,7 +282,8 @@ int isolate_conflicts(struct file af, struct file bf, struct file cf,
                                                        /* no start-of-line found */
                                                        m[j].lo = m[j].al+1;
                                        }
-                                       if (m[j].lo <= m[j].al+1 && m[j].type == Changed) {
+                                       if (m[j].lo <= m[j].al+1 &&
+                                           (m[j].type == Changed && !m[j].ignored)) {
                                                /* this can only work if the end is a line break */
                                                if (is_cutpoint(m[j+1], af,bf,cf))
                                                        /* ok */;
@@ -337,7 +341,7 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
                rv.merger[i].c1 = c1;
                rv.merger[i].c2 = c2;
                rv.merger[i].in_conflict = 0;
-               rv.merger[i].conflict_ignored = 0;
+               rv.merger[i].ignored = 0;
 
                if (!match1 && match2) {
                        /* This is either Unmatched or Extraneous - probably both.
@@ -464,7 +468,7 @@ struct ci make_merger(struct file af, struct file bf, struct file cf,
        rv.merger[i].c1 = c1;
        rv.merger[i].c2 = c2;
        rv.merger[i].in_conflict = 0;
-       rv.merger[i].conflict_ignored = 0;
+       rv.merger[i].ignored = 0;
        assert(i < l);
        rv.conflicts = isolate_conflicts(af, bf, cf, csl1, csl2, words,
                                         rv.merger, show_wiggles);
@@ -509,12 +513,14 @@ void print_merge(FILE *out, struct file *a, struct file *b, struct file *c,
                         */
                        int found_conflict = 0;
                        int st = 0, st1;
-                       if (m->type == Unchanged || m->type == Changed)
+                       if (m->type == Unchanged ||
+                           (m->type == Changed && !m->ignored))
                                if (m->hi >= m->lo)
                                        st = m->hi;
                        st1 = st;
 
-                       if (m->type == Unchanged)
+                       if (m->type == Unchanged ||
+                           (m->type == Changed && m->ignored))
                                printrange(out, a, m->a+m->lo, m->hi - m->lo);
 
                        if (do_trace)
@@ -562,12 +568,13 @@ void print_merge(FILE *out, struct file *a, struct file *b, struct file *c,
                        fputs(words ? "===" : "=======\n", out);
                        st1 = st;
                        for (cm = m; cm->in_conflict; cm++) {
-                               if (cm->type == Unchanged &&
-                                   cm != m && cm->lo < cm->hi) {
+                               if ((cm->type == Unchanged ||
+                                    (cm->type == Changed && cm->ignored))
+                                   && cm != m && cm->lo < cm->hi) {
                                        printrange(out, c, cm->c, cm->lo);
                                        break;
                                }
-                               if (cm->type == Changed)
+                               if (cm->type == Changed && !cm->ignored)
                                        st1 = 0; /* All of result of change must be printed */
                                printrange(out, c, cm->c+st1, cm->cl-st1);
                                st1 = 0;
@@ -584,7 +591,7 @@ void print_merge(FILE *out, struct file *a, struct file *b, struct file *c,
                                        if ((cm->type == Unchanged || cm->type == Changed)
                                            && cm != m && cm->lo < cm->hi)
                                                last = 1;
-                                       switch (cm->type) {
+                                       switch (cm->ignored ? Unchanged : cm->type) {
                                        case Unchanged:
                                        case AlreadyApplied:
                                        case Unmatched:
@@ -608,7 +615,8 @@ void print_merge(FILE *out, struct file *a, struct file *b, struct file *c,
                        }
                        fputs(words ? "--->>>" : ">>>>>>>\n", out);
                        m = cm;
-                       if (m->in_conflict && m->type == Unchanged
+                       if (m->in_conflict && (m->type == Unchanged ||
+                                              (m->type == Changed && m->ignored))
                            && m->hi >= m->al) {
                                printrange(out, a, m->a+m->lo, m->hi-m->lo);
                                m++;
@@ -645,10 +653,13 @@ void print_merge(FILE *out, struct file *a, struct file *b, struct file *c,
                case Extraneous:
                        break;
                case Changed:
-                       printrange(out, c, m->c, m->cl);
+                       if (m->ignored)
+                               printrange(out, a, m->a, m->al);
+                       else
+                               printrange(out, c, m->c, m->cl);
                        break;
                case Conflict:
-                       if (m->conflict_ignored) {
+                       if (m->ignored) {
                                printrange(out, a, m->a, m->al);
                                break;
                        }
index 9e56e938de694035b0b533434d2c6e64be9a5a94..9adfa0d2c7ec3eb6c7334c22eef9f387e9cc55e7 100644 (file)
--- a/vpatch.c
+++ b/vpatch.c
@@ -532,6 +532,11 @@ static int visible(int mode, struct merge *m, struct mpos *pos)
                        return a_extra;
                break;
        case Changed: /* stream zero visible ORIG and BEFORE, stream 2 elsewhere */
+               if (m[pos->p.m].ignored) {
+                       if (stream == 0)
+                               return a_common | A_UNDERLINE;
+                       break;
+               }
                if (stream == 0 &&
                    (mode & (ORIG|BEFORE)))
                        return a_delete;
@@ -540,7 +545,7 @@ static int visible(int mode, struct merge *m, struct mpos *pos)
                        return a_added;
                break;
        case Conflict:
-               if (m[pos->p.m].conflict_ignored)
+               if (m[pos->p.m].ignored)
                        ignore = A_REVERSE|A_UNDERLINE;
                else
                        ignore = 0;
@@ -556,7 +561,7 @@ static int visible(int mode, struct merge *m, struct mpos *pos)
                                return a_extra | (A_UNDERLINE & ~ignore);
                        break;
                case 2:
-                       if ((mode & RESULT) && m[pos->p.m].conflict_ignored)
+                       if ((mode & RESULT) && m[pos->p.m].ignored)
                                break;
                        if (mode & (AFTER|RESULT))
                                return a_added | (A_UNDERLINE & ~ignore);
@@ -598,10 +603,10 @@ static int check_line(struct mpos pos, struct file fm, struct file fb,
        int unmatched = 0;
 
        do {
-               if (m[pos.p.m].type == Changed)
+               if (m[pos.p.m].type == Changed && !m[pos.p.m].ignored)
                        rv |= CHANGES;
                else if (m[pos.p.m].type == Conflict) {
-                       if (m[pos.p.m].conflict_ignored &&
+                       if (m[pos.p.m].ignored &&
                            (mode & RESULT))
                                ;
                        else
@@ -1568,7 +1573,7 @@ static int merge_window(struct plist *p, FILE *f, int reverse)
                        char lbuf[30];
                        (void)attrset(A_BOLD);
                        snprintf(lbuf, 29, "%s%s ln:%d",
-                                ci.merger[curs.pos.m].conflict_ignored
+                                ci.merger[curs.pos.m].ignored
                                 ? "Ignored ":"",
                                 typenames[ci.merger[curs.pos.m].type],
                                 (pos.p.lineno-1)/2);
@@ -2024,9 +2029,10 @@ static int merge_window(struct plist *p, FILE *f, int reverse)
                        break;
 
                case 'x': /* Toggle rejecting of conflict */
-                       if (ci.merger[curs.pos.m].type == Conflict) {
-                               ci.merger[curs.pos.m].conflict_ignored =
-                                       ! ci.merger[curs.pos.m].conflict_ignored;
+                       if (ci.merger[curs.pos.m].type == Conflict ||
+                           ci.merger[curs.pos.m].type == Changed) {
+                               ci.merger[curs.pos.m].ignored =
+                                       ! ci.merger[curs.pos.m].ignored;
                                isolate_conflicts(fm, fb, fa, csl1, csl2, 0, ci.merger, 0);
                                refresh = 1;
                                changes = 1;
index 1974523fbbc4ae83105858a9c57088b75d06dab4..40acf2c648231ad1e5d2b1ce325b64f1f78a8762 100644 (file)
--- a/wiggle.h
+++ b/wiggle.h
@@ -117,7 +117,7 @@ struct merge {
        int al, bl, cl; /* length of ranges */
        int c1, c2; /* this or next common-sequence */
        int in_conflict;
-       int conflict_ignored;
+       int ignored;
        int lo, hi; /* region of a Changed or Unchanged that is not involved
                    * in a conflict.
                    * These are distances from start of the "before" section,