simplemerge
102 lines
| 2.7 KiB
| text/plain
|
TextLexer
/ contrib / simplemerge
|
r4363 | #!/usr/bin/env python | ||
|
r33896 | from __future__ import absolute_import | ||
|
r4362 | |||
|
r30576 | import getopt | ||
|
r19378 | import sys | ||
|
r33896 | |||
import hgdemandimport | ||||
|
r44058 | |||
|
r33896 | hgdemandimport.enable() | ||
|
r4363 | from mercurial.i18n import _ | ||
|
r33896 | from mercurial import ( | ||
|
r34053 | context, | ||
|
r33896 | error, | ||
fancyopts, | ||||
|
r39827 | pycompat, | ||
|
r33896 | simplemerge, | ||
ui as uimod, | ||||
|
r37138 | ) | ||
|
r44058 | from mercurial.utils import procutil, stringutil | ||
|
r4362 | |||
|
r44058 | 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')), | ||||
] | ||||
|
r4364 | |||
|
r44058 | usage = _( | ||
b'''simplemerge [OPTS] LOCAL BASE OTHER | ||||
|
r4364 | |||
Simple three-way file merge utility with a minimal feature set. | ||||
|
r5081 | |||
|
r4364 | Apply to LOCAL the changes necessary to go from BASE to OTHER. | ||
|
r5081 | |||
|
r4364 | By default, LOCAL is overwritten with the results of this operation. | ||
|
r44058 | ''' | ||
) | ||||
|
r4364 | |||
|
r6002 | class ParseError(Exception): | ||
"""Exception raised on errors in parsing the command line.""" | ||||
|
r44058 | |||
|
r4364 | def showhelp(): | ||
|
r45598 | procutil.stdout.write(usage) | ||
procutil.stdout.write(b'\noptions:\n') | ||||
|
r4362 | |||
|
r4364 | out_opts = [] | ||
for shortopt, longopt, default, desc in options: | ||||
|
r44058 | out_opts.append( | ||
( | ||||
b'%2s%s' | ||||
% ( | ||||
shortopt and b'-%s' % shortopt, | ||||
longopt and b' --%s' % longopt, | ||||
), | ||||
b'%s' % desc, | ||||
) | ||||
) | ||||
|
r4364 | opts_len = max([len(opt[0]) for opt in out_opts]) | ||
for first, second in out_opts: | ||||
|
r45598 | procutil.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) | ||
|
r4364 | |||
|
r44058 | |||
|
r6002 | try: | ||
|
r45598 | for fp in (sys.stdin, procutil.stdout, sys.stderr): | ||
|
r37138 | procutil.setbinary(fp) | ||
|
r19022 | |||
|
r6002 | opts = {} | ||
|
r4364 | try: | ||
|
r40296 | bargv = [a.encode('utf8') for a in sys.argv[1:]] | ||
args = fancyopts.fancyopts(bargv, options, opts) | ||||
|
r30576 | except getopt.GetoptError as e: | ||
|
r6002 | raise ParseError(e) | ||
|
r39826 | if opts[b'help']: | ||
|
r4364 | showhelp() | ||
|
r6002 | sys.exit(0) | ||
if len(args) != 3: | ||||
|
r44058 | raise ParseError(_(b'wrong number of arguments').decode('utf8')) | ||
|
r33904 | local, base, other = args | ||
|
r44058 | sys.exit( | ||
simplemerge.simplemerge( | ||||
uimod.ui.load(), | ||||
context.arbitraryfilectx(local), | ||||
context.arbitraryfilectx(base), | ||||
context.arbitraryfilectx(other), | ||||
**pycompat.strkwargs(opts) | ||||
) | ||||
) | ||||
|
r28047 | except ParseError as e: | ||
|
r43684 | e = stringutil.forcebytestr(e) | ||
|
r45598 | procutil.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e)) | ||
|
r6002 | showhelp() | ||
sys.exit(1) | ||||
|
r28047 | except error.Abort as e: | ||
|
r45598 | procutil.stderr.write(b"abort: %s\n" % e) | ||
|
r6002 | sys.exit(255) | ||
except KeyboardInterrupt: | ||||
sys.exit(255) | ||||