17 return ui.configbool("merge-tools", tool + "." + part, default) |
17 return ui.configbool("merge-tools", tool + "." + part, default) |
18 |
18 |
19 def _toollist(ui, tool, part, default=[]): |
19 def _toollist(ui, tool, part, default=[]): |
20 return ui.configlist("merge-tools", tool + "." + part, default) |
20 return ui.configlist("merge-tools", tool + "." + part, default) |
21 |
21 |
22 _internal = {} |
22 internals = {} |
23 |
23 |
24 def internaltool(name, trymerge, onfailure=None): |
24 def internaltool(name, trymerge, onfailure=None): |
25 '''return a decorator for populating internal merge tool table''' |
25 '''return a decorator for populating internal merge tool table''' |
26 def decorator(func): |
26 def decorator(func): |
27 _internal[name] = func |
27 internals[name] = func |
28 func.trymerge = trymerge |
28 func.trymerge = trymerge |
29 func.onfailure = onfailure |
29 func.onfailure = onfailure |
30 return func |
30 return func |
31 return decorator |
31 return decorator |
32 |
32 |
33 def _findtool(ui, tool): |
33 def _findtool(ui, tool): |
34 if tool in _internal: |
34 if tool in internals: |
35 return tool |
35 return tool |
36 for kn in ("regkey", "regkeyalt"): |
36 for kn in ("regkey", "regkeyalt"): |
37 k = _toolstr(ui, tool, kn) |
37 k = _toolstr(ui, tool, kn) |
38 if not k: |
38 if not k: |
39 continue |
39 continue |
131 if newdata != data: |
131 if newdata != data: |
132 util.writefile(file, newdata) |
132 util.writefile(file, newdata) |
133 |
133 |
134 @internaltool('internal:prompt', False) |
134 @internaltool('internal:prompt', False) |
135 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf): |
135 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf): |
|
136 """``internal:prompt`` |
|
137 Asks the user which of the local or the other version to keep as |
|
138 the merged version.""" |
136 ui = repo.ui |
139 ui = repo.ui |
137 fd = fcd.path() |
140 fd = fcd.path() |
138 |
141 |
139 if ui.promptchoice(_(" no tool found to merge %s\n" |
142 if ui.promptchoice(_(" no tool found to merge %s\n" |
140 "keep (l)ocal or take (o)ther?") % fd, |
143 "keep (l)ocal or take (o)ther?") % fd, |
143 else: |
146 else: |
144 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf) |
147 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf) |
145 |
148 |
146 @internaltool('internal:local', False) |
149 @internaltool('internal:local', False) |
147 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf): |
150 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf): |
|
151 """``internal:local`` |
|
152 Uses the local version of files as the merged version.""" |
148 return 0 |
153 return 0 |
149 |
154 |
150 @internaltool('internal:other', False) |
155 @internaltool('internal:other', False) |
151 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf): |
156 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf): |
|
157 """``internal:other`` |
|
158 Uses the other version of files as the merged version.""" |
152 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
159 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
153 return 0 |
160 return 0 |
154 |
161 |
155 @internaltool('internal:fail', False) |
162 @internaltool('internal:fail', False) |
156 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf): |
163 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf): |
|
164 """``internal:fail`` |
|
165 Rather than attempting to merge files that were modified on both |
|
166 branches, it marks them as unresolved. The resolve command must be |
|
167 used to resolve these conflicts.""" |
157 return 1 |
168 return 1 |
158 |
169 |
159 def _premerge(repo, toolconf, files): |
170 def _premerge(repo, toolconf, files): |
160 tool, toolpath, binary, symlink = toolconf |
171 tool, toolpath, binary, symlink = toolconf |
161 a, b, c, back = files |
172 a, b, c, back = files |
185 |
196 |
186 @internaltool('internal:merge', True, |
197 @internaltool('internal:merge', True, |
187 _("merging %s incomplete! " |
198 _("merging %s incomplete! " |
188 "(edit conflicts, then use 'hg resolve --mark')\n")) |
199 "(edit conflicts, then use 'hg resolve --mark')\n")) |
189 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files): |
200 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files): |
|
201 """``internal:merge`` |
|
202 Uses the internal non-interactive simple merge algorithm for merging |
|
203 files. It will fail if there are any conflicts and leave markers in |
|
204 the partially merged file.""" |
190 r = _premerge(repo, toolconf, files) |
205 r = _premerge(repo, toolconf, files) |
191 if r: |
206 if r: |
192 a, b, c, back = files |
207 a, b, c, back = files |
193 |
208 |
194 ui = repo.ui |
209 ui = repo.ui |
197 return True, r |
212 return True, r |
198 return False, 0 |
213 return False, 0 |
199 |
214 |
200 @internaltool('internal:dump', True) |
215 @internaltool('internal:dump', True) |
201 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files): |
216 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files): |
|
217 """``internal:dump`` |
|
218 Creates three versions of the files to merge, containing the |
|
219 contents of local, other and base. These files can then be used to |
|
220 perform a merge manually. If the file to be merged is named |
|
221 ``a.txt``, these files will accordingly be named ``a.txt.local``, |
|
222 ``a.txt.other`` and ``a.txt.base`` and they will be placed in the |
|
223 same directory as ``a.txt``.""" |
202 r = _premerge(repo, toolconf, files) |
224 r = _premerge(repo, toolconf, files) |
203 if r: |
225 if r: |
204 a, b, c, back = files |
226 a, b, c, back = files |
205 |
227 |
206 fd = fcd.path() |
228 fd = fcd.path() |
265 symlink = 'l' in fcd.flags() + fco.flags() |
287 symlink = 'l' in fcd.flags() + fco.flags() |
266 tool, toolpath = _picktool(repo, ui, fd, binary, symlink) |
288 tool, toolpath = _picktool(repo, ui, fd, binary, symlink) |
267 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" % |
289 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" % |
268 (tool, fd, binary, symlink)) |
290 (tool, fd, binary, symlink)) |
269 |
291 |
270 if tool in _internal: |
292 if tool in internals: |
271 func = _internal[tool] |
293 func = internals[tool] |
272 trymerge = func.trymerge |
294 trymerge = func.trymerge |
273 onfailure = func.onfailure |
295 onfailure = func.onfailure |
274 else: |
296 else: |
275 func = _xmerge |
297 func = _xmerge |
276 trymerge = True |
298 trymerge = True |