}
int isolate_conflicts(struct file af, struct file bf, struct file cf,
- struct csl *csl1, struct csl *csl2, int words,
- struct merge *m, int show_wiggles)
+ struct csl *csl1, struct csl *csl2, int words,
+ struct merge *m, int show_wiggles,
+ int *wigglesp)
{
/* A Conflict indicates that something is definitely wrong
* and so we need to be a bit suspicious of nearby apparent matches.
* as including a hunk header.
* If there are 3, and they are all in 'Unchanged' sections, then
* that much context is not really needed - reduce it a bit.
+ *
+ * If a wiggle is adjacent to a conflict then:
+ * - if show_wiggles is set, we just merge them
+ * - if it is not set, we still want to count the wiggle.
*/
int i, j, k;
- int cnt = 0;
+ int cnt = 0, wiggles = 0;
+ int in_wiggle = 0;
int changed = 0;
int unmatched = 0;
int extraneous = 0;
* extraneous text does.
*/
extraneous = 3;
+
+ if (m[i].type != Unchanged && changed && (unmatched || extraneous)) {
+ if (!in_wiggle)
+ wiggles++;
+ in_wiggle = 1;
+ } else
+ in_wiggle = 0;
+
if ((m[i].type == Conflict && m[i].ignored == 0) ||
(show_wiggles && m[i].type != Unchanged && changed && (unmatched || extraneous))) {
/* We have a conflict (or wiggle) here.
*/
int newlines = 0;
m[i].in_conflict = m[i].type == Conflict ? 2 : 3;
- if (m[i].in_conflict == 2)
- cnt++;
j = i;
while (--j >= 0) {
int firstk;
if (m[j].type != Unchanged &&
m[j].type != Changed) {
- m[j].in_conflict = m[i].in_conflict;
+ if (m[j].type == Conflict)
+ m[j].in_conflict = 2;
+ else
+ m[j].in_conflict = m[i].in_conflict;
continue;
}
/* If we find enough newlines in this section,
}
if (m[j].type != Unchanged &&
m[j].type != Changed) {
- m[j].in_conflict = m[i].in_conflict;
+ if (m[j].type == Conflict)
+ m[j].in_conflict = 2;
+ else
+ m[j].in_conflict = m[i].in_conflict;
continue;
}
m[j].hi = m[j].al;
extraneous--;
}
}
+ if (!show_wiggles)
+ *wigglesp = wiggles;
+ /* Now count the conflicts and wiggles */
+ for (i = 0; m[i].type != End; i++) {
+ int true_conflict = 0;
+ if (!m[i].in_conflict)
+ continue;
+
+ for (j = i; m[j].type != End && m[j].in_conflict; j++) {
+ if (m[j].in_conflict == 2)
+ true_conflict = 1;
+ if (j > i &&
+ m[j].in_conflict == 1) {
+ /* end of region */
+ if (!m[j+1].in_conflict)
+ j++;
+ break;
+ }
+ }
+ if (true_conflict)
+ cnt++;
+ else
+ wiggles++;
+ i = j-1;
+ }
+ if (show_wiggles)
+ *wigglesp = wiggles;
return cnt;
}
struct ci rv;
int i, l;
int a, b, c, c1, c2;
- int wiggle_found = 0;
rv.conflicts = rv.wiggles = rv.ignored = 0;
rv.merger[i].al = newa - a;
rv.merger[i].bl = 0;
rv.merger[i].cl = 0;
- wiggle_found++;
} else {
int newb;
int j;
newb = b + 1;
for (j = b; j < newb; j++) {
if (bf.list[j].start[0] == '\0') {
- if (wiggle_found > 1)
- rv.wiggles++;
- wiggle_found = 0;
if (j > b)
newb = j;
- } else
- wiggle_found++;
+ }
}
rv.merger[i].cl =
rv.merger[i].bl = newb - b;
rv.merger[i].type = Conflict;
}
rv.conflicts = isolate_conflicts(af, bf, cf, csl1, csl2, words,
- rv.merger, show_wiggles);
- if (wiggle_found)
- rv.wiggles++;
+ rv.merger, show_wiggles, &rv.wiggles);
return rv;
}
p->wiggles = 0;
p->conflicts = isolate_conflicts(
fm, fb, fa, csl1, csl2, 0,
- ci.merger, 0);
+ ci.merger, 0, &p->wiggles);
p->chunks = p->conflicts;
save_merge(fm, fb, fa, ci.merger,
p->file, !p->is_merge);
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);
+ p->conflicts = isolate_conflicts(
+ fm, fb, fa, csl1, csl2, 0,
+ ci.merger, 0, &p->wiggles);
refresh = 1;
changes = 1;
}
e = prev_melmnt(&tpos.p, fm, fb, fa, ci.merger);
} while (!ends_line(e) ||
visible(mode & (RESULT|AFTER), ci.merger, &tpos) < 0);
- isolate_conflicts(fm, fb, fa, csl1, csl2, 0, ci.merger, 0);
+ p->conflicts = isolate_conflicts(
+ fm, fb, fa, csl1, csl2, 0,
+ ci.merger, 0, &p->wiggles);
refresh = 1;
changes = 1;
break;
extern int isolate_conflicts(struct file af, struct file bf, struct file cf,
struct csl *csl1, struct csl *csl2, int words,
- struct merge *m, int show_wiggles);
+ struct merge *m, int show_wiggles, int *wigglesp);
extern struct ci make_merger(struct file a, struct file b, struct file c,
struct csl *c1, struct csl *c2, int words,
int ignore_already, int show_wiggles);