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

mail settings
Submitter Gregory Szorc
Date July 15, 2015, 10:32 p.m.
Message ID <ed5d4ffdff877bfe6323.1436999527@gps-mbp.local>
Download mbox | patch
Permalink /patch/9994/
State Changes Requested
Headers show


Gregory Szorc - July 15, 2015, 10:32 p.m.
# HG changeset patch
# User Gregory Szorc <>
# 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/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -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