Mercurial > hg
annotate mercurial/filemerge.py @ 23088:fe5f044b753d stable
changelog: use headrevsfiltered
2b5940f64750 introduced use of the new filtering headrevs C implementation. It
caught TypeError to detect when to fall back to the implementation that was
compatible with old extensions. That method was however not reliable.
Instead, use the new headrevsfiltered function when passing a filter. It will
reliably fail with AttributeError when an old extension that predates
headrevsfiltered is used.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Sun, 26 Oct 2014 12:14:12 +0100 |
parents | 38e0363dcbe0 |
children | b405dd6c90bf |
rev | line source |
---|---|
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
1 # filemerge.py - file-level merge handling for Mercurial |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
2 # |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
3 # Copyright 2006, 2007, 2008 Matt Mackall <mpm@selenic.com> |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
4 # |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8209
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
10263 | 6 # GNU General Public License version 2 or any later version. |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
7 |
7873
4a4c7f6a5912
cleanup: drop unused imports
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
7397
diff
changeset
|
8 from node import short |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
9 from i18n import _ |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
10 import util, simplemerge, match, error, templater, templatekw |
8312
b87a50b7125c
separate import lines from mercurial and general python modules
Simon Heimberg <simohe@besonet.ch>
parents:
8269
diff
changeset
|
11 import os, tempfile, re, filecmp |
21922
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
12 import tagmerge |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
13 |
6013
bb441d77df99
filemerge: handle missing regappend
Matt Mackall <mpm@selenic.com>
parents:
6007
diff
changeset
|
14 def _toolstr(ui, tool, part, default=""): |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
15 return ui.config("merge-tools", tool + "." + part, default) |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
16 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
17 def _toolbool(ui, tool, part, default=False): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
18 return ui.configbool("merge-tools", tool + "." + part, default) |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
19 |
11148
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
20 def _toollist(ui, tool, part, default=[]): |
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
21 return ui.configlist("merge-tools", tool + "." + part, default) |
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
22 |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
23 internals = {} |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
24 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
25 def internaltool(name, trymerge, onfailure=None): |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
26 '''return a decorator for populating internal merge tool table''' |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
27 def decorator(func): |
22707
38e0363dcbe0
filemerge: switch the default name for internal tools from internal:x to :x
Mads Kiilerich <madski@unity3d.com>
parents:
22706
diff
changeset
|
28 fullname = ':' + name |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
29 func.__doc__ = "``%s``\n" % fullname + func.__doc__.strip() |
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
30 internals[fullname] = func |
22707
38e0363dcbe0
filemerge: switch the default name for internal tools from internal:x to :x
Mads Kiilerich <madski@unity3d.com>
parents:
22706
diff
changeset
|
31 internals['internal:' + name] = func |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
32 func.trymerge = trymerge |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
33 func.onfailure = onfailure |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
34 return func |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
35 return decorator |
8830
a9850eda2973
filemerge: add internal:prompt target
Matt Mackall <mpm@selenic.com>
parents:
8615
diff
changeset
|
36 |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
37 def _findtool(ui, tool): |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
38 if tool in internals: |
6522
2b181fb3a70a
use internal merge tool when specified for a merge-pattern in hgrc
Dov Feldstern <dfeldstern@fastimap.com>
parents:
6212
diff
changeset
|
39 return tool |
13565
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
40 for kn in ("regkey", "regkeyalt"): |
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
41 k = _toolstr(ui, tool, kn) |
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
42 if not k: |
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
43 continue |
14230
d51630301241
rename util.lookup_reg to lookupreg
Adrian Buehlmann <adrian@cadifra.com>
parents:
14168
diff
changeset
|
44 p = util.lookupreg(k, _toolstr(ui, tool, "regname")) |
6006
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
6005
diff
changeset
|
45 if p: |
14271
4030630fb59c
rename util.find_exe to findexe
Adrian Buehlmann <adrian@cadifra.com>
parents:
14230
diff
changeset
|
46 p = util.findexe(p + _toolstr(ui, tool, "regappend")) |
6006
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
6005
diff
changeset
|
47 if p: |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
6005
diff
changeset
|
48 return p |
15264
157d93c41c10
merge: expand environment variables and ~/ in tool.executable
Greg Ward <greg@gerg.ca>
parents:
14749
diff
changeset
|
49 exe = _toolstr(ui, tool, "executable", tool) |
157d93c41c10
merge: expand environment variables and ~/ in tool.executable
Greg Ward <greg@gerg.ca>
parents:
14749
diff
changeset
|
50 return util.findexe(util.expandpath(exe)) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
51 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
52 def _picktool(repo, ui, path, binary, symlink): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
53 def check(tool, pat, symlink, binary): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
54 tmsg = tool |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
55 if pat: |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
56 tmsg += " specified for " + pat |
7397
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
57 if not _findtool(ui, tool): |
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
58 if pat: # explicitly requested tool deserves a warning |
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
59 ui.warn(_("couldn't find merge tool %s\n") % tmsg) |
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
60 else: # configured but non-existing tools are more silent |
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
61 ui.note(_("couldn't find merge tool %s\n") % tmsg) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
62 elif symlink and not _toolbool(ui, tool, "symlink"): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
63 ui.warn(_("tool %s can't handle symlinks\n") % tmsg) |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
64 elif binary and not _toolbool(ui, tool, "binary"): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
65 ui.warn(_("tool %s can't handle binary\n") % tmsg) |
6007
090b1a665901
filemerge: add config item for GUI tools
Matt Mackall <mpm@selenic.com>
parents:
6006
diff
changeset
|
66 elif not util.gui() and _toolbool(ui, tool, "gui"): |
090b1a665901
filemerge: add config item for GUI tools
Matt Mackall <mpm@selenic.com>
parents:
6006
diff
changeset
|
67 ui.warn(_("tool %s requires a GUI\n") % tmsg) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
68 else: |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
69 return True |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
70 return False |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
71 |
12788
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
72 # forcemerge comes from command line arguments, highest priority |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
73 force = ui.config('ui', 'forcemerge') |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
74 if force: |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
75 toolpath = _findtool(ui, force) |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
76 if toolpath: |
17885
9a2cf955db84
filemerge: use util.shellquote when calling merge (issue3581)
Keegan Carruthers-Smith <keegancsmith@fb.com>
parents:
16256
diff
changeset
|
77 return (force, util.shellquote(toolpath)) |
12788
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
78 else: |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
79 # mimic HGMERGE if given tool not found |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
80 return (force, force) |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
81 |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
82 # HGMERGE takes next precedence |
6025
f2335246e5c7
filemerge: wrap quotes around tool path
Steve Borho <steve@borho.org>
parents:
6016
diff
changeset
|
83 hgmerge = os.environ.get("HGMERGE") |
f2335246e5c7
filemerge: wrap quotes around tool path
Steve Borho <steve@borho.org>
parents:
6016
diff
changeset
|
84 if hgmerge: |
f2335246e5c7
filemerge: wrap quotes around tool path
Steve Borho <steve@borho.org>
parents:
6016
diff
changeset
|
85 return (hgmerge, hgmerge) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
86 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
87 # then patterns |
6016
288ec2f6faa2
filemerge: fix pattern matching
dhruva <dhruvakm@gmail.com>
parents:
6015
diff
changeset
|
88 for pat, tool in ui.configitems("merge-patterns"): |
8567
fea40a677d43
match: add some default args
Matt Mackall <mpm@selenic.com>
parents:
8566
diff
changeset
|
89 mf = match.match(repo.root, '', [pat]) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
90 if mf(path) and check(tool, pat, symlink, False): |
10339
23e608f42f2c
fix spaces/identation issues
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
91 toolpath = _findtool(ui, tool) |
17885
9a2cf955db84
filemerge: use util.shellquote when calling merge (issue3581)
Keegan Carruthers-Smith <keegancsmith@fb.com>
parents:
16256
diff
changeset
|
92 return (tool, util.shellquote(toolpath)) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
93 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
94 # then merge tools |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
95 tools = {} |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
96 for k, v in ui.configitems("merge-tools"): |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
97 t = k.split('.')[0] |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
98 if t not in tools: |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
99 tools[t] = int(_toolstr(ui, t, "priority", "0")) |
6076
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
100 names = tools.keys() |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
101 tools = sorted([(-p, t) for t, p in tools.items()]) |
6076
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
102 uimerge = ui.config("ui", "merge") |
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
103 if uimerge: |
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
104 if uimerge not in names: |
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
105 return (uimerge, uimerge) |
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
106 tools.insert(0, (None, uimerge)) # highest priority |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
107 tools.append((None, "hgmerge")) # the old default, if found |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
108 for p, t in tools: |
7397
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
109 if check(t, None, symlink, binary): |
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
110 toolpath = _findtool(ui, t) |
17885
9a2cf955db84
filemerge: use util.shellquote when calling merge (issue3581)
Keegan Carruthers-Smith <keegancsmith@fb.com>
parents:
16256
diff
changeset
|
111 return (t, util.shellquote(toolpath)) |
16254
c7eef052c9e3
filemerge: restore default prompt for binary/symlink lost in 83925d3a4559
Matt Mackall <mpm@selenic.com>
parents:
16205
diff
changeset
|
112 |
c7eef052c9e3
filemerge: restore default prompt for binary/symlink lost in 83925d3a4559
Matt Mackall <mpm@selenic.com>
parents:
16205
diff
changeset
|
113 # internal merge or prompt as last resort |
c7eef052c9e3
filemerge: restore default prompt for binary/symlink lost in 83925d3a4559
Matt Mackall <mpm@selenic.com>
parents:
16205
diff
changeset
|
114 if symlink or binary: |
22707
38e0363dcbe0
filemerge: switch the default name for internal tools from internal:x to :x
Mads Kiilerich <madski@unity3d.com>
parents:
22706
diff
changeset
|
115 return ":prompt", None |
38e0363dcbe0
filemerge: switch the default name for internal tools from internal:x to :x
Mads Kiilerich <madski@unity3d.com>
parents:
22706
diff
changeset
|
116 return ":merge", None |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
117 |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
118 def _eoltype(data): |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
119 "Guess the EOL type of a file" |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
120 if '\0' in data: # binary |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
121 return None |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
122 if '\r\n' in data: # Windows |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
123 return '\r\n' |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
124 if '\r' in data: # Old Mac |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
125 return '\r' |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
126 if '\n' in data: # UNIX |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
127 return '\n' |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
128 return None # unknown |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
129 |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
130 def _matcheol(file, origfile): |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
131 "Convert EOL markers in a file to match origfile" |
14168
135e244776f0
prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13565
diff
changeset
|
132 tostyle = _eoltype(util.readfile(origfile)) |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
133 if tostyle: |
14168
135e244776f0
prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13565
diff
changeset
|
134 data = util.readfile(file) |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
135 style = _eoltype(data) |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
136 if style: |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
137 newdata = data.replace(style, tostyle) |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
138 if newdata != data: |
14168
135e244776f0
prevent transient leaks of file handle by using new helper functions
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
13565
diff
changeset
|
139 util.writefile(file, newdata) |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
140 |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
141 @internaltool('prompt', False) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
142 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
143 """Asks the user which of the local or the other version to keep as |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
144 the merged version.""" |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
145 ui = repo.ui |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
146 fd = fcd.path() |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
147 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
148 if ui.promptchoice(_(" no tool found to merge %s\n" |
19226
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
18325
diff
changeset
|
149 "keep (l)ocal or take (o)ther?" |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
18325
diff
changeset
|
150 "$$ &Local $$ &Other") % fd, 0): |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
151 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
152 else: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
153 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
154 |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
155 @internaltool('local', False) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
156 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
157 """Uses the local version of files as the merged version.""" |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
158 return 0 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
159 |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
160 @internaltool('other', False) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
161 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
162 """Uses the other version of files as the merged version.""" |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
163 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
164 return 0 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
165 |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
166 @internaltool('fail', False) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
167 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
168 """ |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
169 Rather than attempting to merge files that were modified on both |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
170 branches, it marks them as unresolved. The resolve command must be |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
171 used to resolve these conflicts.""" |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
172 return 1 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
173 |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
174 def _premerge(repo, toolconf, files, labels=None): |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
175 tool, toolpath, binary, symlink = toolconf |
18257
a35d0128545e
merge: never do premerge on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
18256
diff
changeset
|
176 if symlink: |
a35d0128545e
merge: never do premerge on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
18256
diff
changeset
|
177 return 1 |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
178 a, b, c, back = files |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
179 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
180 ui = repo.ui |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
181 |
22032
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
182 validkeep = ['keep', 'keep-merge3'] |
22031
b36c60cfe46f
merge-tools: make premerge valid values extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22028
diff
changeset
|
183 |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
184 # do we attempt to simplemerge first? |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
185 try: |
18257
a35d0128545e
merge: never do premerge on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
18256
diff
changeset
|
186 premerge = _toolbool(ui, tool, "premerge", not binary) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
187 except error.ConfigError: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
188 premerge = _toolstr(ui, tool, "premerge").lower() |
22031
b36c60cfe46f
merge-tools: make premerge valid values extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22028
diff
changeset
|
189 if premerge not in validkeep: |
b36c60cfe46f
merge-tools: make premerge valid values extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22028
diff
changeset
|
190 _valid = ', '.join(["'" + v + "'" for v in validkeep]) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
191 raise error.ConfigError(_("%s.premerge not valid " |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
192 "('%s' is neither boolean nor %s)") % |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
193 (tool, premerge, _valid)) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
194 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
195 if premerge: |
22032
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
196 if premerge == 'keep-merge3': |
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
197 if not labels: |
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
198 labels = _defaultconflictlabels |
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
199 if len(labels) < 3: |
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
200 labels.append('base') |
22023
f18830651811
simplemerge: burn "minimal" feature to the ground
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22022
diff
changeset
|
201 r = simplemerge.simplemerge(ui, a, b, c, quiet=True, label=labels) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
202 if not r: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
203 ui.debug(" premerge successful\n") |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
204 return 0 |
22031
b36c60cfe46f
merge-tools: make premerge valid values extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22028
diff
changeset
|
205 if premerge not in validkeep: |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
206 util.copyfile(back, a) # restore from backup and try again |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
207 return 1 # continue merging |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
208 |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
209 @internaltool('merge', True, |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
210 _("merging %s incomplete! " |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
211 "(edit conflicts, then use 'hg resolve --mark')\n")) |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
212 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
213 """ |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
214 Uses the internal non-interactive simple merge algorithm for merging |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
215 files. It will fail if there are any conflicts and leave markers in |
22027
b98e5c7afc70
internal:merge: update documentation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22026
diff
changeset
|
216 the partially merged file. Markers will have two sections, one for each side |
b98e5c7afc70
internal:merge: update documentation
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22026
diff
changeset
|
217 of merge.""" |
18256
d084df89d948
merge: make internal merge fail cleanly on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
17885
diff
changeset
|
218 tool, toolpath, binary, symlink = toolconf |
d084df89d948
merge: make internal merge fail cleanly on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
17885
diff
changeset
|
219 if symlink: |
22707
38e0363dcbe0
filemerge: switch the default name for internal tools from internal:x to :x
Mads Kiilerich <madski@unity3d.com>
parents:
22706
diff
changeset
|
220 repo.ui.warn(_('warning: internal :merge cannot merge symlinks ' |
18325
297bf69966a0
merge: warn when internal:merge cannot merge symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
18257
diff
changeset
|
221 'for %s\n') % fcd.path()) |
18256
d084df89d948
merge: make internal merge fail cleanly on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
17885
diff
changeset
|
222 return False, 1 |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
223 r = _premerge(repo, toolconf, files, labels=labels) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
224 if r: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
225 a, b, c, back = files |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
226 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
227 ui = repo.ui |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
228 |
22023
f18830651811
simplemerge: burn "minimal" feature to the ground
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22022
diff
changeset
|
229 r = simplemerge.simplemerge(ui, a, b, c, label=labels) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
230 return True, r |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
231 return False, 0 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
232 |
22028
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
233 @internaltool('merge3', True, |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
234 _("merging %s incomplete! " |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
235 "(edit conflicts, then use 'hg resolve --mark')\n")) |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
236 def _imerge3(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
237 """ |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
238 Uses the internal non-interactive simple merge algorithm for merging |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
239 files. It will fail if there are any conflicts and leave markers in |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
240 the partially merged file. Marker will have three sections, one from each |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
241 side of the merge and one for the base content.""" |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
242 if not labels: |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
243 labels = _defaultconflictlabels |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
244 if len(labels) < 3: |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
245 labels.append('base') |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
246 return _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels) |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
247 |
21922
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
248 @internaltool('tagmerge', True, |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
249 _("automatic tag merging of %s failed! " |
22707
38e0363dcbe0
filemerge: switch the default name for internal tools from internal:x to :x
Mads Kiilerich <madski@unity3d.com>
parents:
22706
diff
changeset
|
250 "(use 'hg resolve --tool :merge' or another merge " |
21922
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
251 "tool of your choice)\n")) |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
252 def _itagmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
253 """ |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
254 Uses the internal tag merge algorithm (experimental). |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
255 """ |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
256 return tagmerge.merge(repo, fcd, fco, fca) |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
257 |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
258 @internaltool('dump', True) |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
259 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
260 """ |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
261 Creates three versions of the files to merge, containing the |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
262 contents of local, other and base. These files can then be used to |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
263 perform a merge manually. If the file to be merged is named |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
264 ``a.txt``, these files will accordingly be named ``a.txt.local``, |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
265 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
266 same directory as ``a.txt``.""" |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
267 r = _premerge(repo, toolconf, files, labels=labels) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
268 if r: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
269 a, b, c, back = files |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
270 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
271 fd = fcd.path() |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
272 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
273 util.copyfile(a, a + ".local") |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
274 repo.wwrite(fd + ".other", fco.data(), fco.flags()) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
275 repo.wwrite(fd + ".base", fca.data(), fca.flags()) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
276 return False, r |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
277 |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
278 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
279 r = _premerge(repo, toolconf, files, labels=labels) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
280 if r: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
281 tool, toolpath, binary, symlink = toolconf |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
282 a, b, c, back = files |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
283 out = "" |
20676
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
284 env = {'HG_FILE': fcd.path(), |
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
285 'HG_MY_NODE': short(mynode), |
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
286 'HG_OTHER_NODE': str(fco.changectx()), |
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
287 'HG_BASE_NODE': str(fca.changectx()), |
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
288 'HG_MY_ISLINK': 'l' in fcd.flags(), |
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
289 'HG_OTHER_ISLINK': 'l' in fco.flags(), |
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
290 'HG_BASE_ISLINK': 'l' in fca.flags(), |
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
291 } |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
292 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
293 ui = repo.ui |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
294 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
295 args = _toolstr(ui, tool, "args", '$local $base $other') |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
296 if "$output" in args: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
297 out, a = a, back # read input from backup, write to original |
20676
89b2336e5ccf
filemerge: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
19226
diff
changeset
|
298 replace = {'local': a, 'base': b, 'other': c, 'output': out} |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
299 args = util.interpolate(r'\$', replace, args, |
17885
9a2cf955db84
filemerge: use util.shellquote when calling merge (issue3581)
Keegan Carruthers-Smith <keegancsmith@fb.com>
parents:
16256
diff
changeset
|
300 lambda s: util.shellquote(util.localpath(s))) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
301 r = util.system(toolpath + ' ' + args, cwd=repo.root, environ=env, |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
302 out=ui.fout) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
303 return True, r |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
304 return False, 0 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
305 |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
306 def _formatconflictmarker(repo, ctx, template, label, pad): |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
307 """Applies the given template to the ctx, prefixed by the label. |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
308 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
309 Pad is the minimum width of the label prefix, so that multiple markers |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
310 can have aligned templated parts. |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
311 """ |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
312 if ctx.node() is None: |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
313 ctx = ctx.p1() |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
314 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
315 props = templatekw.keywords.copy() |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
316 props['templ'] = template |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
317 props['ctx'] = ctx |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
318 props['repo'] = repo |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
319 templateresult = template('conflictmarker', **props) |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
320 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
321 label = ('%s:' % label).ljust(pad + 1) |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
322 mark = '%s %s' % (label, templater.stringify(templateresult)) |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
323 |
21864
755bf1bbe0a9
filemerge: use only the first line of the generated conflict marker for safety
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21693
diff
changeset
|
324 if mark: |
755bf1bbe0a9
filemerge: use only the first line of the generated conflict marker for safety
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21693
diff
changeset
|
325 mark = mark.splitlines()[0] # split for safety |
755bf1bbe0a9
filemerge: use only the first line of the generated conflict marker for safety
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21693
diff
changeset
|
326 |
21865
78e56e70c70a
filemerge: use 'util.ellipsis' to trim custom conflict markers correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21864
diff
changeset
|
327 # 8 for the prefix of conflict marker lines (e.g. '<<<<<<< ') |
78e56e70c70a
filemerge: use 'util.ellipsis' to trim custom conflict markers correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21864
diff
changeset
|
328 return util.ellipsis(mark, 80 - 8) |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
329 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
330 _defaultconflictmarker = ('{node|short} ' + |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
331 '{ifeq(tags, "tip", "", "{tags} ")}' + |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
332 '{if(bookmarks, "{bookmarks} ")}' + |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
333 '{ifeq(branch, "default", "", "{branch} ")}' + |
21693
9c35f3a8cac4
merge: drop the quotes around commit description
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21524
diff
changeset
|
334 '- {author|user}: {desc|firstline}') |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
335 |
21524
47b97d9af27e
merge: add labels parameter from merge.update to filemerge
Durham Goode <durham@fb.com>
parents:
21519
diff
changeset
|
336 _defaultconflictlabels = ['local', 'other'] |
47b97d9af27e
merge: add labels parameter from merge.update to filemerge
Durham Goode <durham@fb.com>
parents:
21519
diff
changeset
|
337 |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
338 def _formatlabels(repo, fcd, fco, fca, labels): |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
339 """Formats the given labels using the conflict marker template. |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
340 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
341 Returns a list of formatted labels. |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
342 """ |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
343 cd = fcd.changectx() |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
344 co = fco.changectx() |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
345 ca = fca.changectx() |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
346 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
347 ui = repo.ui |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
348 template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker) |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
349 template = templater.parsestring(template, quoted=False) |
22025
5f22975d320d
filemerge: drop extra white space
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22023
diff
changeset
|
350 tmpl = templater.templater(None, cache={'conflictmarker': template}) |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
351 |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
352 pad = max(len(l) for l in labels) |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
353 |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
354 newlabels = [_formatconflictmarker(repo, cd, tmpl, labels[0], pad), |
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
355 _formatconflictmarker(repo, co, tmpl, labels[1], pad)] |
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
356 if len(labels) > 2: |
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
357 newlabels.append(_formatconflictmarker(repo, ca, tmpl, labels[2], pad)) |
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
358 return newlabels |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
359 |
21524
47b97d9af27e
merge: add labels parameter from merge.update to filemerge
Durham Goode <durham@fb.com>
parents:
21519
diff
changeset
|
360 def filemerge(repo, mynode, orig, fcd, fco, fca, labels=None): |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
361 """perform a 3-way merge in the working directory |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
362 |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
363 mynode = parent node before merge |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
364 orig = original local filename before merge |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
365 fco = other file context |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
366 fca = ancestor file context |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
367 fcd = local file context for current/destination file |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
368 """ |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
369 |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
370 def temp(prefix, ctx): |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
371 pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
372 (fd, name) = tempfile.mkstemp(prefix=pre) |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
373 data = repo.wwritedata(ctx.path(), ctx.data()) |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
374 f = os.fdopen(fd, "wb") |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
375 f.write(data) |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
376 f.close() |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
377 return name |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
378 |
11702
eb07fbc21e9c
filectx: use cmp(self, fctx) instead of cmp(self, text)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11149
diff
changeset
|
379 if not fco.cmp(fcd): # files identical? |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
380 return None |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
381 |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
382 ui = repo.ui |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
383 fd = fcd.path() |
15738
e86dd8dfdea0
context: add isbinary function
Laurens Holst <laurens.hg@grauw.nl>
parents:
15501
diff
changeset
|
384 binary = fcd.isbinary() or fco.isbinary() or fca.isbinary() |
6744
d3691d31fc9c
context: remove islink and isexec methods
Matt Mackall <mpm@selenic.com>
parents:
6743
diff
changeset
|
385 symlink = 'l' in fcd.flags() + fco.flags() |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
386 tool, toolpath = _picktool(repo, ui, fd, binary, symlink) |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9049
diff
changeset
|
387 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" % |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
388 (tool, fd, binary, symlink)) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
389 |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
390 if tool in internals: |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
391 func = internals[tool] |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
392 trymerge = func.trymerge |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
393 onfailure = func.onfailure |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
394 else: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
395 func = _xmerge |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
396 trymerge = True |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
397 onfailure = _("merging %s failed!\n") |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
398 |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
399 toolconf = tool, toolpath, binary, symlink |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
400 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
401 if not trymerge: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
402 return func(repo, mynode, orig, fcd, fco, fca, toolconf) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
403 |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
404 a = repo.wjoin(fd) |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
405 b = temp("base", fca) |
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
406 c = temp("other", fco) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
407 back = a + ".orig" |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
408 util.copyfile(a, back) |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
409 |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
410 if orig != fco.path(): |
8615
94ca38e63576
use ui instead of repo.ui when the former is in scope
Martin Geisler <mg@lazybytes.net>
parents:
8567
diff
changeset
|
411 ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd)) |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
412 else: |
8615
94ca38e63576
use ui instead of repo.ui when the former is in scope
Martin Geisler <mg@lazybytes.net>
parents:
8567
diff
changeset
|
413 ui.status(_("merging %s\n") % fd) |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
414 |
9467
4c041f1ee1b4
do not attempt to translate ui.debug output
Martin Geisler <mg@lazybytes.net>
parents:
9049
diff
changeset
|
415 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
416 |
21918
10abc3a5c6b2
filemerge: use 'basic' as the default of '[ui] mergemarkers' for safety
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21865
diff
changeset
|
417 markerstyle = ui.config('ui', 'mergemarkers', 'basic') |
22021
e9801c7b6ff0
merge: refactor labels selection code
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21922
diff
changeset
|
418 if not labels: |
e9801c7b6ff0
merge: refactor labels selection code
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21922
diff
changeset
|
419 labels = _defaultconflictlabels |
e9801c7b6ff0
merge: refactor labels selection code
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21922
diff
changeset
|
420 if markerstyle != 'basic': |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
421 labels = _formatlabels(repo, fcd, fco, fca, labels) |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
422 |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
423 needcheck, r = func(repo, mynode, orig, fcd, fco, fca, toolconf, |
22021
e9801c7b6ff0
merge: refactor labels selection code
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21922
diff
changeset
|
424 (a, b, c, back), labels=labels) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
425 if not needcheck: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
426 if r: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
427 if onfailure: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
428 ui.warn(onfailure % fd) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
429 else: |
21100
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
430 util.unlink(back) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
431 |
21100
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
432 util.unlink(b) |
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
433 util.unlink(c) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
434 return r |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
435 |
11148
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
436 if not r and (_toolbool(ui, tool, "checkconflicts") or |
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
437 'conflicts' in _toollist(ui, tool, "check")): |
12046
8e7960feb139
Fix merge-tools.checkconflicts
Thomas Arendsen Hein <thomas@intevation.de>
parents:
12008
diff
changeset
|
438 if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(), |
8e7960feb139
Fix merge-tools.checkconflicts
Thomas Arendsen Hein <thomas@intevation.de>
parents:
12008
diff
changeset
|
439 re.MULTILINE): |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
440 r = 1 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
441 |
11149
d3c1eddfdbcf
merge: tool.check = prompt will force an interactive merge check
David Champion <dgc@uchicago.edu>
parents:
11148
diff
changeset
|
442 checked = False |
d3c1eddfdbcf
merge: tool.check = prompt will force an interactive merge check
David Champion <dgc@uchicago.edu>
parents:
11148
diff
changeset
|
443 if 'prompt' in _toollist(ui, tool, "check"): |
d3c1eddfdbcf
merge: tool.check = prompt will force an interactive merge check
David Champion <dgc@uchicago.edu>
parents:
11148
diff
changeset
|
444 checked = True |
19226
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
18325
diff
changeset
|
445 if ui.promptchoice(_("was merge of '%s' successful (yn)?" |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
18325
diff
changeset
|
446 "$$ &Yes $$ &No") % fd, 1): |
11149
d3c1eddfdbcf
merge: tool.check = prompt will force an interactive merge check
David Champion <dgc@uchicago.edu>
parents:
11148
diff
changeset
|
447 r = 1 |
d3c1eddfdbcf
merge: tool.check = prompt will force an interactive merge check
David Champion <dgc@uchicago.edu>
parents:
11148
diff
changeset
|
448 |
d3c1eddfdbcf
merge: tool.check = prompt will force an interactive merge check
David Champion <dgc@uchicago.edu>
parents:
11148
diff
changeset
|
449 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or |
d3c1eddfdbcf
merge: tool.check = prompt will force an interactive merge check
David Champion <dgc@uchicago.edu>
parents:
11148
diff
changeset
|
450 'changed' in _toollist(ui, tool, "check")): |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
451 if filecmp.cmp(a, back): |
9048
86b4a9b0ddda
ui: extract choice from prompt
Simon Heimberg <simohe@besonet.ch>
parents:
8861
diff
changeset
|
452 if ui.promptchoice(_(" output file %s appears unchanged\n" |
19226
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
18325
diff
changeset
|
453 "was merge successful (yn)?" |
c58b6ab4c26f
ui: merge prompt text components into a singe string
Matt Mackall <mpm@selenic.com>
parents:
18325
diff
changeset
|
454 "$$ &Yes $$ &No") % fd, 1): |
6075
63e0e57ab157
filemerge: add 'checkchanged' merge tool property
Steve Borho <steve@borho.org>
parents:
6025
diff
changeset
|
455 r = 1 |
63e0e57ab157
filemerge: add 'checkchanged' merge tool property
Steve Borho <steve@borho.org>
parents:
6025
diff
changeset
|
456 |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
457 if _toolbool(ui, tool, "fixeol"): |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
458 _matcheol(a, back) |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
459 |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
460 if r: |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
461 if onfailure: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
462 ui.warn(onfailure % fd) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
463 else: |
21100
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
464 util.unlink(back) |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
465 |
21100
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
466 util.unlink(b) |
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
467 util.unlink(c) |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
468 return r |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
469 |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
470 # tell hggettext to extract docstrings from these functions: |
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
471 i18nfunctions = internals.values() |