# HG changeset patch # User Gregory Szorc # Date 1437240577 25200 # Node ID 00e3f909907f2f02a7661caf515560d80c2ad3e1 # Parent d68544b69736acc8674563c6bde7d1717f316c3d 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. diff -r d68544b69736 -r 00e3f909907f mercurial/revlog.py --- 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