[PATCH 4 of 5] transaction: handle backup of a missing file in `backupentries`

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Oct 18 06:44:56 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1413627584 25200
#      Sat Oct 18 03:19:44 2014 -0700
# Node ID 85a27c5441d6fbbc86a8272b46c2f1eb4255389e
# Parent  f533386d7f84a8e5ad1885d654d5983d81302b79
transaction: handle backup of a missing file in `backupentries`

We can easily handle the restoration of "no-file" in the `backupentries` record.
This avoids having to grow "location" capability to the "entries" record.

diff --git a/mercurial/transaction.py b/mercurial/transaction.py
--- a/mercurial/transaction.py
+++ b/mercurial/transaction.py
@@ -43,17 +43,24 @@ def _playback(journal, report, opener, v
 
     backupfiles = []
     for l, f, b, _ignore in backupentries:
         vfs = vfsmap[l]
         filepath = vfs.join(f)
-        backuppath = vfs.join(b)
-        try:
-            util.copyfile(backuppath, filepath)
-            backupfiles.append(b)
-        except IOError:
-            report(_("failed to recover %s\n") % f)
-            raise
+        if b:
+            backuppath = vfs.join(b)
+            try:
+                util.copyfile(backuppath, filepath)
+                backupfiles.append(b)
+            except IOError:
+                report(_("failed to recover %s\n") % f)
+                raise
+        else:
+            try:
+                vfs.unlink(f)
+            except (IOError, OSError), inst:
+                if inst.errno != errno.ENOENT:
+                    raise
 
     opener.unlink(journal)
     backuppath = "%s.backupfiles2" % journal
     if opener.exists(backuppath):
         opener.unlink(backuppath)
@@ -167,12 +174,11 @@ class transaction(object):
         if vfs.exists(file):
             filepath = vfs.join(file)
             backuppath = self.opener.join(backupfile)
             util.copyfiles(filepath, backuppath, hardlink=hardlink)
         else:
-            self.add(file, 0)
-            return
+            backupfile = ''
 
         if self._queue:
             self._queue[-1][1].append((file, backupfile))
             return
 
@@ -280,12 +286,13 @@ class transaction(object):
         if self.opener.isfile(self.journal):
             self.opener.unlink(self.journal)
         if self.opener.isfile(self.backupjournal):
             self.opener.unlink(self.backupjournal)
             for l, _f, b, _ignore in self.backupentries:
-                vfs = self._vfsmap[l]
-                vfs.unlink(b)
+                if b:
+                    vfs = self._vfsmap[l]
+                    vfs.unlink(b)
         self.backupentries = []
         self.journal = None
 
     @active
     def abort(self):


More information about the Mercurial-devel mailing list