simplemerge
64 lines
| 2.0 KiB
| text/plain
|
TextLexer
/ contrib / simplemerge
|
r4363 | #!/usr/bin/env python | ||
|
r4362 | |||
|
r4364 | from mercurial import demandimport | ||
demandimport.enable() | ||||
|
r4362 | |||
|
r6002 | import os, sys | ||
|
r4363 | from mercurial.i18n import _ | ||
|
r6002 | from mercurial import simplemerge, fancyopts, util | ||
|
r4362 | |||
|
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')), | ||||
('', 'no-minimal', None, | ||||
_('do not try to minimize conflict regions')), | ||||
('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. | ||||
|
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. | ||
''') | ||||
|
r6002 | class ParseError(Exception): | ||
"""Exception raised on errors in parsing the command line.""" | ||||
|
r4364 | def showhelp(): | ||
sys.stdout.write(usage) | ||||
sys.stdout.write('\noptions:\n') | ||||
|
r4362 | |||
|
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)) | ||||
|
r6002 | try: | ||
opts = {} | ||||
|
r4364 | try: | ||
|
r6002 | args = fancyopts.fancyopts(sys.argv[1:], options, opts) | ||
except fancyopts.getopt.GetoptError, e: | ||||
raise ParseError(e) | ||||
if opts['help']: | ||||
|
r4364 | showhelp() | ||
|
r6002 | sys.exit(0) | ||
if len(args) != 3: | ||||
raise ParseError(_('wrong number of arguments')) | ||||
sys.exit(simplemerge.simplemerge(*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) | ||||