simplemerge
81 lines
| 2.4 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, | ||||
simplemerge, | ||||
ui as uimod, | ||||
util, | ||||
) | ||||
Alexis S. L. Carvalho
|
r4362 | |||
Alexis S. L. Carvalho
|
r4364 | 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')), | ||||
Pierre-Yves David
|
r22023 | ('', 'no-minimal', None, _('no effect (DEPRECATED)')), | ||
Alexis S. L. Carvalho
|
r4364 | ('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. | ||||
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(): | ||
sys.stdout.write(usage) | ||||
sys.stdout.write('\noptions:\n') | ||||
Alexis S. L. Carvalho
|
r4362 | |||
Alexis S. L. Carvalho
|
r4364 | 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)) | ||||
Matt Mackall
|
r6002 | try: | ||
Patrick Mezard
|
r7080 | for fp in (sys.stdin, sys.stdout, sys.stderr): | ||
Adrian Buehlmann
|
r14233 | util.setbinary(fp) | ||
Mads Kiilerich
|
r19022 | |||
Matt Mackall
|
r6002 | opts = {} | ||
Alexis S. L. Carvalho
|
r4364 | try: | ||
Matt Mackall
|
r6002 | args = fancyopts.fancyopts(sys.argv[1:], options, opts) | ||
Pulkit Goyal
|
r30576 | except getopt.GetoptError as e: | ||
Matt Mackall
|
r6002 | raise ParseError(e) | ||
if opts['help']: | ||||
Alexis S. L. Carvalho
|
r4364 | showhelp() | ||
Matt Mackall
|
r6002 | sys.exit(0) | ||
if len(args) != 3: | ||||
raise ParseError(_('wrong number of arguments')) | ||||
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), | ||||
Phil Cohen
|
r33904 | **opts)) | ||
FUJIWARA Katsunori
|
r28047 | except ParseError as e: | ||
Matt Mackall
|
r6002 | sys.stdout.write("%s: %s\n" % (sys.argv[0], e)) | ||
showhelp() | ||||
sys.exit(1) | ||||
FUJIWARA Katsunori
|
r28047 | except error.Abort as e: | ||
Matt Mackall
|
r6002 | sys.stderr.write("abort: %s\n" % e) | ||
sys.exit(255) | ||||
except KeyboardInterrupt: | ||||
sys.exit(255) | ||||