transaction: include backup file in the "undo" transaction
authorPierre-Yves David <pierre-yves.david@fb.com>
Fri, 16 Jan 2015 18:34:14 -0800
changeset 23904 d251da5e0e84
parent 23903 426607be9c69
child 23905 8b5b963ba95a
transaction: include backup file in the "undo" transaction Once the transaction is closed, we now write transaction related data for possible future undo. For now, we only do it for full file "backup" because their were not handle at all in that case. In the future, we could move all the current logic to set undo up (that currently exists in localrepository) inside transaction itself, but it is not strictly requires to solve the current situation.
mercurial/transaction.py
tests/test-fncache.t
tests/test-hardlinks.t
tests/test-hook.t
tests/test-inherit-mode.t
--- a/mercurial/transaction.py	Fri Jan 16 19:35:04 2015 -0800
+++ b/mercurial/transaction.py	Fri Jan 16 18:34:14 2015 -0800
@@ -405,6 +405,7 @@
                     self.report("couldn't remote %s: %s\n"
                                 % (vfs.join(b), inst))
         self.entries = []
+        self._writeundo()
         if self.after:
             self.after()
         if self.opener.isfile(self.journal):
@@ -440,6 +441,32 @@
         scope)'''
         self._abort()
 
+    def _writeundo(self):
+        """write transaction data for possible future undo call"""
+        if self.undoname is None:
+            return
+        undobackupfile = self.opener.open("%s.backupfiles" % self.undoname, 'w')
+        undobackupfile.write('%d\n' % version)
+        for l, f, b, c in self._backupentries:
+            if not f:  # temporary file
+                continue
+            if not b:
+                u = ''
+            else:
+                if l not in self._vfsmap and c:
+                    self.report("couldn't remote %s: unknown cache location"
+                                "%s\n" % (b, l))
+                    continue
+                vfs = self._vfsmap[l]
+                base, name = vfs.split(b)
+                assert name.startswith(self.journal), name
+                uname = name.replace(self.journal, self.undoname, 1)
+                u = vfs.reljoin(base, uname)
+                util.copyfile(vfs.join(b), vfs.join(u), hardlink=True)
+            undobackupfile.write("%s\0%s\0%s\0%d\n" % (l, f, u, c))
+        undobackupfile.close()
+
+
     def _abort(self):
         self.count = 0
         self.usages = 0
--- a/tests/test-fncache.t	Fri Jan 16 19:35:04 2015 -0800
+++ b/tests/test-fncache.t	Fri Jan 16 18:34:14 2015 -0800
@@ -81,6 +81,7 @@
   .hg/phaseroots
   .hg/requires
   .hg/undo
+  .hg/undo.backupfiles
   .hg/undo.bookmarks
   .hg/undo.branch
   .hg/undo.desc
@@ -114,6 +115,7 @@
   .hg/store/data/tst.d.hg/_foo.i
   .hg/store/phaseroots
   .hg/store/undo
+  .hg/store/undo.backupfiles
   .hg/store/undo.phaseroots
   .hg/undo.bookmarks
   .hg/undo.branch
--- a/tests/test-hardlinks.t	Fri Jan 16 19:35:04 2015 -0800
+++ b/tests/test-hardlinks.t	Fri Jan 16 18:34:14 2015 -0800
@@ -50,6 +50,8 @@
   1 r1/.hg/store/fncache
   1 r1/.hg/store/phaseroots
   1 r1/.hg/store/undo
+  1 r1/.hg/store/undo.backup.fncache
+  1 r1/.hg/store/undo.backupfiles
   1 r1/.hg/store/undo.phaseroots
 
 
@@ -80,6 +82,8 @@
   2 r1/.hg/store/fncache
   1 r1/.hg/store/phaseroots
   1 r1/.hg/store/undo
+  1 r1/.hg/store/undo.backup.fncache
+  1 r1/.hg/store/undo.backupfiles
   1 r1/.hg/store/undo.phaseroots
 
   $ nlinksdir r2/.hg/store
@@ -99,6 +103,7 @@
   1 r3/.hg/store/fncache
   1 r3/.hg/store/phaseroots
   1 r3/.hg/store/undo
+  1 r3/.hg/store/undo.backupfiles
   1 r3/.hg/store/undo.phaseroots
 
 
@@ -124,6 +129,9 @@
   1 r3/.hg/store/fncache
   1 r3/.hg/store/phaseroots
   1 r3/.hg/store/undo
+  1 r3/.hg/store/undo.backup.fncache
+  1 r3/.hg/store/undo.backup.phaseroots
+  1 r3/.hg/store/undo.backupfiles
   1 r3/.hg/store/undo.phaseroots
 
 Push to repo r1 should break up most hardlinks in r2:
@@ -151,7 +159,7 @@
   1 r2/.hg/store/00manifest.i
   1 r2/.hg/store/data/d1/f2.i
   2 r2/.hg/store/data/f1.i
-  1 r2/.hg/store/fncache
+  2 r2/.hg/store/fncache
 
   $ hg -R r2 verify
   checking changesets
@@ -176,7 +184,7 @@
   1 r2/.hg/store/00manifest.i
   1 r2/.hg/store/data/d1/f2.i
   1 r2/.hg/store/data/f1.i
-  1 r2/.hg/store/fncache
+  2 r2/.hg/store/fncache
 
 
   $ cd r3
@@ -210,6 +218,9 @@
   2 r4/.hg/store/fncache
   2 r4/.hg/store/phaseroots
   2 r4/.hg/store/undo
+  2 r4/.hg/store/undo.backup.fncache
+  2 r4/.hg/store/undo.backup.phaseroots
+  2 r4/.hg/store/undo.backupfiles
   2 r4/.hg/store/undo.phaseroots
   2 r4/.hg/undo.bookmarks
   2 r4/.hg/undo.branch
@@ -242,6 +253,9 @@
   2 r4/.hg/store/fncache
   2 r4/.hg/store/phaseroots
   2 r4/.hg/store/undo
+  2 r4/.hg/store/undo.backup.fncache
+  2 r4/.hg/store/undo.backup.phaseroots
+  2 r4/.hg/store/undo.backupfiles
   2 r4/.hg/store/undo.phaseroots
   2 r4/.hg/undo.bookmarks
   2 r4/.hg/undo.branch
--- a/tests/test-hook.t	Fri Jan 16 19:35:04 2015 -0800
+++ b/tests/test-hook.t	Fri Jan 16 18:34:14 2015 -0800
@@ -158,6 +158,8 @@
   journal.phaseroots
   phaseroots
   undo
+  undo.backup.fncache
+  undo.backupfiles
   undo.phaseroots
 
 
--- a/tests/test-inherit-mode.t	Fri Jan 16 19:35:04 2015 -0800
+++ b/tests/test-inherit-mode.t	Fri Jan 16 18:34:14 2015 -0800
@@ -81,6 +81,7 @@
   00660 ./.hg/store/fncache
   00660 ./.hg/store/phaseroots
   00660 ./.hg/store/undo
+  00660 ./.hg/store/undo.backupfiles
   00660 ./.hg/store/undo.phaseroots
   00660 ./.hg/undo.bookmarks
   00660 ./.hg/undo.branch
@@ -125,6 +126,7 @@
   00660 ../push/.hg/store/data/foo.i
   00660 ../push/.hg/store/fncache
   00660 ../push/.hg/store/undo
+  00660 ../push/.hg/store/undo.backupfiles
   00660 ../push/.hg/store/undo.phaseroots
   00660 ../push/.hg/undo.bookmarks
   00660 ../push/.hg/undo.branch