comparison mercurial/filemerge.py @ 48756:86e4b86df932

filemerge: when not keeping premerge, don't write markers to context When premerge is enabled (as it is for non-binary inputs by default) and the markers are not kept, we currently still write it to the output context and then restore the previous content right after. With the refactoring in the previous patch, we can easily avoid that step and instead write the output in the opposite case (i.e. when it's successful or when the markers are supposed to be kept). Differential Revision: https://phab.mercurial-scm.org/D12149
author Martin von Zweigbergk <martinvonz@google.com>
date Tue, 18 Jan 2022 12:57:55 -0800
parents 6ae3c97a0919
children 7dad4665d223
comparison
equal deleted inserted replaced
48755:6ae3c97a0919 48756:86e4b86df932
409 msg = _(b"%s looks like a binary file.") % input.fctx.path() 409 msg = _(b"%s looks like a binary file.") % input.fctx.path()
410 ui.warn(_(b'warning: %s\n') % msg) 410 ui.warn(_(b'warning: %s\n') % msg)
411 raise error.Abort(msg) 411 raise error.Abort(msg)
412 412
413 413
414 def _premerge(repo, local, other, base, toolconf, backup): 414 def _premerge(repo, local, other, base, toolconf):
415 tool, toolpath, binary, symlink, scriptfn = toolconf 415 tool, toolpath, binary, symlink, scriptfn = toolconf
416 if symlink or local.fctx.isabsent() or other.fctx.isabsent(): 416 if symlink or local.fctx.isabsent() or other.fctx.isabsent():
417 return 1 417 return 1
418 418
419 ui = repo.ui 419 ui = repo.ui
443 ): 443 ):
444 return 1 # continue merging 444 return 1 # continue merging
445 merged_text, conflicts = simplemerge.simplemerge( 445 merged_text, conflicts = simplemerge.simplemerge(
446 ui, local, base, other, mode=mode 446 ui, local, base, other, mode=mode
447 ) 447 )
448 # fcd.flags() already has the merged flags (done in 448 if not conflicts or premerge in validkeep:
449 # mergestate.resolve()) 449 # fcd.flags() already has the merged flags (done in
450 local.fctx.write(merged_text, local.fctx.flags()) 450 # mergestate.resolve())
451 local.fctx.write(merged_text, local.fctx.flags())
451 if not conflicts: 452 if not conflicts:
452 ui.debug(b" premerge successful\n") 453 ui.debug(b" premerge successful\n")
453 return 0 454 return 0
454 if premerge not in validkeep:
455 # restore from backup and try again
456 _restorebackup(local.fctx, backup)
457 return 1 # continue merging 455 return 1 # continue merging
458 456
459 457
460 def _mergecheck(repo, mynode, fcd, fco, fca, toolconf): 458 def _mergecheck(repo, mynode, fcd, fco, fca, toolconf):
461 tool, toolpath, binary, symlink, scriptfn = toolconf 459 tool, toolpath, binary, symlink, scriptfn = toolconf
877 b"l": b" [%s]" % labels[0], 875 b"l": b" [%s]" % labels[0],
878 b"o": b" [%s]" % labels[1], 876 b"o": b" [%s]" % labels[1],
879 } 877 }
880 878
881 879
882 def _restorebackup(fcd, backup):
883 # TODO: Add a workingfilectx.write(otherfilectx) path so we can use
884 # util.copy here instead.
885 fcd.write(backup.data(), fcd.flags())
886
887
888 def _makebackup(repo, ui, wctx, fcd): 880 def _makebackup(repo, ui, wctx, fcd):
889 """Makes and returns a filectx-like object for ``fcd``'s backup file. 881 """Makes and returns a filectx-like object for ``fcd``'s backup file.
890 882
891 In addition to preserving the user's pre-existing modifications to `fcd` 883 In addition to preserving the user's pre-existing modifications to `fcd`
892 (if any), the backup is used to undo certain premerges, confirm whether a 884 (if any), the backup is used to undo certain premerges, confirm whether a
1121 repo, 1113 repo,
1122 local, 1114 local,
1123 other, 1115 other,
1124 base, 1116 base,
1125 toolconf, 1117 toolconf,
1126 backup,
1127 ) 1118 )
1128 # we're done if premerge was successful (r is 0) 1119 # we're done if premerge was successful (r is 0)
1129 if not r: 1120 if not r:
1130 return r, False 1121 return r, False
1131 1122