Details
Details
- Reviewers
pulkit - Group Reviewers
hg-reviewers - Commits
- rHGb54d93fc3ba8: simplemerge: port to Python 3
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
pulkit |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
By default, LOCAL is overwritten with the results of this operation. | By default, LOCAL is overwritten with the results of this operation. | ||||
''') | ''') | ||||
class ParseError(Exception): | class ParseError(Exception): | ||||
"""Exception raised on errors in parsing the command line.""" | """Exception raised on errors in parsing the command line.""" | ||||
def showhelp(): | def showhelp(): | ||||
sys.stdout.write(usage) | pycompat.stdout.write(usage.encode('utf8')) | ||||
sys.stdout.write(b'\noptions:\n') | pycompat.stdout.write(b'\noptions:\n') | ||||
out_opts = [] | out_opts = [] | ||||
for shortopt, longopt, default, desc in options: | for shortopt, longopt, default, desc in options: | ||||
out_opts.append((b'%2s%s' % (shortopt and b'-%s' % shortopt, | out_opts.append((b'%2s%s' % (shortopt and b'-%s' % shortopt, | ||||
longopt and b' --%s' % longopt), | longopt and b' --%s' % longopt), | ||||
b'%s' % desc)) | b'%s' % desc)) | ||||
opts_len = max([len(opt[0]) for opt in out_opts]) | opts_len = max([len(opt[0]) for opt in out_opts]) | ||||
for first, second in out_opts: | for first, second in out_opts: | ||||
sys.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) | pycompat.stdout.write(b' %-*s %s\n' % (opts_len, first, second)) | ||||
try: | try: | ||||
for fp in (sys.stdin, sys.stdout, sys.stderr): | for fp in (sys.stdin, pycompat.stdout, sys.stderr): | ||||
procutil.setbinary(fp) | procutil.setbinary(fp) | ||||
opts = {} | opts = {} | ||||
try: | try: | ||||
args = fancyopts.fancyopts(sys.argv[1:], options, opts) | bargv = [a.encode('utf8') for a in sys.argv[1:]] | ||||
args = fancyopts.fancyopts(bargv, options, opts) | |||||
except getopt.GetoptError as e: | except getopt.GetoptError as e: | ||||
raise ParseError(e) | raise ParseError(e) | ||||
if opts[b'help']: | if opts[b'help']: | ||||
showhelp() | showhelp() | ||||
sys.exit(0) | sys.exit(0) | ||||
if len(args) != 3: | if len(args) != 3: | ||||
raise ParseError(_(b'wrong number of arguments')) | raise ParseError(_(b'wrong number of arguments').decode('utf8')) | ||||
local, base, other = args | local, base, other = args | ||||
sys.exit(simplemerge.simplemerge(uimod.ui.load(), | sys.exit(simplemerge.simplemerge(uimod.ui.load(), | ||||
context.arbitraryfilectx(local), | context.arbitraryfilectx(local), | ||||
context.arbitraryfilectx(base), | context.arbitraryfilectx(base), | ||||
context.arbitraryfilectx(other), | context.arbitraryfilectx(other), | ||||
**pycompat.strkwargs(opts))) | **pycompat.strkwargs(opts))) | ||||
except ParseError as e: | except ParseError as e: | ||||
sys.stdout.write(b"%s: %s\n" % (sys.argv[0], e)) | if pycompat.ispy3: | ||||
e = str(e).encode('utf8') | |||||
pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e)) | |||||
showhelp() | showhelp() | ||||
sys.exit(1) | sys.exit(1) | ||||
except error.Abort as e: | except error.Abort as e: | ||||
sys.stderr.write(b"abort: %s\n" % e) | pycompat.stderr.write(b"abort: %s\n" % e) | ||||
sys.exit(255) | sys.exit(255) | ||||
except KeyboardInterrupt: | except KeyboardInterrupt: | ||||
sys.exit(255) | sys.exit(255) |