Mercurial > hg-stable
changeset 25822:00e3f909907f
revlog: add support for a callback whenever revisions are added
A subsequent patch will add a feature that performs iterative
computation as changesets are added from a changegroup. To facilitate
this type of processing in a generic manner, we add a mechanism for
calling a function whenever a revision is added via revlog.addgroup().
There are potential performance concerns with this callback, as using it
will flush the revlog after every revision is added.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 18 Jul 2015 10:29:37 -0700 |
parents | d68544b69736 |
children | 2406e2baa937 |
files | mercurial/revlog.py |
diffstat | 1 files changed, 12 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revlog.py Fri Jul 17 13:44:01 2015 -0700 +++ b/mercurial/revlog.py Sat Jul 18 10:29:37 2015 -0700 @@ -1379,13 +1379,16 @@ ifh.write(data[1]) self.checkinlinesize(transaction, ifh) - def addgroup(self, bundle, linkmapper, transaction): + def addgroup(self, bundle, linkmapper, transaction, addrevisioncb=None): """ add a delta group given a set of deltas, add them to the revision log. the first delta is against its parent, which should be in our log, the rest are against the previous delta. + + If ``addrevisioncb`` is defined, it will be called with arguments of + this revlog and the node that was added. """ # track the base of the current delta log @@ -1459,6 +1462,14 @@ chain = self._addrevision(node, None, transaction, link, p1, p2, flags, (baserev, delta), ifh, dfh) + + if addrevisioncb: + # Data for added revision can't be read unless flushed + # because _loadchunk always opensa new file handle and + # there is no guarantee data was actually written yet. + flush() + addrevisioncb(self, chain) + if not dfh and not self._inline: # addrevision switched from inline to conventional # reopen the index