##// END OF EJS Templates
py3: fix exception display encoding in contrib/simplemerge.py...
Emmanuel Leblond -
r43684:3c2799cb stable
parent child Browse files
Show More
@@ -1,87 +1,87 b''
1 1 #!/usr/bin/env python
2 2 from __future__ import absolute_import
3 3
4 4 import getopt
5 5 import sys
6 6
7 7 import hgdemandimport
8 8 hgdemandimport.enable()
9 9
10 10 from mercurial.i18n import _
11 11 from mercurial import (
12 12 context,
13 13 error,
14 14 fancyopts,
15 15 pycompat,
16 16 simplemerge,
17 17 ui as uimod,
18 18 )
19 19 from mercurial.utils import (
20 20 procutil,
21 stringutil
21 22 )
22 23
23 24 options = [(b'L', b'label', [], _(b'labels to use on conflict markers')),
24 25 (b'a', b'text', None, _(b'treat all files as text')),
25 26 (b'p', b'print', None,
26 27 _(b'print results instead of overwriting LOCAL')),
27 28 (b'', b'no-minimal', None, _(b'no effect (DEPRECATED)')),
28 29 (b'h', b'help', None, _(b'display help and exit')),
29 30 (b'q', b'quiet', None, _(b'suppress output'))]
30 31
31 32 usage = _(b'''simplemerge [OPTS] LOCAL BASE OTHER
32 33
33 34 Simple three-way file merge utility with a minimal feature set.
34 35
35 36 Apply to LOCAL the changes necessary to go from BASE to OTHER.
36 37
37 38 By default, LOCAL is overwritten with the results of this operation.
38 39 ''')
39 40
40 41 class ParseError(Exception):
41 42 """Exception raised on errors in parsing the command line."""
42 43
43 44 def showhelp():
44 45 pycompat.stdout.write(usage)
45 46 pycompat.stdout.write(b'\noptions:\n')
46 47
47 48 out_opts = []
48 49 for shortopt, longopt, default, desc in options:
49 50 out_opts.append((b'%2s%s' % (shortopt and b'-%s' % shortopt,
50 51 longopt and b' --%s' % longopt),
51 52 b'%s' % desc))
52 53 opts_len = max([len(opt[0]) for opt in out_opts])
53 54 for first, second in out_opts:
54 55 pycompat.stdout.write(b' %-*s %s\n' % (opts_len, first, second))
55 56
56 57 try:
57 58 for fp in (sys.stdin, pycompat.stdout, sys.stderr):
58 59 procutil.setbinary(fp)
59 60
60 61 opts = {}
61 62 try:
62 63 bargv = [a.encode('utf8') for a in sys.argv[1:]]
63 64 args = fancyopts.fancyopts(bargv, options, opts)
64 65 except getopt.GetoptError as e:
65 66 raise ParseError(e)
66 67 if opts[b'help']:
67 68 showhelp()
68 69 sys.exit(0)
69 70 if len(args) != 3:
70 71 raise ParseError(_(b'wrong number of arguments').decode('utf8'))
71 72 local, base, other = args
72 73 sys.exit(simplemerge.simplemerge(uimod.ui.load(),
73 74 context.arbitraryfilectx(local),
74 75 context.arbitraryfilectx(base),
75 76 context.arbitraryfilectx(other),
76 77 **pycompat.strkwargs(opts)))
77 78 except ParseError as e:
78 if pycompat.ispy3:
79 e = str(e).encode('utf8')
79 e = stringutil.forcebytestr(e)
80 80 pycompat.stdout.write(b"%s: %s\n" % (sys.argv[0].encode('utf8'), e))
81 81 showhelp()
82 82 sys.exit(1)
83 83 except error.Abort as e:
84 84 pycompat.stderr.write(b"abort: %s\n" % e)
85 85 sys.exit(255)
86 86 except KeyboardInterrupt:
87 87 sys.exit(255)
General Comments 0
You need to be logged in to leave comments. Login now