Comments
Patch
@@ -85,8 +85,9 @@ class transaction(object):
self.map = {}
self.backupmap = {}
self.journal = journal
self._queue = []
+ self._chained = []
# a dict of arguments to be passed to hooks
self.hookargs = {}
self.backupjournal = "%s.backupfiles" % journal
@@ -172,8 +173,24 @@ class transaction(object):
self.backupsfile.write("%s\0%s\0" % (file, backupfile))
self.backupsfile.flush()
@active
+ def chaintransaction(self, tr):
+ """Chains another transaction to this one.
+
+ Sometimes it is desirable to have multiple simultaneous transactions
+ with mutually exclusive stores/vfss. This function allows you to
+ chain/associate another transaction with this one. Transaction
+ terminating actions such as close and abort will be applied to chained
+ transactions as well. This makes calling logic interfacing with
+ multiple transaction easier to manage.
+
+ Operations on chained transactions will be performed after they are
+ performed on this transaction.
+ """
+ self._chained.append(tr)
+
+ @active
def find(self, file):
if file in self.map:
return self.entries[self.map[file]]
if file in self.backupmap:
@@ -232,8 +249,11 @@ class transaction(object):
self.opener.unlink(b)
self.backupentries = []
self.journal = None
+ for tr in self._chained:
+ tr.close()
+
@active
def abort(self):
'''abort the transaction (generally called on error, or when the
transaction is not explicitly committed before going out of
@@ -261,8 +281,11 @@ class transaction(object):
try:
_playback(self.journal, self.report, self.opener,
self.entries, self.backupentries, False)
+ for tr in self._chained:
+ tr._abort()
+
self.report(_("rollback completed\n"))
except Exception:
self.report(_("rollback failed - please run hg recover\n"))
finally: