##// END OF EJS Templates
transaction: add functionality to have multiple validators...
Pulkit Goyal -
r45031:36f08ae8 default
parent child Browse files
Show More
@@ -165,12 +165,6 b' class transaction(util.transactional):'
165 165 self._journal = journalname
166 166 self._undoname = undoname
167 167 self._queue = []
168 # A callback to validate transaction content before closing it.
169 # should raise exception is anything is wrong.
170 # target user is repository hooks.
171 if validator is None:
172 validator = lambda tr: None
173 self._validator = validator
174 168 # A callback to do something just after releasing transaction.
175 169 if releasefn is None:
176 170 releasefn = lambda tr, success: None
@@ -214,6 +208,11 b' class transaction(util.transactional):'
214 208 self._anypending = False
215 209 # holds callback to call when writing the transaction
216 210 self._finalizecallback = {}
211 # holds callback to call when validating the transaction
212 # should raise exception if anything is wrong
213 self._validatecallback = {}
214 if validator is not None:
215 self._validatecallback[b'001-userhooks'] = validator
217 216 # hold callback for post transaction close
218 217 self._postclosecallback = {}
219 218 # holds callbacks to call during abort
@@ -506,11 +505,21 b' class transaction(util.transactional):'
506 505 self._abortcallback[category] = callback
507 506
508 507 @active
508 def addvalidator(self, category, callback):
509 """ adds a callback to be called when validating the transaction.
510
511 The transaction will be given as the first argument to the callback.
512
513 callback should raise exception if to abort transaction """
514 self._validatecallback[category] = callback
515
516 @active
509 517 def close(self):
510 518 '''commit the transaction'''
511 519 if self._count == 1:
512 self._validator(self) # will raise exception if needed
513 self._validator = None # Help prevent cycles.
520 for category in sorted(self._validatecallback):
521 self._validatecallback[category](self)
522 self._validatecallback = None # Help prevent cycles.
514 523 self._generatefiles(group=GEN_GROUP_PRE_FINALIZE)
515 524 while self._finalizecallback:
516 525 callbacks = self._finalizecallback
General Comments 0
You need to be logged in to leave comments. Login now