Mercurial > hg
comparison mercurial/transaction.py @ 23202:ea5af863fbff
transaction: add 'writepending' logic
The contents of the transaction must be flushed to disk before running
a hook. But it must be flushed to a special file so that the normal
reader does not use it. This logic is currently in the changelog only.
We add some facility to register such operations in the transaction
itself.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 17 Oct 2014 21:19:54 -0700 |
parents | 29bfa964d6d8 |
children | 10beda5bd2b7 |
comparison
equal
deleted
inserted
replaced
23201:7e97bf6ee2d6 | 23202:ea5af863fbff |
---|---|
99 opener.chmod(self.journal, createmode & 0666) | 99 opener.chmod(self.journal, createmode & 0666) |
100 opener.chmod(self.backupjournal, createmode & 0666) | 100 opener.chmod(self.backupjournal, createmode & 0666) |
101 | 101 |
102 # hold file generations to be performed on commit | 102 # hold file generations to be performed on commit |
103 self._filegenerators = {} | 103 self._filegenerators = {} |
104 # hold callbalk to write pending data for hooks | |
105 self._pendingcallback = {} | |
106 # True is any pending data have been written ever | |
107 self._anypending = False | |
104 | 108 |
105 def __del__(self): | 109 def __del__(self): |
106 if self.journal: | 110 if self.journal: |
107 self._abort() | 111 self._abort() |
108 | 112 |
261 self._abort() | 265 self._abort() |
262 | 266 |
263 def running(self): | 267 def running(self): |
264 return self.count > 0 | 268 return self.count > 0 |
265 | 269 |
270 def addpending(self, category, callback): | |
271 """add a callback to be called when the transaction is pending | |
272 | |
273 Category is a unique identifier to allow overwriting an old callback | |
274 with a newer callback. | |
275 """ | |
276 self._pendingcallback[category] = callback | |
277 | |
278 @active | |
279 def writepending(self): | |
280 '''write pending file to temporary version | |
281 | |
282 This is used to allow hooks to view a transaction before commit''' | |
283 categories = sorted(self._pendingcallback) | |
284 for cat in categories: | |
285 # remove callback since the data will have been flushed | |
286 any = self._pendingcallback.pop(cat)() | |
287 self._anypending = self._anypending or any | |
288 return self._anypending | |
289 | |
266 @active | 290 @active |
267 def close(self): | 291 def close(self): |
268 '''commit the transaction''' | 292 '''commit the transaction''' |
269 if self.count == 1 and self.onclose is not None: | 293 if self.count == 1 and self.onclose is not None: |
270 self._generatefiles() | 294 self._generatefiles() |