[PATCH 1 of 2 V3] revlog: add support for a callback whenever revisions are added

Gregory Szorc gregory.szorc at gmail.com
Sat Jul 18 18:08:17 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1437240577 25200
#      Sat Jul 18 10:29:37 2015 -0700
# Node ID 3319a574de6de4ee19183bafa3c0d31f78211a7d
# Parent  584044e5ad571c3b4f2f9c2f6201917fd369b1f9
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 --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1378,15 +1378,18 @@ class revlog(object):
             ifh.write(data[0])
             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
         content = []
@@ -1458,8 +1461,16 @@ class revlog(object):
 
                 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
                     ifh.close()


More information about the Mercurial-devel mailing list