[PATCH 2 of 3] merge: introduce method to minimize merge regions

Martin von Zweigbergk martinvonz at google.com
Wed Feb 10 12:11:01 EST 2016


On Wed, Feb 10, 2016 at 8:24 AM, Ryan McElroy <rm at fb.com> wrote:
> On 2/10/2016 00:40, Ryan McElroy wrote:
>>
>> # 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
>
>
> Whoops, this should be a2 - endmatches
>
> Thanks to Jun Wu for giving me some test cases that uncovered this bug. I'll
> send out a v2 with the fix.

There's no added test case in V2 of this patch. Could you include Jun
Wu's test case?


More information about the Mercurial-devel mailing list