contrib/simplemerge
author Denis Laxalde <denis.laxalde@logilab.fr>
Wed, 05 Jul 2017 13:54:53 +0200
changeset 33284 b2670290eab4
parent 30576 541949a10a68
child 33895 aed91971d88c
permissions -rwxr-xr-x
followlines: join merge parents line ranges in blockdescendants() (issue5595) In blockdescendants(), we had an assertion when line range of a merge changeset was not consistent depending on which parent was considered for computation. For instance, this might occur when file content (in lookup range) is significantly different between parent branches of the merge as demonstrated in added tests (where we almost completely rewrite the "baz" file while also introducing similarities with its content in the other branch we later merge to). Now, in such case, we combine line ranges from all parents by storing the envelope of both line ranges. This is conservative (the line range is extended, possibly unnecessarily) but at least this should avoid missing descendants with changes in a range that would fall in that of one parent but not in another one (the case of "baz: narrow change (2->2+)" changeset in tests).

#!/usr/bin/env python

from mercurial import demandimport
demandimport.enable()

import getopt
import sys
from mercurial.i18n import _
from mercurial import error, simplemerge, fancyopts, util, ui

options = [('L', 'label', [], _('labels to use on conflict markers')),
           ('a', 'text', None, _('treat all files as text')),
           ('p', 'print', None,
            _('print results instead of overwriting LOCAL')),
           ('', 'no-minimal', None, _('no effect (DEPRECATED)')),
           ('h', 'help', None, _('display help and exit')),
           ('q', 'quiet', None, _('suppress output'))]

usage = _('''simplemerge [OPTS] LOCAL BASE OTHER

    Simple three-way file merge utility with a minimal feature set.

    Apply to LOCAL the changes necessary to go from BASE to OTHER.

    By default, LOCAL is overwritten with the results of this operation.
''')

class ParseError(Exception):
    """Exception raised on errors in parsing the command line."""

def showhelp():
    sys.stdout.write(usage)
    sys.stdout.write('\noptions:\n')

    out_opts = []
    for shortopt, longopt, default, desc in options:
        out_opts.append(('%2s%s' % (shortopt and '-%s' % shortopt,
                                    longopt and ' --%s' % longopt),
                         '%s' % desc))
    opts_len = max([len(opt[0]) for opt in out_opts])
    for first, second in out_opts:
        sys.stdout.write(' %-*s  %s\n' % (opts_len, first, second))

try:
    for fp in (sys.stdin, sys.stdout, sys.stderr):
        util.setbinary(fp)

    opts = {}
    try:
        args = fancyopts.fancyopts(sys.argv[1:], options, opts)
    except getopt.GetoptError as e:
        raise ParseError(e)
    if opts['help']:
        showhelp()
        sys.exit(0)
    if len(args) != 3:
            raise ParseError(_('wrong number of arguments'))
    sys.exit(simplemerge.simplemerge(ui.ui.load(), *args, **opts))
except ParseError as e:
    sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
    showhelp()
    sys.exit(1)
except error.Abort as e:
    sys.stderr.write("abort: %s\n" % e)
    sys.exit(255)
except KeyboardInterrupt:
    sys.exit(255)