mercurial/filemerge.py
changeset 48756 86e4b86df932
parent 48755 6ae3c97a0919
child 48758 7dad4665d223
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