# HG changeset patch # User Pierre-Yves David # Date 2015-01-17 02:34:14 # Node ID d251da5e0e841971cc54f2fc1fc4d70743056b5c # Parent 426607be9c6960588b66e24548dd3cdc8c69d18c 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. diff --git a/mercurial/transaction.py b/mercurial/transaction.py --- a/mercurial/transaction.py +++ b/mercurial/transaction.py @@ -405,6 +405,7 @@ class transaction(object): 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 @@ class transaction(object): 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 diff --git a/tests/test-fncache.t b/tests/test-fncache.t --- a/tests/test-fncache.t +++ b/tests/test-fncache.t @@ -81,6 +81,7 @@ Non store repo: .hg/phaseroots .hg/requires .hg/undo + .hg/undo.backupfiles .hg/undo.bookmarks .hg/undo.branch .hg/undo.desc @@ -114,6 +115,7 @@ Non fncache repo: .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 diff --git a/tests/test-hardlinks.t b/tests/test-hardlinks.t --- a/tests/test-hardlinks.t +++ b/tests/test-hardlinks.t @@ -50,6 +50,8 @@ Prepare repo r1: 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 @@ Repos r1 and r2 should now contain hardl 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 @@ Repo r3 should not be hardlinked: 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 @@ Create a non-inlined filelog in r3: 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 @@ Push to repo r1 should break up most har 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 @@ Committing a change to f1 in r1 must bre 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 @@ r4 has hardlinks in the working dir (not 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 @@ Update back to revision 11 in r4 should 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 diff --git a/tests/test-hook.t b/tests/test-hook.t --- a/tests/test-hook.t +++ b/tests/test-hook.t @@ -158,6 +158,8 @@ more there after journal.phaseroots phaseroots undo + undo.backup.fncache + undo.backupfiles undo.phaseroots diff --git a/tests/test-inherit-mode.t b/tests/test-inherit-mode.t --- a/tests/test-inherit-mode.t +++ b/tests/test-inherit-mode.t @@ -81,6 +81,7 @@ new directories are setgid 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 @@ group can still write everything 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