D1059: filemerge: store backups in the overlayworkingctx if using imm

phillco (Phil Cohen) phabricator at mercurial-scm.org
Mon Oct 16 21:46:42 EDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rHGb5e7aa688689: filemerge: store backups in the overlayworkingctx if using imm (authored by phillco, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1059?vs=2698&id=2864

REVISION DETAIL
  https://phab.mercurial-scm.org/D1059

AFFECTED FILES
  mercurial/filemerge.py

CHANGE DETAILS

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -606,9 +606,24 @@
     from . import context
     a = _workingpath(repo, fcd)
     back = scmutil.origpath(ui, repo, a)
-    if premerge:
-        util.copyfile(a, back)
-    return context.arbitraryfilectx(back, repo=repo)
+    inworkingdir = (back.startswith(repo.wvfs.base) and not
+        back.startswith(repo.vfs.base))
+
+    if isinstance(fcd, context.overlayworkingfilectx) and inworkingdir:
+        # If the backup file is to be in the working directory, and we're
+        # merging in-memory, we must redirect the backup to the memory context
+        # so we don't disturb the working directory.
+        relpath = back[len(repo.wvfs.base) + 1:]
+        wctx[relpath].write(fcd.data(), fcd.flags())
+        return wctx[relpath]
+    else:
+        # Otherwise, write to wherever the user specified the backups should go.
+        #
+        # A arbitraryfilectx is returned, so we can run the same functions on
+        # the backup context regardless of where it lives.
+        if premerge:
+            util.copyfile(a, back)
+        return context.arbitraryfilectx(back, repo=repo)
 
 def _maketempfiles(repo, fco, fca):
     """Writes out `fco` and `fca` as temporary files, so an external merge



To: phillco, #hg-reviewers, durin42
Cc: mercurial-devel


More information about the Mercurial-devel mailing list