D1806: filemerge: fix backing up an in-memory file to a custom location
phillco (Phil Cohen)
phabricator at mercurial-scm.org
Fri Jan 5 00:38:17 EST 2018
phillco updated this revision to Diff 4699.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D1806?vs=4697&id=4699
REVISION DETAIL
https://phab.mercurial-scm.org/D1806
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
@@ -618,6 +618,9 @@
(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.
"""
if fcd.isabsent():
return None
@@ -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):
To: phillco, #hg-reviewers, durham
Cc: durham, mercurial-devel
More information about the Mercurial-devel
mailing list