changeset 27656:57c0d4888ca8

batchget: add support for backing up files We're going to use this in an upcoming feature.
author Siddharth Agarwal <sid0@fb.com>
date Sat, 02 Jan 2016 03:21:01 -0800
parents af13eaf9ab8c
children 7b5c8c8a2f8c
files mercurial/merge.py
diffstat 1 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/merge.py	Sat Jan 02 03:02:57 2016 -0800
+++ b/mercurial/merge.py	Sat Jan 02 03:21:01 2016 -0800
@@ -26,6 +26,7 @@
     error,
     filemerge,
     obsolete,
+    scmutil,
     subrepo,
     util,
     worker,
@@ -971,12 +972,27 @@
     verbose = repo.ui.verbose
     fctx = mctx.filectx
     wwrite = repo.wwrite
+    ui = repo.ui
     i = 0
-    for f, args, msg in actions:
+    for f, (flags, backup), msg in actions:
         repo.ui.debug(" %s: %s -> g\n" % (f, msg))
         if verbose:
             repo.ui.note(_("getting %s\n") % f)
-        wwrite(f, fctx(f).data(), args[0])
+
+        if backup:
+            absf = repo.wjoin(f)
+            orig = scmutil.origpath(ui, repo, absf)
+            try:
+                # TODO Mercurial has always aborted if an untracked directory
+                # is replaced by a tracked file, or generally with
+                # file/directory merges. This needs to be sorted out.
+                if repo.wvfs.isfileorlink(f):
+                    util.rename(absf, orig)
+            except OSError as e:
+                if e.errno != errno.ENOENT:
+                    raise
+
+        wwrite(f, fctx(f).data(), flags)
         if i == 100:
             yield i, f
             i = 0