batchget: add support for backing up files
authorSiddharth Agarwal <sid0@fb.com>
Sat, 02 Jan 2016 03:21:01 -0800
changeset 27656 57c0d4888ca8
parent 27655 af13eaf9ab8c
child 27657 7b5c8c8a2f8c
batchget: add support for backing up files We're going to use this in an upcoming feature.
mercurial/merge.py
--- 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