[PATCH 2 of 3] merge: introduce method to minimize merge regions
Ryan McElroy
rm at fb.com
Wed Feb 10 11:24:15 EST 2016
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.
> +
> def find_sync_regions(self):
> """Return a list of sync regions, where both descendants match the base.
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.mercurial-2Dscm.org_mailman_listinfo_mercurial-2Ddevel&d=CwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=Jw8rundaE7TbmqBYd1txIQ&m=TsUaPFbqTz-o5qLlFuiq4dESVihm3t-zFsm2on_u9z4&s=PyChbb2AR3TOGSjT2ldzmpzpZslO5rfW-q-9x75vaYo&e=
More information about the Mercurial-devel
mailing list