Mercurial > hg-stable
changeset 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 | 7e97bf6ee2d6 |
children | 3872d563e01a |
files | mercurial/transaction.py |
diffstat | 1 files changed, 24 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/transaction.py Sat Oct 18 01:12:18 2014 -0700 +++ b/mercurial/transaction.py Fri Oct 17 21:19:54 2014 -0700 @@ -101,6 +101,10 @@ # hold file generations to be performed on commit self._filegenerators = {} + # hold callbalk to write pending data for hooks + self._pendingcallback = {} + # True is any pending data have been written ever + self._anypending = False def __del__(self): if self.journal: @@ -263,6 +267,26 @@ def running(self): return self.count > 0 + def addpending(self, category, callback): + """add a callback to be called when the transaction is pending + + Category is a unique identifier to allow overwriting an old callback + with a newer callback. + """ + self._pendingcallback[category] = callback + + @active + def writepending(self): + '''write pending file to temporary version + + This is used to allow hooks to view a transaction before commit''' + categories = sorted(self._pendingcallback) + for cat in categories: + # remove callback since the data will have been flushed + any = self._pendingcallback.pop(cat)() + self._anypending = self._anypending or any + return self._anypending + @active def close(self): '''commit the transaction'''