Mercurial > public > mercurial-scm > hg
comparison mercurial/filemerge.py @ 26526:7fa3560443fd
filemerge: switch trymerge boolean to mergetype enum
trymerge = False becomes mergetype = nomerge, and trymerge = True becomes
mergetype = fullmerge or mergeonly, depending on whether a premerge happens.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 07 Oct 2015 16:14:57 -0700 |
parents | abc2327e382a |
children | b4aab4223102 |
comparison
equal
deleted
inserted
replaced
26525:abc2327e382a | 26526:7fa3560443fd |
---|---|
41 # internal tool merge types | 41 # internal tool merge types |
42 nomerge = None | 42 nomerge = None |
43 mergeonly = 'mergeonly' # just the full merge, no premerge | 43 mergeonly = 'mergeonly' # just the full merge, no premerge |
44 fullmerge = 'fullmerge' # both premerge and merge | 44 fullmerge = 'fullmerge' # both premerge and merge |
45 | 45 |
46 def internaltool(name, trymerge, onfailure=None, precheck=None): | 46 def internaltool(name, mergetype, onfailure=None, precheck=None): |
47 '''return a decorator for populating internal merge tool table''' | 47 '''return a decorator for populating internal merge tool table''' |
48 def decorator(func): | 48 def decorator(func): |
49 fullname = ':' + name | 49 fullname = ':' + name |
50 func.__doc__ = "``%s``\n" % fullname + func.__doc__.strip() | 50 func.__doc__ = "``%s``\n" % fullname + func.__doc__.strip() |
51 internals[fullname] = func | 51 internals[fullname] = func |
52 internals['internal:' + name] = func | 52 internals['internal:' + name] = func |
53 internalsdoc[fullname] = func | 53 internalsdoc[fullname] = func |
54 func.trymerge = trymerge | 54 func.mergetype = mergetype |
55 func.onfailure = onfailure | 55 func.onfailure = onfailure |
56 func.precheck = precheck | 56 func.precheck = precheck |
57 return func | 57 return func |
58 return decorator | 58 return decorator |
59 | 59 |
163 if style: | 163 if style: |
164 newdata = data.replace(style, tostyle) | 164 newdata = data.replace(style, tostyle) |
165 if newdata != data: | 165 if newdata != data: |
166 util.writefile(file, newdata) | 166 util.writefile(file, newdata) |
167 | 167 |
168 @internaltool('prompt', False) | 168 @internaltool('prompt', nomerge) |
169 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf): | 169 def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf): |
170 """Asks the user which of the local or the other version to keep as | 170 """Asks the user which of the local or the other version to keep as |
171 the merged version.""" | 171 the merged version.""" |
172 ui = repo.ui | 172 ui = repo.ui |
173 fd = fcd.path() | 173 fd = fcd.path() |
177 "$$ &Local $$ &Other") % fd, 0): | 177 "$$ &Local $$ &Other") % fd, 0): |
178 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf) | 178 return _iother(repo, mynode, orig, fcd, fco, fca, toolconf) |
179 else: | 179 else: |
180 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf) | 180 return _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf) |
181 | 181 |
182 @internaltool('local', False) | 182 @internaltool('local', nomerge) |
183 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf): | 183 def _ilocal(repo, mynode, orig, fcd, fco, fca, toolconf): |
184 """Uses the local version of files as the merged version.""" | 184 """Uses the local version of files as the merged version.""" |
185 return 0 | 185 return 0 |
186 | 186 |
187 @internaltool('other', False) | 187 @internaltool('other', nomerge) |
188 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf): | 188 def _iother(repo, mynode, orig, fcd, fco, fca, toolconf): |
189 """Uses the other version of files as the merged version.""" | 189 """Uses the other version of files as the merged version.""" |
190 repo.wwrite(fcd.path(), fco.data(), fco.flags()) | 190 repo.wwrite(fcd.path(), fco.data(), fco.flags()) |
191 return 0 | 191 return 0 |
192 | 192 |
193 @internaltool('fail', False) | 193 @internaltool('fail', nomerge) |
194 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf): | 194 def _ifail(repo, mynode, orig, fcd, fco, fca, toolconf): |
195 """ | 195 """ |
196 Rather than attempting to merge files that were modified on both | 196 Rather than attempting to merge files that were modified on both |
197 branches, it marks them as unresolved. The resolve command must be | 197 branches, it marks them as unresolved. The resolve command must be |
198 used to resolve these conflicts.""" | 198 used to resolve these conflicts.""" |
255 | 255 |
256 r = simplemerge.simplemerge(ui, a, b, c, label=labels, mode=mode) | 256 r = simplemerge.simplemerge(ui, a, b, c, label=labels, mode=mode) |
257 return True, r | 257 return True, r |
258 return False, 0 | 258 return False, 0 |
259 | 259 |
260 @internaltool('union', True, | 260 @internaltool('union', fullmerge, |
261 _("merging %s incomplete! " | 261 _("merging %s incomplete! " |
262 "(edit conflicts, then use 'hg resolve --mark')\n"), | 262 "(edit conflicts, then use 'hg resolve --mark')\n"), |
263 precheck=_symlinkcheck) | 263 precheck=_symlinkcheck) |
264 def _iunion(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): | 264 def _iunion(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
265 """ | 265 """ |
267 files. It will use both left and right sides for conflict regions. | 267 files. It will use both left and right sides for conflict regions. |
268 No markers are inserted.""" | 268 No markers are inserted.""" |
269 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf, | 269 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf, |
270 files, labels, 'union') | 270 files, labels, 'union') |
271 | 271 |
272 @internaltool('merge', True, | 272 @internaltool('merge', fullmerge, |
273 _("merging %s incomplete! " | 273 _("merging %s incomplete! " |
274 "(edit conflicts, then use 'hg resolve --mark')\n"), | 274 "(edit conflicts, then use 'hg resolve --mark')\n"), |
275 precheck=_symlinkcheck) | 275 precheck=_symlinkcheck) |
276 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): | 276 def _imerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
277 """ | 277 """ |
280 the partially merged file. Markers will have two sections, one for each side | 280 the partially merged file. Markers will have two sections, one for each side |
281 of merge.""" | 281 of merge.""" |
282 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf, | 282 return _merge(repo, mynode, orig, fcd, fco, fca, toolconf, |
283 files, labels, 'merge') | 283 files, labels, 'merge') |
284 | 284 |
285 @internaltool('merge3', True, | 285 @internaltool('merge3', fullmerge, |
286 _("merging %s incomplete! " | 286 _("merging %s incomplete! " |
287 "(edit conflicts, then use 'hg resolve --mark')\n"), | 287 "(edit conflicts, then use 'hg resolve --mark')\n"), |
288 precheck=_symlinkcheck) | 288 precheck=_symlinkcheck) |
289 def _imerge3(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): | 289 def _imerge3(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
290 """ | 290 """ |
312 a, b, c, back = files | 312 a, b, c, back = files |
313 r = simplemerge.simplemerge(repo.ui, a, b, c, label=labels, | 313 r = simplemerge.simplemerge(repo.ui, a, b, c, label=labels, |
314 localorother=localorother) | 314 localorother=localorother) |
315 return True, r | 315 return True, r |
316 | 316 |
317 @internaltool('merge-local', True) | 317 @internaltool('merge-local', mergeonly) |
318 def _imergelocal(*args, **kwargs): | 318 def _imergelocal(*args, **kwargs): |
319 """ | 319 """ |
320 Like :merge, but resolve all conflicts non-interactively in favor | 320 Like :merge, but resolve all conflicts non-interactively in favor |
321 of the local changes.""" | 321 of the local changes.""" |
322 success, status = _imergeauto(localorother='local', *args, **kwargs) | 322 success, status = _imergeauto(localorother='local', *args, **kwargs) |
323 return success, status | 323 return success, status |
324 | 324 |
325 @internaltool('merge-other', True) | 325 @internaltool('merge-other', mergeonly) |
326 def _imergeother(*args, **kwargs): | 326 def _imergeother(*args, **kwargs): |
327 """ | 327 """ |
328 Like :merge, but resolve all conflicts non-interactively in favor | 328 Like :merge, but resolve all conflicts non-interactively in favor |
329 of the other changes.""" | 329 of the other changes.""" |
330 success, status = _imergeauto(localorother='other', *args, **kwargs) | 330 success, status = _imergeauto(localorother='other', *args, **kwargs) |
331 return success, status | 331 return success, status |
332 | 332 |
333 @internaltool('tagmerge', True, | 333 @internaltool('tagmerge', mergeonly, |
334 _("automatic tag merging of %s failed! " | 334 _("automatic tag merging of %s failed! " |
335 "(use 'hg resolve --tool :merge' or another merge " | 335 "(use 'hg resolve --tool :merge' or another merge " |
336 "tool of your choice)\n")) | 336 "tool of your choice)\n")) |
337 def _itagmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): | 337 def _itagmerge(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
338 """ | 338 """ |
339 Uses the internal tag merge algorithm (experimental). | 339 Uses the internal tag merge algorithm (experimental). |
340 """ | 340 """ |
341 return tagmerge.merge(repo, fcd, fco, fca) | 341 return tagmerge.merge(repo, fcd, fco, fca) |
342 | 342 |
343 @internaltool('dump', True) | 343 @internaltool('dump', fullmerge) |
344 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): | 344 def _idump(repo, mynode, orig, fcd, fco, fca, toolconf, files, labels=None): |
345 """ | 345 """ |
346 Creates three versions of the files to merge, containing the | 346 Creates three versions of the files to merge, containing the |
347 contents of local, other and base. These files can then be used to | 347 contents of local, other and base. These files can then be used to |
348 perform a merge manually. If the file to be merged is named | 348 perform a merge manually. If the file to be merged is named |
477 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" % | 477 ui.debug("picked tool '%s' for %s (binary %s symlink %s)\n" % |
478 (tool, fd, binary, symlink)) | 478 (tool, fd, binary, symlink)) |
479 | 479 |
480 if tool in internals: | 480 if tool in internals: |
481 func = internals[tool] | 481 func = internals[tool] |
482 trymerge = func.trymerge | 482 mergetype = func.mergetype |
483 onfailure = func.onfailure | 483 onfailure = func.onfailure |
484 precheck = func.precheck | 484 precheck = func.precheck |
485 else: | 485 else: |
486 func = _xmerge | 486 func = _xmerge |
487 trymerge = True | 487 mergetype = fullmerge |
488 onfailure = _("merging %s failed!\n") | 488 onfailure = _("merging %s failed!\n") |
489 precheck = None | 489 precheck = None |
490 | 490 |
491 toolconf = tool, toolpath, binary, symlink | 491 toolconf = tool, toolpath, binary, symlink |
492 | 492 |
493 if not trymerge: | 493 if mergetype == nomerge: |
494 return func(repo, mynode, orig, fcd, fco, fca, toolconf) | 494 return func(repo, mynode, orig, fcd, fco, fca, toolconf) |
495 | 495 |
496 a = repo.wjoin(fd) | 496 a = repo.wjoin(fd) |
497 b = temp("base", fca) | 497 b = temp("base", fca) |
498 c = temp("other", fco) | 498 c = temp("other", fco) |