Show More
@@ -165,12 +165,6 b' class transaction(util.transactional):' | |||||
165 | self._journal = journalname |
|
165 | self._journal = journalname | |
166 | self._undoname = undoname |
|
166 | self._undoname = undoname | |
167 | self._queue = [] |
|
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 | # A callback to do something just after releasing transaction. |
|
168 | # A callback to do something just after releasing transaction. | |
175 | if releasefn is None: |
|
169 | if releasefn is None: | |
176 | releasefn = lambda tr, success: None |
|
170 | releasefn = lambda tr, success: None | |
@@ -214,6 +208,11 b' class transaction(util.transactional):' | |||||
214 | self._anypending = False |
|
208 | self._anypending = False | |
215 | # holds callback to call when writing the transaction |
|
209 | # holds callback to call when writing the transaction | |
216 | self._finalizecallback = {} |
|
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 | # hold callback for post transaction close |
|
216 | # hold callback for post transaction close | |
218 | self._postclosecallback = {} |
|
217 | self._postclosecallback = {} | |
219 | # holds callbacks to call during abort |
|
218 | # holds callbacks to call during abort | |
@@ -506,11 +505,21 b' class transaction(util.transactional):' | |||||
506 | self._abortcallback[category] = callback |
|
505 | self._abortcallback[category] = callback | |
507 |
|
506 | |||
508 | @active |
|
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 | def close(self): |
|
517 | def close(self): | |
510 | '''commit the transaction''' |
|
518 | '''commit the transaction''' | |
511 | if self._count == 1: |
|
519 | if self._count == 1: | |
512 | self._validator(self) # will raise exception if needed |
|
520 | for category in sorted(self._validatecallback): | |
513 | self._validator = None # Help prevent cycles. |
|
521 | self._validatecallback[category](self) | |
|
522 | self._validatecallback = None # Help prevent cycles. | |||
514 | self._generatefiles(group=GEN_GROUP_PRE_FINALIZE) |
|
523 | self._generatefiles(group=GEN_GROUP_PRE_FINALIZE) | |
515 | while self._finalizecallback: |
|
524 | while self._finalizecallback: | |
516 | callbacks = self._finalizecallback |
|
525 | callbacks = self._finalizecallback |
General Comments 0
You need to be logged in to leave comments.
Login now