##// END OF EJS Templates
transaction: add releasefn to notify the end of a transaction scope...
FUJIWARA Katsunori -
r26576:9e0aaac0 default
parent child Browse files
Show More
@@ -89,7 +89,7 b' def _playback(journal, report, opener, v'
89
89
90 class transaction(object):
90 class transaction(object):
91 def __init__(self, report, opener, vfsmap, journalname, undoname=None,
91 def __init__(self, report, opener, vfsmap, journalname, undoname=None,
92 after=None, createmode=None, validator=None):
92 after=None, createmode=None, validator=None, releasefn=None):
93 """Begin a new transaction
93 """Begin a new transaction
94
94
95 Begins a new transaction that allows rolling back writes in the event of
95 Begins a new transaction that allows rolling back writes in the event of
@@ -97,6 +97,7 b' class transaction(object):'
97
97
98 * `after`: called after the transaction has been committed
98 * `after`: called after the transaction has been committed
99 * `createmode`: the mode of the journal file that will be created
99 * `createmode`: the mode of the journal file that will be created
100 * `releasefn`: called after releasing (with transaction and result)
100 """
101 """
101 self.count = 1
102 self.count = 1
102 self.usages = 1
103 self.usages = 1
@@ -119,6 +120,11 b' class transaction(object):'
119 if validator is None:
120 if validator is None:
120 validator = lambda tr: None
121 validator = lambda tr: None
121 self.validator = validator
122 self.validator = validator
123 # A callback to do something just after releasing transaction.
124 if releasefn is None:
125 releasefn = lambda tr, success: None
126 self.releasefn = releasefn
127
122 # a dict of arguments to be passed to hooks
128 # a dict of arguments to be passed to hooks
123 self.hookargs = {}
129 self.hookargs = {}
124 self.file = opener.open(self.journal, "w")
130 self.file = opener.open(self.journal, "w")
@@ -442,6 +448,9 b' class transaction(object):'
442 % (vfs.join(b), inst))
448 % (vfs.join(b), inst))
443 self._backupentries = []
449 self._backupentries = []
444 self.journal = None
450 self.journal = None
451
452 self.releasefn(self, True) # notify success of closing transaction
453
445 # run post close action
454 # run post close action
446 categories = sorted(self._postclosecallback)
455 categories = sorted(self._postclosecallback)
447 for cat in categories:
456 for cat in categories:
@@ -506,7 +515,7 b' class transaction(object):'
506 self.report(_("rollback failed - please run hg recover\n"))
515 self.report(_("rollback failed - please run hg recover\n"))
507 finally:
516 finally:
508 self.journal = None
517 self.journal = None
509
518 self.releasefn(self, False) # notify failure of transaction
510
519
511 def rollback(opener, vfsmap, file, report):
520 def rollback(opener, vfsmap, file, report):
512 """Rolls back the transaction contained in the given file
521 """Rolls back the transaction contained in the given file
General Comments 0
You need to be logged in to leave comments. Login now