Mercurial > hg
annotate mercurial/filemerge.py @ 30186:f7ed5af31242
mergecopies: rename 'ca' to 'base'
This variable was named after the common ancestor. It is actually the merge
base that might differ from the common ancestor in the graft case. We rename the
variable before a larger refactoring to clarify the situation. Similar rename
was also applied to 'checkcopies' in a prior changeset.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Thu, 13 Oct 2016 01:30:14 +0200 |
parents | aa23c93e636d |
children | 8819b63732b9 |
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 |
25949
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
8 from __future__ import absolute_import |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
9 |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
10 import filecmp |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
11 import os |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
12 import re |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
13 import tempfile |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
14 |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
15 from .i18n import _ |
26979
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
16 from .node import nullid, short |
25949
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
17 |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
18 from . import ( |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
19 error, |
28955
78759f78a44e
templater: factor out function that creates templater from string template
Yuya Nishihara <yuya@tcha.org>
parents:
28954
diff
changeset
|
20 formatter, |
25949
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
21 match, |
30073
aa23c93e636d
py3: make format strings unicodes and not bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29775
diff
changeset
|
22 pycompat, |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27599
diff
changeset
|
23 scmutil, |
25949
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
24 simplemerge, |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
25 tagmerge, |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
26 templatekw, |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
27 templater, |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
28 util, |
80aba76e29c1
filemerge: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25835
diff
changeset
|
29 ) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
30 |
6013
bb441d77df99
filemerge: handle missing regappend
Matt Mackall <mpm@selenic.com>
parents:
6007
diff
changeset
|
31 def _toolstr(ui, tool, part, default=""): |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
32 return ui.config("merge-tools", tool + "." + part, default) |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
33 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
34 def _toolbool(ui, tool, part, default=False): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
35 return ui.configbool("merge-tools", tool + "." + part, default) |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
36 |
11148
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
37 def _toollist(ui, tool, part, default=[]): |
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
38 return ui.configlist("merge-tools", tool + "." + part, default) |
a912f26777d3
merge: introduce tool.check parameter
David Champion <dgc@uchicago.edu>
parents:
11146
diff
changeset
|
39 |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
40 internals = {} |
24099
be83fd9d46d5
help.merge-tools: do not double document merge tools
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23270
diff
changeset
|
41 # Merge tools to document. |
be83fd9d46d5
help.merge-tools: do not double document merge tools
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23270
diff
changeset
|
42 internalsdoc = {} |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
43 |
26525
abc2327e382a
filemerge: add some merge types
Siddharth Agarwal <sid0@fb.com>
parents:
26519
diff
changeset
|
44 # internal tool merge types |
abc2327e382a
filemerge: add some merge types
Siddharth Agarwal <sid0@fb.com>
parents:
26519
diff
changeset
|
45 nomerge = None |
abc2327e382a
filemerge: add some merge types
Siddharth Agarwal <sid0@fb.com>
parents:
26519
diff
changeset
|
46 mergeonly = 'mergeonly' # just the full merge, no premerge |
abc2327e382a
filemerge: add some merge types
Siddharth Agarwal <sid0@fb.com>
parents:
26519
diff
changeset
|
47 fullmerge = 'fullmerge' # both premerge and merge |
abc2327e382a
filemerge: add some merge types
Siddharth Agarwal <sid0@fb.com>
parents:
26519
diff
changeset
|
48 |
26979
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
49 class absentfilectx(object): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
50 """Represents a file that's ostensibly in a context but is actually not |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
51 present in it. |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
52 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
53 This is here because it's very specific to the filemerge code for now -- |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
54 other code is likely going to break with the values this returns.""" |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
55 def __init__(self, ctx, f): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
56 self._ctx = ctx |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
57 self._f = f |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
58 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
59 def path(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
60 return self._f |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
61 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
62 def size(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
63 return None |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
64 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
65 def data(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
66 return None |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
67 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
68 def filenode(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
69 return nullid |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
70 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
71 _customcmp = True |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
72 def cmp(self, fctx): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
73 """compare with other file context |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
74 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
75 returns True if different from fctx. |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
76 """ |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
77 return not (fctx.isabsent() and |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
78 fctx.ctx() == self.ctx() and |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
79 fctx.path() == self.path()) |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
80 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
81 def flags(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
82 return '' |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
83 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
84 def changectx(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
85 return self._ctx |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
86 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
87 def isbinary(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
88 return False |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
89 |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
90 def isabsent(self): |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
91 return True |
7b038ec6c5fd
filemerge: introduce class whose objects represent files not in a context
Siddharth Agarwal <sid0@fb.com>
parents:
26967
diff
changeset
|
92 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
93 def internaltool(name, mergetype, onfailure=None, precheck=None): |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
94 '''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
|
95 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
|
96 fullname = ':' + name |
30073
aa23c93e636d
py3: make format strings unicodes and not bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29775
diff
changeset
|
97 func.__doc__ = (pycompat.sysstr("``%s``\n" % fullname) |
aa23c93e636d
py3: make format strings unicodes and not bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29775
diff
changeset
|
98 + func.__doc__.strip()) |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
99 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
|
100 internals['internal:' + name] = func |
24099
be83fd9d46d5
help.merge-tools: do not double document merge tools
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23270
diff
changeset
|
101 internalsdoc[fullname] = func |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
102 func.mergetype = mergetype |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
103 func.onfailure = onfailure |
26513
01224c28e0ed
filemerge: add a before-merge callback to internal merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
26512
diff
changeset
|
104 func.precheck = precheck |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
105 return func |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
106 return decorator |
8830
a9850eda2973
filemerge: add internal:prompt target
Matt Mackall <mpm@selenic.com>
parents:
8615
diff
changeset
|
107 |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
108 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
|
109 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
|
110 return tool |
23148
b405dd6c90bf
filemerge: split the logic for finding an external tool to its own function
Matt Harbison <matt_harbison@yahoo.com>
parents:
22707
diff
changeset
|
111 return findexternaltool(ui, tool) |
b405dd6c90bf
filemerge: split the logic for finding an external tool to its own function
Matt Harbison <matt_harbison@yahoo.com>
parents:
22707
diff
changeset
|
112 |
b405dd6c90bf
filemerge: split the logic for finding an external tool to its own function
Matt Harbison <matt_harbison@yahoo.com>
parents:
22707
diff
changeset
|
113 def findexternaltool(ui, tool): |
13565
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
114 for kn in ("regkey", "regkeyalt"): |
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
115 k = _toolstr(ui, tool, kn) |
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
116 if not k: |
984175605311
filemerge: introduce a 'regkeyalt' merge tool variable
Steve Borho <steve@borho.org>
parents:
12788
diff
changeset
|
117 continue |
14230
d51630301241
rename util.lookup_reg to lookupreg
Adrian Buehlmann <adrian@cadifra.com>
parents:
14168
diff
changeset
|
118 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
|
119 if p: |
14271
4030630fb59c
rename util.find_exe to findexe
Adrian Buehlmann <adrian@cadifra.com>
parents:
14230
diff
changeset
|
120 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
|
121 if p: |
3c9dbb743d20
merge: add registry look up bits to tool search
Matt Mackall <mpm@selenic.com>
parents:
6005
diff
changeset
|
122 return p |
15264
157d93c41c10
merge: expand environment variables and ~/ in tool.executable
Greg Ward <greg@gerg.ca>
parents:
14749
diff
changeset
|
123 exe = _toolstr(ui, tool, "executable", tool) |
157d93c41c10
merge: expand environment variables and ~/ in tool.executable
Greg Ward <greg@gerg.ca>
parents:
14749
diff
changeset
|
124 return util.findexe(util.expandpath(exe)) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
125 |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
126 def _picktool(repo, ui, path, binary, symlink, changedelete): |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
127 def supportscd(tool): |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
128 return tool in internals and internals[tool].mergetype == nomerge |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
129 |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
130 def check(tool, pat, symlink, binary, changedelete): |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
131 tmsg = tool |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
132 if pat: |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
133 tmsg += " specified for " + pat |
7397
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
134 if not _findtool(ui, tool): |
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
135 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
|
136 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
|
137 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
|
138 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
|
139 elif symlink and not _toolbool(ui, tool, "symlink"): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
140 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
|
141 elif binary and not _toolbool(ui, tool, "binary"): |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
142 ui.warn(_("tool %s can't handle binary\n") % tmsg) |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
143 elif changedelete and not supportscd(tool): |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
144 # the nomerge tools are the only tools that support change/delete |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
145 # conflicts |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
146 pass |
6007
090b1a665901
filemerge: add config item for GUI tools
Matt Mackall <mpm@selenic.com>
parents:
6006
diff
changeset
|
147 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
|
148 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
|
149 else: |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
150 return True |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
151 return False |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
152 |
25835
34ffe4c29782
filemerge: mark internal-only config option
Matt Mackall <mpm@selenic.com>
parents:
24987
diff
changeset
|
153 # internal config: ui.forcemerge |
12788
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
154 # 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
|
155 force = ui.config('ui', 'forcemerge') |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
156 if force: |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
157 toolpath = _findtool(ui, force) |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
158 if changedelete and not supportscd(toolpath): |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
159 return ":prompt", None |
12788
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
160 else: |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
161 if toolpath: |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
162 return (force, util.shellquote(toolpath)) |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
163 else: |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
164 # mimic HGMERGE if given tool not found |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
165 return (force, force) |
12788
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
166 |
de793925862e
merge: implement --tool arguments using new ui.forcemerge configurable
Steve Borho <steve@borho.org>
parents:
12047
diff
changeset
|
167 # HGMERGE takes next precedence |
6025
f2335246e5c7
filemerge: wrap quotes around tool path
Steve Borho <steve@borho.org>
parents:
6016
diff
changeset
|
168 hgmerge = os.environ.get("HGMERGE") |
f2335246e5c7
filemerge: wrap quotes around tool path
Steve Borho <steve@borho.org>
parents:
6016
diff
changeset
|
169 if hgmerge: |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
170 if changedelete and not supportscd(hgmerge): |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
171 return ":prompt", None |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
172 else: |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
173 return (hgmerge, hgmerge) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
174 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
175 # then patterns |
6016
288ec2f6faa2
filemerge: fix pattern matching
dhruva <dhruvakm@gmail.com>
parents:
6015
diff
changeset
|
176 for pat, tool in ui.configitems("merge-patterns"): |
8567
fea40a677d43
match: add some default args
Matt Mackall <mpm@selenic.com>
parents:
8566
diff
changeset
|
177 mf = match.match(repo.root, '', [pat]) |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
178 if mf(path) and check(tool, pat, symlink, False, changedelete): |
10339
23e608f42f2c
fix spaces/identation issues
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
10282
diff
changeset
|
179 toolpath = _findtool(ui, tool) |
17885
9a2cf955db84
filemerge: use util.shellquote when calling merge (issue3581)
Keegan Carruthers-Smith <keegancsmith@fb.com>
parents:
16256
diff
changeset
|
180 return (tool, util.shellquote(toolpath)) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
181 |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
182 # then merge tools |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
183 tools = {} |
26730
a1e43e85d294
merge-tools: allow marking a mergetool as completely disabled
Augie Fackler <augie@google.com>
parents:
26614
diff
changeset
|
184 disabled = set() |
10282
08a0f04b56bd
many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents:
10263
diff
changeset
|
185 for k, v in ui.configitems("merge-tools"): |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
186 t = k.split('.')[0] |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
187 if t not in tools: |
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
188 tools[t] = int(_toolstr(ui, t, "priority", "0")) |
26730
a1e43e85d294
merge-tools: allow marking a mergetool as completely disabled
Augie Fackler <augie@google.com>
parents:
26614
diff
changeset
|
189 if _toolbool(ui, t, "disabled", False): |
a1e43e85d294
merge-tools: allow marking a mergetool as completely disabled
Augie Fackler <augie@google.com>
parents:
26614
diff
changeset
|
190 disabled.add(t) |
6076
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
191 names = tools.keys() |
26730
a1e43e85d294
merge-tools: allow marking a mergetool as completely disabled
Augie Fackler <augie@google.com>
parents:
26614
diff
changeset
|
192 tools = sorted([(-p, t) for t, p in tools.items() if t not in disabled]) |
6076
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
193 uimerge = ui.config("ui", "merge") |
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
194 if uimerge: |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
195 # external tools defined in uimerge won't be able to handle |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
196 # change/delete conflicts |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
197 if uimerge not in names and not changedelete: |
6076
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
198 return (uimerge, uimerge) |
0ee885fea464
filemerge: more backwards compatible behavior for ui.merge
Steve Borho <steve@borho.org>
parents:
6075
diff
changeset
|
199 tools.insert(0, (None, uimerge)) # highest priority |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
200 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
|
201 for p, t in tools: |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
202 if check(t, None, symlink, binary, changedelete): |
7397
4c92d8971809
More verbose logging when filemerge searches for merge-tool
Mads Kiilerich <mads@kiilerich.com>
parents:
6762
diff
changeset
|
203 toolpath = _findtool(ui, t) |
17885
9a2cf955db84
filemerge: use util.shellquote when calling merge (issue3581)
Keegan Carruthers-Smith <keegancsmith@fb.com>
parents:
16256
diff
changeset
|
204 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
|
205 |
c7eef052c9e3
filemerge: restore default prompt for binary/symlink lost in 83925d3a4559
Matt Mackall <mpm@selenic.com>
parents:
16205
diff
changeset
|
206 # internal merge or prompt as last resort |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
207 if symlink or binary or changedelete: |
22707
38e0363dcbe0
filemerge: switch the default name for internal tools from internal:x to :x
Mads Kiilerich <madski@unity3d.com>
parents:
22706
diff
changeset
|
208 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
|
209 return ":merge", None |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
210 |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
211 def _eoltype(data): |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
212 "Guess the EOL type of a file" |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
213 if '\0' in data: # binary |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
214 return None |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
215 if '\r\n' in data: # Windows |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
216 return '\r\n' |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
217 if '\r' in data: # Old Mac |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
218 return '\r' |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
219 if '\n' in data: # UNIX |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
220 return '\n' |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
221 return None # unknown |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
222 |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
223 def _matcheol(file, origfile): |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
224 "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
|
225 tostyle = _eoltype(util.readfile(origfile)) |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
226 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
|
227 data = util.readfile(file) |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
228 style = _eoltype(data) |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
229 if style: |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
230 newdata = data.replace(style, tostyle) |
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
231 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
|
232 util.writefile(file, newdata) |
6005
3c33032d8906
merge: add support for tool EOL fixups
Matt Mackall <mpm@selenic.com>
parents:
6004
diff
changeset
|
233 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
234 @internaltool('prompt', nomerge) |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
235 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): |
28640
4fc640fd0026
filemerge: use revset notation for p1/p2 of local/other descriptions
timeless <timeless@mozdev.org>
parents:
28578
diff
changeset
|
236 """Asks the user which of the local `p1()` or the other `p2()` version to |
4fc640fd0026
filemerge: use revset notation for p1/p2 of local/other descriptions
timeless <timeless@mozdev.org>
parents:
28578
diff
changeset
|
237 keep as the merged version.""" |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
238 ui = repo.ui |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
239 fd = fcd.path() |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
240 |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
241 prompts = partextras(labels) |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
242 prompts['fd'] = fd |
26898
33eb8a56d0c9
filemerge: treat EOF at prompt as fail, not abort
Siddharth Agarwal <sid0@fb.com>
parents:
26893
diff
changeset
|
243 try: |
27038
58a4eb16e722
filemerge: add support for change/delete conflicts to the ':prompt' tool
Siddharth Agarwal <sid0@fb.com>
parents:
27037
diff
changeset
|
244 if fco.isabsent(): |
58a4eb16e722
filemerge: add support for change/delete conflicts to the ':prompt' tool
Siddharth Agarwal <sid0@fb.com>
parents:
27037
diff
changeset
|
245 index = ui.promptchoice( |
29775
978b907d9b36
merge: always use other, not remote, in user prompts
Simon Farnsworth <simonfar@fb.com>
parents:
29774
diff
changeset
|
246 _("local%(l)s changed %(fd)s which other%(o)s deleted\n" |
27163
27b89a0957ec
filemerge: add a 'leave unresolved' option to change/delete prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27162
diff
changeset
|
247 "use (c)hanged version, (d)elete, or leave (u)nresolved?" |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
248 "$$ &Changed $$ &Delete $$ &Unresolved") % prompts, 2) |
27163
27b89a0957ec
filemerge: add a 'leave unresolved' option to change/delete prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27162
diff
changeset
|
249 choice = ['local', 'other', 'unresolved'][index] |
27038
58a4eb16e722
filemerge: add support for change/delete conflicts to the ':prompt' tool
Siddharth Agarwal <sid0@fb.com>
parents:
27037
diff
changeset
|
250 elif fcd.isabsent(): |
58a4eb16e722
filemerge: add support for change/delete conflicts to the ':prompt' tool
Siddharth Agarwal <sid0@fb.com>
parents:
27037
diff
changeset
|
251 index = ui.promptchoice( |
29775
978b907d9b36
merge: always use other, not remote, in user prompts
Simon Farnsworth <simonfar@fb.com>
parents:
29774
diff
changeset
|
252 _("other%(o)s changed %(fd)s which local%(l)s deleted\n" |
27163
27b89a0957ec
filemerge: add a 'leave unresolved' option to change/delete prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27162
diff
changeset
|
253 "use (c)hanged version, leave (d)eleted, or " |
27b89a0957ec
filemerge: add a 'leave unresolved' option to change/delete prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27162
diff
changeset
|
254 "leave (u)nresolved?" |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
255 "$$ &Changed $$ &Deleted $$ &Unresolved") % prompts, 2) |
27163
27b89a0957ec
filemerge: add a 'leave unresolved' option to change/delete prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27162
diff
changeset
|
256 choice = ['other', 'local', 'unresolved'][index] |
27038
58a4eb16e722
filemerge: add support for change/delete conflicts to the ':prompt' tool
Siddharth Agarwal <sid0@fb.com>
parents:
27037
diff
changeset
|
257 else: |
27162
4ab69be0ea15
filemerge: add a 'leave unresolved' option to regular prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27161
diff
changeset
|
258 index = ui.promptchoice( |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
259 _("no tool found to merge %(fd)s\n" |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
260 "keep (l)ocal%(l)s, take (o)ther%(o)s, or leave (u)nresolved?" |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
261 "$$ &Local $$ &Other $$ &Unresolved") % prompts, 2) |
27162
4ab69be0ea15
filemerge: add a 'leave unresolved' option to regular prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27161
diff
changeset
|
262 choice = ['local', 'other', 'unresolved'][index] |
26851
859f453e8b4e
filemerge.prompt: separate out choice selection and action
Siddharth Agarwal <sid0@fb.com>
parents:
26730
diff
changeset
|
263 |
26898
33eb8a56d0c9
filemerge: treat EOF at prompt as fail, not abort
Siddharth Agarwal <sid0@fb.com>
parents:
26893
diff
changeset
|
264 if choice == 'other': |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
265 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf, |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
266 labels) |
27162
4ab69be0ea15
filemerge: add a 'leave unresolved' option to regular prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27161
diff
changeset
|
267 elif choice == 'local': |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
268 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf, |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
269 labels) |
27162
4ab69be0ea15
filemerge: add a 'leave unresolved' option to regular prompts
Siddharth Agarwal <sid0@fb.com>
parents:
27161
diff
changeset
|
270 elif choice == 'unresolved': |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
271 return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
272 labels) |
26898
33eb8a56d0c9
filemerge: treat EOF at prompt as fail, not abort
Siddharth Agarwal <sid0@fb.com>
parents:
26893
diff
changeset
|
273 except error.ResponseExpected: |
33eb8a56d0c9
filemerge: treat EOF at prompt as fail, not abort
Siddharth Agarwal <sid0@fb.com>
parents:
26893
diff
changeset
|
274 ui.write("\n") |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
275 return _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
276 labels) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
277 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
278 @internaltool('local', nomerge) |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
279 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): |
28640
4fc640fd0026
filemerge: use revset notation for p1/p2 of local/other descriptions
timeless <timeless@mozdev.org>
parents:
28578
diff
changeset
|
280 """Uses the local `p1()` version of files as the merged version.""" |
27036
63d6bc874dea
filemerge: add support for change/delete conflicts to the ':local' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27034
diff
changeset
|
281 return 0, fcd.isabsent() |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
282 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
283 @internaltool('other', nomerge) |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
284 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): |
28640
4fc640fd0026
filemerge: use revset notation for p1/p2 of local/other descriptions
timeless <timeless@mozdev.org>
parents:
28578
diff
changeset
|
285 """Uses the other `p2()` version of files as the merged version.""" |
27037
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
286 if fco.isabsent(): |
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
287 # local changed, remote deleted -- 'deleted' picked |
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
288 repo.wvfs.unlinkpath(fcd.path()) |
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
289 deleted = True |
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
290 else: |
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
291 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
292 deleted = False |
a8908c139f2f
filemerge: add support for change/delete conflicts to the ':other' merge tool
Siddharth Agarwal <sid0@fb.com>
parents:
27036
diff
changeset
|
293 return 0, deleted |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
294 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
295 @internaltool('fail', nomerge) |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
296 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
297 """ |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
298 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
|
299 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
|
300 used to resolve these conflicts.""" |
27123
4dc5951df1e4
filemerge: in ':fail' tool, write out other side if local side is deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27047
diff
changeset
|
301 # for change/delete conflicts write out the changed version, then fail |
4dc5951df1e4
filemerge: in ':fail' tool, write out other side if local side is deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27047
diff
changeset
|
302 if fcd.isabsent(): |
4dc5951df1e4
filemerge: in ':fail' tool, write out other side if local side is deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27047
diff
changeset
|
303 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
27032
28ee7af4b685
filemerge: return whether the file is deleted for nomerge internal tools
Siddharth Agarwal <sid0@fb.com>
parents:
26979
diff
changeset
|
304 return 1, False |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
305 |
27041
0e330f59ef68
filemerge: don't attempt to premerge change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27040
diff
changeset
|
306 def _premerge(repo, fcd, fco, fca, toolconf, files, labels=None): |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
307 tool, toolpath, binary, symlink = toolconf |
27041
0e330f59ef68
filemerge: don't attempt to premerge change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27040
diff
changeset
|
308 if symlink or fcd.isabsent() or fco.isabsent(): |
18257
a35d0128545e
merge: never do premerge on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
18256
diff
changeset
|
309 return 1 |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
310 a, b, c, back = files |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
311 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
312 ui = repo.ui |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
313 |
22032
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
314 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
|
315 |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
316 # do we attempt to simplemerge first? |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
317 try: |
18257
a35d0128545e
merge: never do premerge on symlinks
Mads Kiilerich <mads@kiilerich.com>
parents:
18256
diff
changeset
|
318 premerge = _toolbool(ui, tool, "premerge", not binary) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
319 except error.ConfigError: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
320 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
|
321 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
|
322 _valid = ', '.join(["'" + v + "'" for v in validkeep]) |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
323 raise error.ConfigError(_("%s.premerge not valid " |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
324 "('%s' is neither boolean nor %s)") % |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
325 (tool, premerge, _valid)) |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
326 |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
327 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
|
328 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
|
329 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
|
330 labels = _defaultconflictlabels |
d7f25834ffbb
merge-tools: add a `premerge=keep-merge3` config option
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22031
diff
changeset
|
331 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
|
332 labels.append('base') |
22023
f18830651811
simplemerge: burn "minimal" feature to the ground
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22022
diff
changeset
|
333 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
|
334 if not r: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
335 ui.debug(" premerge successful\n") |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
336 return 0 |
22031
b36c60cfe46f
merge-tools: make premerge valid values extensible
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22028
diff
changeset
|
337 if premerge not in validkeep: |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
338 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
|
339 return 1 # continue merging |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
340 |
26948
067ab07435c9
filemerge: rename _symlinkcheck to _mergecheck
Siddharth Agarwal <sid0@fb.com>
parents:
26941
diff
changeset
|
341 def _mergecheck(repo, mynode, orig, fcd, fco, fca, toolconf): |
26515
0ffa7fe1076b
filemerge: add a precheck for symlinks
Siddharth Agarwal <sid0@fb.com>
parents:
26514
diff
changeset
|
342 tool, toolpath, binary, symlink = toolconf |
0ffa7fe1076b
filemerge: add a precheck for symlinks
Siddharth Agarwal <sid0@fb.com>
parents:
26514
diff
changeset
|
343 if symlink: |
26518
a77679d0b887
filemerge: print correct name of tool for symlink checks
Siddharth Agarwal <sid0@fb.com>
parents:
26517
diff
changeset
|
344 repo.ui.warn(_('warning: internal %s cannot merge symlinks ' |
a77679d0b887
filemerge: print correct name of tool for symlink checks
Siddharth Agarwal <sid0@fb.com>
parents:
26517
diff
changeset
|
345 'for %s\n') % (tool, fcd.path())) |
26515
0ffa7fe1076b
filemerge: add a precheck for symlinks
Siddharth Agarwal <sid0@fb.com>
parents:
26514
diff
changeset
|
346 return False |
27040
1bde66b89bb2
filemerge._mergecheck: add check for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27039
diff
changeset
|
347 if fcd.isabsent() or fco.isabsent(): |
1bde66b89bb2
filemerge._mergecheck: add check for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27039
diff
changeset
|
348 repo.ui.warn(_('warning: internal %s cannot merge change/delete ' |
1bde66b89bb2
filemerge._mergecheck: add check for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27039
diff
changeset
|
349 'conflict for %s\n') % (tool, fcd.path())) |
1bde66b89bb2
filemerge._mergecheck: add check for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27039
diff
changeset
|
350 return False |
26515
0ffa7fe1076b
filemerge: add a precheck for symlinks
Siddharth Agarwal <sid0@fb.com>
parents:
26514
diff
changeset
|
351 return True |
0ffa7fe1076b
filemerge: add a precheck for symlinks
Siddharth Agarwal <sid0@fb.com>
parents:
26514
diff
changeset
|
352 |
26070
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
353 def _merge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels, mode): |
16127
14dc2bbba6d2
filemerge: remove some redundancy in decorators/docstrings
Matt Mackall <mpm@selenic.com>
parents:
16126
diff
changeset
|
354 """ |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
355 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
|
356 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
|
357 the partially merged file. Markers will have two sections, one for each side |
26070
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
358 of merge, unless mode equals 'union' which suppresses the markers.""" |
26572
c7850af6bb75
filemerge._merge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26567
diff
changeset
|
359 a, b, c, back = files |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
360 |
26572
c7850af6bb75
filemerge._merge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26567
diff
changeset
|
361 ui = repo.ui |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
362 |
26572
c7850af6bb75
filemerge._merge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26567
diff
changeset
|
363 r = simplemerge.simplemerge(ui, a, b, c, label=labels, mode=mode) |
27033
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
364 return True, r, False |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
365 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
366 @internaltool('union', fullmerge, |
26614
ef1eb6df7071
simplemerge: move conflict warning message to filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26613
diff
changeset
|
367 _("warning: conflicts while merging %s! " |
ef1eb6df7071
simplemerge: move conflict warning message to filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26613
diff
changeset
|
368 "(edit, then use 'hg resolve --mark')\n"), |
26948
067ab07435c9
filemerge: rename _symlinkcheck to _mergecheck
Siddharth Agarwal <sid0@fb.com>
parents:
26941
diff
changeset
|
369 precheck=_mergecheck) |
26071
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
370 def _iunion(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
371 """ |
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
372 Uses the internal non-interactive simple merge algorithm for merging |
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
373 files. It will use both left and right sides for conflict regions. |
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
374 No markers are inserted.""" |
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
375 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf, |
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
376 files, labels, 'union') |
ff12a6c63c3d
filemerge: add 'union' merge to internal merge tool
Erik Huelsmann <ehuels@gmail.com>
parents:
26070
diff
changeset
|
377 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
378 @internaltool('merge', fullmerge, |
26614
ef1eb6df7071
simplemerge: move conflict warning message to filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26613
diff
changeset
|
379 _("warning: conflicts while merging %s! " |
ef1eb6df7071
simplemerge: move conflict warning message to filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26613
diff
changeset
|
380 "(edit, then use 'hg resolve --mark')\n"), |
26948
067ab07435c9
filemerge: rename _symlinkcheck to _mergecheck
Siddharth Agarwal <sid0@fb.com>
parents:
26941
diff
changeset
|
381 precheck=_mergecheck) |
26070
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
382 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
383 """ |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
384 Uses the internal non-interactive simple merge algorithm for merging |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
385 files. It will fail if there are any conflicts and leave markers in |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
386 the partially merged file. Markers will have two sections, one for each side |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
387 of merge.""" |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
388 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf, |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
389 files, labels, 'merge') |
e15966216aec
filemerge: split internal merge into api entry point and internal helper
Erik Huelsmann <ehuels@gmail.com>
parents:
25949
diff
changeset
|
390 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
391 @internaltool('merge3', fullmerge, |
26614
ef1eb6df7071
simplemerge: move conflict warning message to filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26613
diff
changeset
|
392 _("warning: conflicts while merging %s! " |
ef1eb6df7071
simplemerge: move conflict warning message to filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26613
diff
changeset
|
393 "(edit, then use 'hg resolve --mark')\n"), |
26948
067ab07435c9
filemerge: rename _symlinkcheck to _mergecheck
Siddharth Agarwal <sid0@fb.com>
parents:
26941
diff
changeset
|
394 precheck=_mergecheck) |
22028
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
395 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
|
396 """ |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 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
|
401 if not labels: |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
402 labels = _defaultconflictlabels |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
403 if len(labels) < 3: |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
404 labels.append('base') |
3d0572ab3b4a
merge: add an internal:merge3 tool
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
22027
diff
changeset
|
405 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
|
406 |
26224
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
407 def _imergeauto(repo, mynode, orig, fcd, fco, fca, toolconf, files, |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
408 labels=None, localorother=None): |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
409 """ |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
410 Generic driver for _imergelocal and _imergeother |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
411 """ |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
412 assert localorother is not None |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
413 tool, toolpath, binary, symlink = toolconf |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
414 a, b, c, back = files |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
415 r = simplemerge.simplemerge(repo.ui, a, b, c, label=labels, |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
416 localorother=localorother) |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
417 return True, r |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
418 |
26948
067ab07435c9
filemerge: rename _symlinkcheck to _mergecheck
Siddharth Agarwal <sid0@fb.com>
parents:
26941
diff
changeset
|
419 @internaltool('merge-local', mergeonly, precheck=_mergecheck) |
26224
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
420 def _imergelocal(*args, **kwargs): |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
421 """ |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
422 Like :merge, but resolve all conflicts non-interactively in favor |
28640
4fc640fd0026
filemerge: use revset notation for p1/p2 of local/other descriptions
timeless <timeless@mozdev.org>
parents:
28578
diff
changeset
|
423 of the local `p1()` changes.""" |
26224
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
424 success, status = _imergeauto(localorother='local', *args, **kwargs) |
27033
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
425 return success, status, False |
26224
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
426 |
26948
067ab07435c9
filemerge: rename _symlinkcheck to _mergecheck
Siddharth Agarwal <sid0@fb.com>
parents:
26941
diff
changeset
|
427 @internaltool('merge-other', mergeonly, precheck=_mergecheck) |
26224
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
428 def _imergeother(*args, **kwargs): |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
429 """ |
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
430 Like :merge, but resolve all conflicts non-interactively in favor |
28640
4fc640fd0026
filemerge: use revset notation for p1/p2 of local/other descriptions
timeless <timeless@mozdev.org>
parents:
28578
diff
changeset
|
431 of the other `p2()` changes.""" |
26224
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
432 success, status = _imergeauto(localorother='other', *args, **kwargs) |
27033
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
433 return success, status, False |
26224
a4da463df6cf
filemerge: add non-interactive :merge-local and :merge-other
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
26071
diff
changeset
|
434 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
435 @internaltool('tagmerge', mergeonly, |
21922
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
436 _("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
|
437 "(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
|
438 "tool of your choice)\n")) |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
439 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
|
440 """ |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
441 Uses the internal tag merge algorithm (experimental). |
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
442 """ |
27033
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
443 success, status = tagmerge.merge(repo, fcd, fco, fca) |
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
444 return success, status, False |
21922
50e20154cb68
filemerge: add internal:tagmerge merge tool
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21921
diff
changeset
|
445 |
26526
7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
Siddharth Agarwal <sid0@fb.com>
parents:
26525
diff
changeset
|
446 @internaltool('dump', fullmerge) |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
447 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
|
448 """ |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
449 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
|
450 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
|
451 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
|
452 ``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
|
453 ``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
|
454 same directory as ``a.txt``.""" |
26573
a875773cf537
filemerge._idump: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26572
diff
changeset
|
455 a, b, c, back = files |
a875773cf537
filemerge._idump: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26572
diff
changeset
|
456 |
a875773cf537
filemerge._idump: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26572
diff
changeset
|
457 fd = fcd.path() |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
458 |
26573
a875773cf537
filemerge._idump: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26572
diff
changeset
|
459 util.copyfile(a, a + ".local") |
a875773cf537
filemerge._idump: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26572
diff
changeset
|
460 repo.wwrite(fd + ".other", fco.data(), fco.flags()) |
a875773cf537
filemerge._idump: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26572
diff
changeset
|
461 repo.wwrite(fd + ".base", fca.data(), fca.flags()) |
27033
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
462 return False, 1, False |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
463 |
21273
20b8090d8125
merge: define conflict marker labels in filemerge()
Durham Goode <durham@fb.com>
parents:
21100
diff
changeset
|
464 def _xmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
26574
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
465 tool, toolpath, binary, symlink = toolconf |
27042
30b919bc49bf
filemerge: don't try using external tools on change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27041
diff
changeset
|
466 if fcd.isabsent() or fco.isabsent(): |
30b919bc49bf
filemerge: don't try using external tools on change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27041
diff
changeset
|
467 repo.ui.warn(_('warning: %s cannot merge change/delete conflict ' |
30b919bc49bf
filemerge: don't try using external tools on change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27041
diff
changeset
|
468 'for %s\n') % (tool, fcd.path())) |
30b919bc49bf
filemerge: don't try using external tools on change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27041
diff
changeset
|
469 return False, 1, None |
26574
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
470 a, b, c, back = files |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
471 out = "" |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
472 env = {'HG_FILE': fcd.path(), |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
473 'HG_MY_NODE': short(mynode), |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
474 'HG_OTHER_NODE': str(fco.changectx()), |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
475 'HG_BASE_NODE': str(fca.changectx()), |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
476 'HG_MY_ISLINK': 'l' in fcd.flags(), |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
477 'HG_OTHER_ISLINK': 'l' in fco.flags(), |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
478 'HG_BASE_ISLINK': 'l' in fca.flags(), |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
479 } |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
480 |
26574
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
481 ui = repo.ui |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
482 |
26574
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
483 args = _toolstr(ui, tool, "args", '$local $base $other') |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
484 if "$output" in args: |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
485 out, a = a, back # read input from backup, write to original |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
486 replace = {'local': a, 'base': b, 'other': c, 'output': out} |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
487 args = util.interpolate(r'\$', replace, args, |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
488 lambda s: util.shellquote(util.localpath(s))) |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
489 cmd = toolpath + ' ' + args |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
490 repo.ui.debug('launching merge tool: %s\n' % cmd) |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
491 r = ui.system(cmd, cwd=repo.root, environ=env) |
f82cb7dffb49
filemerge._xmerge: drop no longer necessary 'if r:' check
Siddharth Agarwal <sid0@fb.com>
parents:
26573
diff
changeset
|
492 repo.ui.debug('merge tool returned: %s\n' % r) |
27033
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
493 return True, r, False |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
494 |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
495 def _formatconflictmarker(repo, ctx, template, label, pad): |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
496 """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
|
497 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
498 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
|
499 can have aligned templated parts. |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
500 """ |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
501 if ctx.node() is None: |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
502 ctx = ctx.p1() |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
503 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
504 props = templatekw.keywords.copy() |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
505 props['templ'] = template |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
506 props['ctx'] = ctx |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
507 props['repo'] = repo |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
508 templateresult = template('conflictmarker', **props) |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
509 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
510 label = ('%s:' % label).ljust(pad + 1) |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
511 mark = '%s %s' % (label, templater.stringify(templateresult)) |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
512 |
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
|
513 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
|
514 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
|
515 |
21865
78e56e70c70a
filemerge: use 'util.ellipsis' to trim custom conflict markers correctly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21864
diff
changeset
|
516 # 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
|
517 return util.ellipsis(mark, 80 - 8) |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
518 |
29660
99b50346b750
merge: concatenate default conflict marker at parsing phase of .py
Yuya Nishihara <yuya@tcha.org>
parents:
28955
diff
changeset
|
519 _defaultconflictmarker = ('{node|short} ' |
99b50346b750
merge: concatenate default conflict marker at parsing phase of .py
Yuya Nishihara <yuya@tcha.org>
parents:
28955
diff
changeset
|
520 '{ifeq(tags, "tip", "", "{tags} ")}' |
99b50346b750
merge: concatenate default conflict marker at parsing phase of .py
Yuya Nishihara <yuya@tcha.org>
parents:
28955
diff
changeset
|
521 '{if(bookmarks, "{bookmarks} ")}' |
99b50346b750
merge: concatenate default conflict marker at parsing phase of .py
Yuya Nishihara <yuya@tcha.org>
parents:
28955
diff
changeset
|
522 '{ifeq(branch, "default", "", "{branch} ")}' |
99b50346b750
merge: concatenate default conflict marker at parsing phase of .py
Yuya Nishihara <yuya@tcha.org>
parents:
28955
diff
changeset
|
523 '- {author|user}: {desc|firstline}') |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
524 |
21524
47b97d9af27e
merge: add labels parameter from merge.update to filemerge
Durham Goode <durham@fb.com>
parents:
21519
diff
changeset
|
525 _defaultconflictlabels = ['local', 'other'] |
47b97d9af27e
merge: add labels parameter from merge.update to filemerge
Durham Goode <durham@fb.com>
parents:
21519
diff
changeset
|
526 |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
527 def _formatlabels(repo, fcd, fco, fca, labels): |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
528 """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
|
529 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
530 Returns a list of formatted labels. |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
531 """ |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
532 cd = fcd.changectx() |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
533 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
|
534 ca = fca.changectx() |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
535 |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
536 ui = repo.ui |
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
537 template = ui.config('ui', 'mergemarkertemplate', _defaultconflictmarker) |
28955
78759f78a44e
templater: factor out function that creates templater from string template
Yuya Nishihara <yuya@tcha.org>
parents:
28954
diff
changeset
|
538 tmpl = formatter.maketemplater(ui, 'conflictmarker', template) |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
539 |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
540 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
|
541 |
22026
6966542768ff
filemerge: allow the formatting of three labels instead of two
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22025
diff
changeset
|
542 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
|
543 _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
|
544 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
|
545 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
|
546 return newlabels |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
547 |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
548 def partextras(labels): |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
549 """Return a dictionary of extra labels for use in prompts to the user |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
550 |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
551 Intended use is in strings of the form "(l)ocal%(l)s". |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
552 """ |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
553 if labels is None: |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
554 return { |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
555 "l": "", |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
556 "o": "", |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
557 } |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
558 |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
559 return { |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
560 "l": " [%s]" % labels[0], |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
561 "o": " [%s]" % labels[1], |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
562 } |
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
563 |
26607
45a6233d5f50
filemerge: introduce a premerge flag and function
Siddharth Agarwal <sid0@fb.com>
parents:
26606
diff
changeset
|
564 def _filemerge(premerge, 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
|
565 """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
|
566 |
26607
45a6233d5f50
filemerge: introduce a premerge flag and function
Siddharth Agarwal <sid0@fb.com>
parents:
26606
diff
changeset
|
567 premerge = whether this is a premerge |
6512
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
568 mynode = parent node before merge |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
569 orig = original local filename before merge |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
570 fco = other file context |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
571 fca = ancestor file context |
368a4ec603cc
merge: introduce mergestate
Matt Mackall <mpm@selenic.com>
parents:
6212
diff
changeset
|
572 fcd = local file context for current/destination file |
26606
2a405d307f8c
filemerge: also return whether the merge is complete
Siddharth Agarwal <sid0@fb.com>
parents:
26605
diff
changeset
|
573 |
27034
86ede9eda252
filemerge: return whether the file was deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27033
diff
changeset
|
574 Returns whether the merge is complete, the return value of the merge, and |
86ede9eda252
filemerge: return whether the file was deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27033
diff
changeset
|
575 a boolean indicating whether the file was deleted from disk.""" |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
576 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
577 def temp(prefix, ctx): |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
578 pre = "%s~%s." % (os.path.basename(ctx.path()), prefix) |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
579 (fd, name) = tempfile.mkstemp(prefix=pre) |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
580 data = repo.wwritedata(ctx.path(), ctx.data()) |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
581 f = os.fdopen(fd, "wb") |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
582 f.write(data) |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
583 f.close() |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
584 return name |
26512
4c52dd406adc
filemerge: indent filemerge.filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26224
diff
changeset
|
585 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
586 if not fco.cmp(fcd): # files identical? |
27034
86ede9eda252
filemerge: return whether the file was deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27033
diff
changeset
|
587 return True, None, False |
26512
4c52dd406adc
filemerge: indent filemerge.filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26224
diff
changeset
|
588 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
589 ui = repo.ui |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
590 fd = fcd.path() |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
591 binary = fcd.isbinary() or fco.isbinary() or fca.isbinary() |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
592 symlink = 'l' in fcd.flags() + fco.flags() |
27039
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
593 changedelete = fcd.isabsent() or fco.isabsent() |
d7517deedf86
filemerge._picktool: only pick from nomerge tools for change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27038
diff
changeset
|
594 tool, toolpath = _picktool(repo, ui, fd, binary, symlink, changedelete) |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
595 if tool in internals and tool.startswith('internal:'): |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
596 # normalize to new-style names (':merge' etc) |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
597 tool = tool[len('internal'):] |
27161
296d55def9c4
filemerge: add debug output for whether this is a change/delete conflict
Siddharth Agarwal <sid0@fb.com>
parents:
27124
diff
changeset
|
598 ui.debug("picked tool '%s' for %s (binary %s symlink %s changedelete %s)\n" |
296d55def9c4
filemerge: add debug output for whether this is a change/delete conflict
Siddharth Agarwal <sid0@fb.com>
parents:
27124
diff
changeset
|
599 % (tool, fd, binary, symlink, changedelete)) |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
600 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
601 if tool in internals: |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
602 func = internals[tool] |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
603 mergetype = func.mergetype |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
604 onfailure = func.onfailure |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
605 precheck = func.precheck |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
606 else: |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
607 func = _xmerge |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
608 mergetype = fullmerge |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
609 onfailure = _("merging %s failed!\n") |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
610 precheck = None |
26512
4c52dd406adc
filemerge: indent filemerge.filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26224
diff
changeset
|
611 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
612 toolconf = tool, toolpath, binary, symlink |
6003
7855b88ba838
filemerge: pull file-merging code into its own module
Matt Mackall <mpm@selenic.com>
parents:
diff
changeset
|
613 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
614 if mergetype == nomerge: |
29774
a7f8939641aa
merge: use labels in prompts to the user
Simon Farnsworth <simonfar@fb.com>
parents:
29660
diff
changeset
|
615 r, deleted = func(repo, mynode, orig, fcd, fco, fca, toolconf, labels) |
27034
86ede9eda252
filemerge: return whether the file was deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27033
diff
changeset
|
616 return True, r, deleted |
26512
4c52dd406adc
filemerge: indent filemerge.filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26224
diff
changeset
|
617 |
26609
47681e77e484
filemerge: only print out "merging f" output at premerge step
Siddharth Agarwal <sid0@fb.com>
parents:
26608
diff
changeset
|
618 if premerge: |
47681e77e484
filemerge: only print out "merging f" output at premerge step
Siddharth Agarwal <sid0@fb.com>
parents:
26608
diff
changeset
|
619 if orig != fco.path(): |
47681e77e484
filemerge: only print out "merging f" output at premerge step
Siddharth Agarwal <sid0@fb.com>
parents:
26608
diff
changeset
|
620 ui.status(_("merging %s and %s to %s\n") % (orig, fco.path(), fd)) |
47681e77e484
filemerge: only print out "merging f" output at premerge step
Siddharth Agarwal <sid0@fb.com>
parents:
26608
diff
changeset
|
621 else: |
47681e77e484
filemerge: only print out "merging f" output at premerge step
Siddharth Agarwal <sid0@fb.com>
parents:
26608
diff
changeset
|
622 ui.status(_("merging %s\n") % fd) |
26528
8bfef5737321
filemerge: move 'merging' output to before file creation
Siddharth Agarwal <sid0@fb.com>
parents:
26527
diff
changeset
|
623 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
624 ui.debug("my %s other %s ancestor %s\n" % (fcd, fco, fca)) |
26528
8bfef5737321
filemerge: move 'merging' output to before file creation
Siddharth Agarwal <sid0@fb.com>
parents:
26527
diff
changeset
|
625 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
626 if precheck and not precheck(repo, mynode, orig, fcd, fco, fca, |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
627 toolconf): |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
628 if onfailure: |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
629 ui.warn(onfailure % fd) |
27034
86ede9eda252
filemerge: return whether the file was deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27033
diff
changeset
|
630 return True, 1, False |
26529
7833b13b001f
filemerge: move precheck to before files are written out
Siddharth Agarwal <sid0@fb.com>
parents:
26528
diff
changeset
|
631 |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
632 a = repo.wjoin(fd) |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
633 b = temp("base", fca) |
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
634 c = temp("other", fco) |
27047
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
635 if not fcd.isabsent(): |
27651
07fc2f2134ba
origpath: move from cmdutil to scmutil
Siddharth Agarwal <sid0@fb.com>
parents:
27599
diff
changeset
|
636 back = scmutil.origpath(ui, repo, a) |
27047
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
637 if premerge: |
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
638 util.copyfile(a, back) |
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
639 else: |
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
640 back = None |
26608
ae5b60d3294f
filemerge: deindent the parts of filemerge outside the try block
Siddharth Agarwal <sid0@fb.com>
parents:
26607
diff
changeset
|
641 files = (a, b, c, back) |
26512
4c52dd406adc
filemerge: indent filemerge.filemerge
Siddharth Agarwal <sid0@fb.com>
parents:
26224
diff
changeset
|
642 |
26589
fb388aa26453
filemerge: clean up temp files in a finally block
Siddharth Agarwal <sid0@fb.com>
parents:
26575
diff
changeset
|
643 r = 1 |
fb388aa26453
filemerge: clean up temp files in a finally block
Siddharth Agarwal <sid0@fb.com>
parents:
26575
diff
changeset
|
644 try: |
26529
7833b13b001f
filemerge: move precheck to before files are written out
Siddharth Agarwal <sid0@fb.com>
parents:
26528
diff
changeset
|
645 markerstyle = ui.config('ui', 'mergemarkers', 'basic') |
7833b13b001f
filemerge: move precheck to before files are written out
Siddharth Agarwal <sid0@fb.com>
parents:
26528
diff
changeset
|
646 if not labels: |
7833b13b001f
filemerge: move precheck to before files are written out
Siddharth Agarwal <sid0@fb.com>
parents:
26528
diff
changeset
|
647 labels = _defaultconflictlabels |
7833b13b001f
filemerge: move precheck to before files are written out
Siddharth Agarwal <sid0@fb.com>
parents:
26528
diff
changeset
|
648 if markerstyle != 'basic': |
7833b13b001f
filemerge: move precheck to before files are written out
Siddharth Agarwal <sid0@fb.com>
parents:
26528
diff
changeset
|
649 labels = _formatlabels(repo, fcd, fco, fca, labels) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
650 |
26607
45a6233d5f50
filemerge: introduce a premerge flag and function
Siddharth Agarwal <sid0@fb.com>
parents:
26606
diff
changeset
|
651 if premerge and mergetype == fullmerge: |
27041
0e330f59ef68
filemerge: don't attempt to premerge change/delete conflicts
Siddharth Agarwal <sid0@fb.com>
parents:
27040
diff
changeset
|
652 r = _premerge(repo, fcd, fco, fca, toolconf, files, labels=labels) |
26611
a5ff66e6d77a
filemerge: break overall filemerge into separate premerge and merge steps
Siddharth Agarwal <sid0@fb.com>
parents:
26610
diff
changeset
|
653 # complete if premerge successful (r is 0) |
27034
86ede9eda252
filemerge: return whether the file was deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27033
diff
changeset
|
654 return not r, r, False |
26567
f18646cf0e93
filemerge: call premerge directly from main merge function
Siddharth Agarwal <sid0@fb.com>
parents:
26529
diff
changeset
|
655 |
27033
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
656 needcheck, r, deleted = func(repo, mynode, orig, fcd, fco, fca, |
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
657 toolconf, files, labels=labels) |
089dab8794dc
filemerge: return whether the file is deleted from all other merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27032
diff
changeset
|
658 |
26575
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
659 if needcheck: |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
660 r = _check(r, ui, tool, fcd, files) |
21519
25d5a9ecbb85
merge: add conflict marker formatter (BC)
Durham Goode <durham@fb.com>
parents:
21273
diff
changeset
|
661 |
16125
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
662 if r: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
663 if onfailure: |
83925d3a4559
filemerge: refactoring of 'filemerge()'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
15738
diff
changeset
|
664 ui.warn(onfailure % fd) |
26589
fb388aa26453
filemerge: clean up temp files in a finally block
Siddharth Agarwal <sid0@fb.com>
parents:
26575
diff
changeset
|
665 |
27034
86ede9eda252
filemerge: return whether the file was deleted
Siddharth Agarwal <sid0@fb.com>
parents:
27033
diff
changeset
|
666 return True, r, deleted |
26589
fb388aa26453
filemerge: clean up temp files in a finally block
Siddharth Agarwal <sid0@fb.com>
parents:
26575
diff
changeset
|
667 finally: |
27047
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
668 if not r and back is not None: |
21100
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
669 util.unlink(back) |
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
670 util.unlink(b) |
098a274764b3
filemerge: better handling of failing remove of temporary files
Mads Kiilerich <madski@unity3d.com>
parents:
20676
diff
changeset
|
671 util.unlink(c) |
6004
5af5f0f9d724
merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents:
6003
diff
changeset
|
672 |
26575
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
673 def _check(r, ui, tool, fcd, files): |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
674 fd = fcd.path() |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
675 a, b, c, back = files |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
676 |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
677 if not r and (_toolbool(ui, tool, "checkconflicts") or |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
678 'conflicts' in _toollist(ui, tool, "check")): |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
679 if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(), |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
680 re.MULTILINE): |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
681 r = 1 |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
682 |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
683 checked = False |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
684 if 'prompt' in _toollist(ui, tool, "check"): |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
685 checked = True |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
686 if ui.promptchoice(_("was merge of '%s' successful (yn)?" |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
687 "$$ &Yes $$ &No") % fd, 1): |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
688 r = 1 |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
689 |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
690 if not r and not checked and (_toolbool(ui, tool, "checkchanged") or |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
691 'changed' in |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
692 _toollist(ui, tool, "check")): |
27047
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
693 if back is not None and filecmp.cmp(a, back): |
26575
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
694 if ui.promptchoice(_(" output file %s appears unchanged\n" |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
695 "was merge successful (yn)?" |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
696 "$$ &Yes $$ &No") % fd, 1): |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
697 r = 1 |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
698 |
27047
e1458049dca5
filemerge: don't try to copy files known to be absent
Siddharth Agarwal <sid0@fb.com>
parents:
27042
diff
changeset
|
699 if back is not None and _toolbool(ui, tool, "fixeol"): |
26575
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
700 _matcheol(a, back) |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
701 |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
702 return r |
d60815664c34
filemerge: move post-merge checks into a separate function
Siddharth Agarwal <sid0@fb.com>
parents:
26574
diff
changeset
|
703 |
26607
45a6233d5f50
filemerge: introduce a premerge flag and function
Siddharth Agarwal <sid0@fb.com>
parents:
26606
diff
changeset
|
704 def premerge(repo, mynode, orig, fcd, fco, fca, labels=None): |
45a6233d5f50
filemerge: introduce a premerge flag and function
Siddharth Agarwal <sid0@fb.com>
parents:
26606
diff
changeset
|
705 return _filemerge(True, repo, mynode, orig, fcd, fco, fca, labels=labels) |
45a6233d5f50
filemerge: introduce a premerge flag and function
Siddharth Agarwal <sid0@fb.com>
parents:
26606
diff
changeset
|
706 |
26605
ef21a2c41629
filemerge: add a wrapper around the filemerge function
Siddharth Agarwal <sid0@fb.com>
parents:
26589
diff
changeset
|
707 def filemerge(repo, mynode, orig, fcd, fco, fca, labels=None): |
26611
a5ff66e6d77a
filemerge: break overall filemerge into separate premerge and merge steps
Siddharth Agarwal <sid0@fb.com>
parents:
26610
diff
changeset
|
708 return _filemerge(False, repo, mynode, orig, fcd, fco, fca, labels=labels) |
26605
ef21a2c41629
filemerge: add a wrapper around the filemerge function
Siddharth Agarwal <sid0@fb.com>
parents:
26589
diff
changeset
|
709 |
16126
0c4bec9596d8
filemerge: create detail of internal merge tools from documentation string
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
16125
diff
changeset
|
710 # 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
|
711 i18nfunctions = internals.values() |