[PATCH 2 of 3] merge: introduce method to minimize merge regions
Ryan McElroy
rm at fb.com
Wed Feb 10 00:40:08 UTC 2016
# HG changeset patch
# User Ryan McElroy <rmcelroy at fb.com>
# Date 1455063667 28800
# Tue Feb 09 16:21:07 2016 -0800
# Node ID 51558e81358f58eb82c8a09d5cc3663e12619f7c
# Parent d520165147534eabfd95d66df6f176809a4c5b03
merge: introduce method to minimize merge regions
In the next diff, we will use this to trim down the start and end of conflict
regions where the A and B sides both made the same changes.
diff --git a/mercurial/simplemerge.py b/mercurial/simplemerge.py
--- a/mercurial/simplemerge.py
+++ b/mercurial/simplemerge.py
@@ -269,6 +269,45 @@ class Merge3Text(object):
ia = aend
ib = bend
+ def minimize(self, merge_regions):
+ """Trim conflict regions of lines where A and B sides match.
+
+ Lines where both A and B have made the same changes at the begining
+ or the end of each merge region are eliminated from the conflict
+ region and are instead considered the same.
+ """
+ for region in merge_regions:
+ if region[0] != "conflict":
+ yield region
+ continue
+ issue, z1, z2, a1, a2, b1, b2 = region
+ alen = a2 - a1
+ blen = b2 - b1
+
+ # find matches at the front
+ ii = 0
+ while ii < alen and ii < blen and \
+ self.a[a1 + ii] == self.b[b1 + ii]:
+ ii += 1
+ startmatches = ii
+
+ # find matches at the end
+ ii = 0
+ while ii < alen and ii < blen and \
+ self.a[a2 - ii - 1] == self.b[b2 - ii - 1]:
+ ii += 1
+ endmatches = ii
+
+ if startmatches > 0:
+ yield 'same', a1, a1 + startmatches
+
+ yield ('conflict', z1, z2,
+ a1 + startmatches, a2 - endmatches,
+ b1 + startmatches, b2 - endmatches)
+
+ if endmatches > 0:
+ yield 'same', a2 - startmatches, a2
+
def find_sync_regions(self):
"""Return a list of sync regions, where both descendants match the base.
More information about the Mercurial-devel
mailing list