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