simplemerge
87 lines
| 2.7 KiB
| text/plain
|
TextLexer
/ contrib / simplemerge
Alexis S. L. Carvalho
|
r4363 | #!/usr/bin/env python | ||
Augie Fackler
|
r33896 | from __future__ import absolute_import | ||
Alexis S. L. Carvalho
|
r4362 | |||
Pulkit Goyal
|
r30576 | import getopt | ||
Simon Heimberg
|
r19378 | import sys | ||
Augie Fackler
|
r33896 | |||
import hgdemandimport | ||||
hgdemandimport.enable() | ||||
Alexis S. L. Carvalho
|
r4363 | from mercurial.i18n import _ | ||
Augie Fackler
|
r33896 | from mercurial import ( | ||
Phil Cohen
|
r34053 | context, | ||
Augie Fackler
|
r33896 | error, | ||
fancyopts, | ||||
Pulkit Goyal
|
r39827 | pycompat, | ||
Augie Fackler
|
r33896 | simplemerge, | ||
ui as uimod, | ||||
Yuya Nishihara
|
r37138 | ) | ||
from mercurial.utils import ( | ||||
procutil, | ||||
Augie Fackler
|
r33896 | ) | ||
Alexis S. L. Carvalho
|
r4362 | |||
Pulkit Goyal
|
r39826 | options = [(b'L', b'label', [], _(b'labels to use on conflict markers')), | ||
(b'a', b'text', None, _(b'treat all files as text')), | ||||
(b'p', b'print', None, | ||||
_(b'print results instead of overwriting LOCAL')), | ||||
(b'', b'no-minimal', None, _(b'no effect (DEPRECATED)')), | ||||
(b'h', b'help', None, _(b'display help and exit')), | ||||
(b'q', b'quiet', None, _(b'suppress output'))] | ||||
Alexis S. L. Carvalho
|
r4364 | |||
Yuya Nishihara
|
r40301 | usage = _(b'''simplemerge [OPTS] LOCAL BASE OTHER | ||
Alexis S. L. Carvalho
|
r4364 | |||
Simple three-way file merge utility with a minimal feature set. | ||||
Thomas Arendsen Hein
|
r5081 | |||
Alexis S. L. Carvalho
|
r4364 | Apply to LOCAL the changes necessary to go from BASE to OTHER. | ||
Thomas Arendsen Hein
|
r5081 | |||
Alexis S. L. Carvalho
|
r4364 | By default, LOCAL is overwritten with the results of this operation. | ||
''') | ||||
Matt Mackall
|
r6002 | class ParseError(Exception): | ||
"""Exception raised on errors in parsing the command line.""" | ||||
Alexis S. L. Carvalho
|
r4364 | def showhelp(): | ||
Yuya Nishihara
|
r40301 | pycompat.stdout.write(usage) | ||
Augie Fackler
|
r40296 | pycompat.stdout.write(b'\noptions:\n') | ||
Alexis S. L. Carvalho
|
r4362 | |||
Alexis S. L. Carvalho
|
r4364 | out_opts = [] | ||
for shortopt, longopt, default, desc in options: | ||||
Pulkit Goyal
|
r39826 | out_opts.append((b'%2s%s' % (shortopt and b'-%s' % shortopt, | ||
longopt and b' --%s' % longopt), | ||||
b'%s' % desc)) | ||||
Alexis S. L. Carvalho
|
r4364 | opts_len = max([len(opt[0]) for opt in out_opts]) | ||
for first, second in out_opts: | ||||
Augie Fackler
|
r40296 | pycompat.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) | ||
Alexis S. L. Carvalho
|
r4364 | |||
Matt Mackall
|
r6002 | try: | ||
Augie Fackler
|
r40296 | for fp in (sys.stdin, pycompat.stdout, sys.stderr): | ||
Yuya Nishihara
|
r37138 | procutil.setbinary(fp) | ||
Mads Kiilerich
|
r19022 | |||
Matt Mackall
|
r6002 | opts = {} | ||
Alexis S. L. Carvalho
|
r4364 | try: | ||
Augie Fackler
|
r40296 | bargv = [a.encode('utf8') for a in sys.argv[1:]] | ||
args = fancyopts.fancyopts(bargv, options, opts) | ||||
Pulkit Goyal
|
r30576 | except getopt.GetoptError as e: | ||
Matt Mackall
|
r6002 | raise ParseError(e) | ||
Pulkit Goyal
|
r39826 | if opts[b'help']: | ||
Alexis S. L. Carvalho
|
r4364 | showhelp() | ||
Matt Mackall
|
r6002 | sys.exit(0) | ||
if len(args) != 3: | ||||
Augie Fackler
|
r40296 | raise ParseError(_(b'wrong number of arguments').decode('utf8')) | ||
Phil Cohen
|
r33904 | local, base, other = args | ||
sys.exit(simplemerge.simplemerge(uimod.ui.load(), | ||||
Phil Cohen
|
r34053 | context.arbitraryfilectx(local), | ||
context.arbitraryfilectx(base), | ||||
context.arbitraryfilectx(other), | ||||
Pulkit Goyal
|
r39827 | **pycompat.strkwargs(opts))) | ||
FUJIWARA Katsunori
|
r28047 | except ParseError as e: | ||
Augie Fackler
|
r40296 | if pycompat.ispy3: | ||
e = str(e).encode('utf8') | ||||
pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e)) | ||||
Matt Mackall
|
r6002 | showhelp() | ||
sys.exit(1) | ||||
FUJIWARA Katsunori
|
r28047 | except error.Abort as e: | ||
Augie Fackler
|
r40296 | pycompat.stderr.write(b"abort: %s\n" % e) | ||
Matt Mackall
|
r6002 | sys.exit(255) | ||
except KeyboardInterrupt: | ||||
sys.exit(255) | ||||