[PATCH 4 of 5 V2] changelog: pass full changelog entry to addrevisioncb

Gregory Szorc gregory.szorc at gmail.com
Wed Jul 15 17:32:07 CDT 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1436997598 25200
#      Wed Jul 15 14:59:58 2015 -0700
# Node ID ed5d4ffdff877bfe632376a17a5a50cece817209
# Parent  3c13ae7f08b610bb5ff0e7aba3a3e35d0369983c
changelog: pass full changelog entry to addrevisioncb

The initial use case for addrevisioncb feature (see the next patch)
needs to compute something beyond just the added node value. This patch
modifies the behavior of addrevisioncb on the changelog to pass the full
changelog entry as opposed to just the node.

While we did introduce an extra function call to adding changelog
entries, measurements reveal no measureable impact to mozilla-central
unbundle times. My guess is the function call overhead is dominated by
the time spent handling over 1 GB of data and over 200,000 changesets.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -385,8 +385,24 @@ class changelog(revlog.revlog):
         l = [hex(manifest), user, parseddate] + sorted(files) + ["", desc]
         text = "\n".join(l)
         return self.addrevision(text, transaction, len(self), p1, p2)
 
+    def _addrevision(self, *args, **kwargs):
+        # Wraps default implementation to pass full object to addrevisioncb.
+        #
+        # We have separate calls to _addrevision because we want to avoid
+        # calculating returntext unless it is requested, since calculating it
+        # isn't free.
+        addrevisioncb = kwargs.get('addrevisioncb')
+        if addrevisioncb:
+            del kwargs['addrevisioncb']
+            node, text = super(changelog, self)._addrevision(returntext=True,
+                                                             *args, **kwargs)
+            addrevisioncb(self, self._newchangelog(text))
+            return node
+        else:
+            return super(changelog, self)._addrevision(*args, **kwargs)
+
     def branchinfo(self, rev):
         """return the branch name and open/close state of a revision
 
         This function exists because creating a changectx object


More information about the Mercurial-devel mailing list