contrib/simplemerge
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 22 Apr 2015 23:38:52 +0900
branchstable
changeset 24833 cb981009d697
parent 22023 f18830651811
child 26587 56b2bcea2529
permissions -rwxr-xr-x
dirstate: use pathutil.normasprefix to ensure os.sep at the end of root 3cc630be5f09 replaced "os.path.join(root, '')" by "root.endswith(os.sep)" examination, because Python 2.7.9 changes behavior of "os.path.join(path, '')" on UNC path. But some problematic encodings use 0x5c (= "os.sep" on Windows) as the tail byte of some multi-byte characters, and replacement above prevents Mercurial from working on the repository, of which root path ends with such multi-byte character, regardless of enabling win32mbcs. This patch uses "pathutil.normasprefix()" instead of "root.endswith(os.sep)" examination, to ensure "os.sep" at the end of "dirstate._rootdir" even with problematic encodings. "root" of dirstate can be passed to "pathutil.normasprefix()" without normalization, because it is always given from "repo.root" = "repo.wvfs.base", which is normalized by "os.path.realpath()". Using "util.endswithsep()" instead of "str.endswith(os.sep)" also fixes this problem, but this patch chooses "pathutil.normasprefix()" to centralize "adding os.sep if endswith(os.sep)" logic into it.

#!/usr/bin/env python

from mercurial import demandimport
demandimport.enable()

import sys
from mercurial.i18n import _
from mercurial import 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 fancyopts.getopt.GetoptError, 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(), *args, **opts))
except ParseError, e:
    sys.stdout.write("%s: %s\n" % (sys.argv[0], e))
    showhelp()
    sys.exit(1)
except util.Abort, e:
    sys.stderr.write("abort: %s\n" % e)
    sys.exit(255)
except KeyboardInterrupt:
    sys.exit(255)