##// END OF EJS Templates
filemerge: when using in-memory merge, always put backup files in temp dir...
Martin von Zweigbergk -
r49631:c7dbfc36 default
parent child Browse files
Show More
@@ -877,7 +877,7 b' def partextras(labels):'
877 }
877 }
878
878
879
879
880 def _makebackup(repo, ui, wctx, fcd):
880 def _makebackup(repo, ui, fcd):
881 """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.
882
882
883 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`
@@ -894,30 +894,17 b' def _makebackup(repo, ui, wctx, fcd):'
894 # merge -> filemerge). (I suspect the fileset import is the weakest link)
894 # merge -> filemerge). (I suspect the fileset import is the weakest link)
895 from . import context
895 from . import context
896
896
897 backup = scmutil.backuppath(ui, repo, fcd.path())
897 if isinstance(fcd, context.overlayworkingfilectx):
898 inworkingdir = backup.startswith(repo.wvfs.base) and not backup.startswith(
898 # If we're merging in-memory, we're free to put the backup anywhere.
899 repo.vfs.base
899 fd, backup = pycompat.mkstemp(b'hg-merge-backup')
900 )
900 with os.fdopen(fd, 'wb') as f:
901 if isinstance(fcd, context.overlayworkingfilectx) and inworkingdir:
901 f.write(fcd.data())
902 # If the backup file is to be in the working directory, and we're
903 # merging in-memory, we must redirect the backup to the memory context
904 # so we don't disturb the working directory.
905 relpath = backup[len(repo.wvfs.base) + 1 :]
906 wctx[relpath].write(fcd.data(), fcd.flags())
907 return wctx[relpath]
908 else:
902 else:
909 # Otherwise, write to wherever path the user specified the backups
903 backup = scmutil.backuppath(ui, repo, fcd.path())
910 # should go. We still need to switch based on whether the source is
904 a = _workingpath(repo, fcd)
911 # in-memory so we can use the fast path of ``util.copy`` if both are
905 util.copyfile(a, backup)
912 # on disk.
906
913 if isinstance(fcd, context.overlayworkingfilectx):
907 return context.arbitraryfilectx(backup, repo=repo)
914 util.writefile(backup, fcd.data())
915 else:
916 a = _workingpath(repo, fcd)
917 util.copyfile(a, backup)
918 # A arbitraryfilectx is returned, so we can run the same functions on
919 # the backup context regardless of where it lives.
920 return context.arbitraryfilectx(backup, repo=repo)
921
908
922
909
923 @contextlib.contextmanager
910 @contextlib.contextmanager
@@ -1065,7 +1052,7 b' def filemerge(repo, wctx, mynode, orig, '
1065 ui.warn(onfailure % fduipath)
1052 ui.warn(onfailure % fduipath)
1066 return 1, False
1053 return 1, False
1067
1054
1068 backup = _makebackup(repo, ui, wctx, fcd)
1055 backup = _makebackup(repo, ui, fcd)
1069 r = 1
1056 r = 1
1070 try:
1057 try:
1071 internalmarkerstyle = ui.config(b'ui', b'mergemarkers')
1058 internalmarkerstyle = ui.config(b'ui', b'mergemarkers')
General Comments 0
You need to be logged in to leave comments. Login now