mercurial/mergestate.py
changeset 45497 e833ff4dd0ea
parent 45496 ef3273ac5f6e
child 45498 cc5f811b1f15
equal deleted inserted replaced
45496:ef3273ac5f6e 45497:e833ff4dd0ea
   543         """hash the path of a local file context for storage in the .hg/merge
   543         """hash the path of a local file context for storage in the .hg/merge
   544         directory."""
   544         directory."""
   545 
   545 
   546         return hex(hashutil.sha1(path).digest())
   546         return hex(hashutil.sha1(path).digest())
   547 
   547 
       
   548     def _make_backup(self, fctx, localkey):
       
   549         self._repo.vfs.write(b'merge/' + localkey, fctx.data())
       
   550 
       
   551     def _restore_backup(self, fctx, localkey, flags):
       
   552         with self._repo.vfs(b'merge/' + localkey) as f:
       
   553             fctx.write(f.read(), flags)
       
   554 
   548     def add(self, fcl, fco, fca, fd):
   555     def add(self, fcl, fco, fca, fd):
   549         """add a new (potentially?) conflicting file the merge state
   556         """add a new (potentially?) conflicting file the merge state
   550         fcl: file context for local,
   557         fcl: file context for local,
   551         fco: file context for remote,
   558         fco: file context for remote,
   552         fca: file context for ancestors,
   559         fca: file context for ancestors,
   556         """
   563         """
   557         if fcl.isabsent():
   564         if fcl.isabsent():
   558             localkey = nullhex
   565             localkey = nullhex
   559         else:
   566         else:
   560             localkey = mergestate.getlocalkey(fcl.path())
   567             localkey = mergestate.getlocalkey(fcl.path())
   561             self._repo.vfs.write(b'merge/' + localkey, fcl.data())
   568             self._make_backup(fcl, localkey)
   562         self._state[fd] = [
   569         self._state[fd] = [
   563             MERGE_RECORD_UNRESOLVED,
   570             MERGE_RECORD_UNRESOLVED,
   564             localkey,
   571             localkey,
   565             fcl.path(),
   572             fcl.path(),
   566             fca.path(),
   573             fca.path(),
   662             elif flags == fla:
   669             elif flags == fla:
   663                 flags = flo
   670                 flags = flo
   664         if preresolve:
   671         if preresolve:
   665             # restore local
   672             # restore local
   666             if localkey != nullhex:
   673             if localkey != nullhex:
   667                 f = self._repo.vfs(b'merge/' + localkey)
   674                 self._restore_backup(wctx[dfile], localkey, flags)
   668                 wctx[dfile].write(f.read(), flags)
       
   669                 f.close()
       
   670             else:
   675             else:
   671                 wctx[dfile].remove(ignoremissing=True)
   676                 wctx[dfile].remove(ignoremissing=True)
   672             complete, merge_ret, deleted = filemerge.premerge(
   677             complete, merge_ret, deleted = filemerge.premerge(
   673                 self._repo,
   678                 self._repo,
   674                 wctx,
   679                 wctx,