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