[PATCH 2 of 5 V2] changelog: extract changelog parsing into standalone function

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


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1436996427 25200
#      Wed Jul 15 14:40:27 2015 -0700
# Node ID 8510f2a1d3b2ec3231391dc0cf9a865b696a22cb
# Parent  dc1a29f5daaabb76257b2862d3c55818cf644800
changelog: extract changelog parsing into standalone function

An upcoming patch will introduce an additional consumer for parsing
raw revision content into a changelog data structure. We refactor the
common code for parsing raw data into a standalone function.

A downside of this refactor is an extra function call is introduced.
However, revsetbenchmark.py doesn't seem to indicate any significant
change in performance. There are reported changes, but very similar
revsets are both faster and slower, so I think the differences are a
result of expected variations. Someone else may want to test this before
landing, just to be sure. If this extra function call really does
regress performance, we're probably at the performance level where we
should consider implementing changeset parsing in C.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -307,9 +307,14 @@ class changelog(revlog.revlog):
         if not self._delayed:
             revlog.revlog.checkinlinesize(self, tr, fp)
 
     def read(self, node):
+        return self._newchangelog(self.revision(node))
+
+    def _newchangelog(self, text):
         """
+        Parse raw revision content into a tuple.
+
         format used:
         nodeid\n        : manifest node in ascii
         user\n          : user, no \n or \r allowed
         time tz extra\n : date (time is int or float, timezone is int)
@@ -319,9 +324,8 @@ class changelog(revlog.revlog):
         (.*)            : comment (free text, ideally utf-8)
 
         changelog v0 doesn't use extra
         """
-        text = self.revision(node)
         if not text:
             return (nullid, "", (0, 0), [], "", _defaultextra)
         last = text.index("\n\n")
         desc = encoding.tolocal(text[last + 2:])


More information about the Mercurial-devel mailing list