Mercurial > hg-stable
changeset 28071:261324dd5f5b
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.
author | Ryan McElroy <rmcelroy@fb.com> |
---|---|
date | Wed, 10 Feb 2016 08:25:03 -0800 |
parents | a504794cee29 |
children | c3e9269d9602 |
files | mercurial/simplemerge.py |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/simplemerge.py Tue Feb 09 15:25:09 2016 -0800 +++ b/mercurial/simplemerge.py Wed Feb 10 08:25:03 2016 -0800 @@ -269,6 +269,45 @@ 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 - endmatches, a2 + def find_sync_regions(self): """Return a list of sync regions, where both descendants match the base.