Patchwork D1806: filemerge: fix backing up an in-memory file to a custom location

login
register
mail settings
Submitter phabricator
Date Jan. 5, 2018, 5:35 a.m.
Message ID <de6667d86d6a49741fdd9b64912b33c1@localhost.localdomain>
Download mbox | patch
Permalink /patch/26553/
State Not Applicable
Headers show

Comments

phabricator - Jan. 5, 2018, 5:35 a.m.
phillco updated this revision to Diff 4697.
phillco edited the summary of this revision.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1806?vs=4688&id=4697

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

AFFECTED FILES
  mercurial/filemerge.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -618,7 +618,10 @@ 
     (if any), the backup is used to undo certain premerges, confirm whether a
     merge changed anything, and determine what line endings the new file should
     have.
-    """
+
+    Backups only need to be written once (right before the premerge) since their
+    content doesn't change afterwards.
+s    """
     if fcd.isabsent():
         return None
     # TODO: Break this import cycle somehow. (filectx -> ctx -> fileset ->
@@ -628,21 +631,25 @@ 
     back = scmutil.origpath(ui, repo, a)
     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.
-        #
+        if premerge:
+            # Otherwise, write to wherever path the user specified the backups
+            # should go. We still need to switch based on whether the source is
+            # in-memory so we can use the fast path of ``util.copy`` if both are
+            # on disk.
+            if isinstance(fcd, context.overlayworkingfilectx):
+                util.writefile(back, fcd.data())
+            else:
+                util.copyfile(a, back)
         # 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):