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