[PATCH 08 of 10 lazy-changelog-parse] changelog: parse description last

Gregory Szorc gregory.szorc at gmail.com
Sun Mar 6 18:58:54 EST 2016


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1457298834 28800
#      Sun Mar 06 13:13:54 2016 -0800
# Node ID 6f9345c743c024c50c634f6cb54d2dd892dc2792
# Parent  e37bac9adf9215f82850e7b105e3e47e1bee3d7a
changelog: parse description last

Before, we first searched for the double newline as the first step in
the parse then moved to the front of the string and worked our way
to the back again. This made sense when we were splitting the raw
text on the double newline. But in our new newline scanning based
approach, this feels awkward.

This patch updates the parsing logic to parse the text linearly and
deal with the description field last.

Because we're avoiding an extra string scan, revsets appear to
demonstrate a very slight performance win. But the percentage
change is marginal, so the numbers aren't worth reporting.

diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -179,34 +179,34 @@ class changelogrevision(object):
         # time tz extra\n : date (time is int or float, timezone is int)
         #                 : extra is metadata, encoded and separated by '\0'
         #                 : older versions ignore it
         # files\n\n       : files modified by the cset, no \n or \r allowed
         # (.*)            : comment (free text, ideally utf-8)
         #
         # changelog v0 doesn't use extra
 
-        doublenl = text.index('\n\n')
-        self._rawdesc = text[doublenl + 2:]
-
         nl1 = text.index('\n')
         self._rawmanifest = text[0:nl1]
 
         nl2 = text.index('\n', nl1 + 1)
         self._rawuser = text[nl1 + 1:nl2]
 
         nl3 = text.index('\n', nl2 + 1)
         self._rawdateextra = text[nl2 + 1:nl3]
 
         # The list of files may be empty. Which means nl3 is the first of the
         # double newline that precedes the description.
-        if nl3 == doublenl:
+        if text[nl3 + 1] == '\n':
             self._rawfiles = None
+            self._rawdesc = text[nl3 + 2:]
         else:
+            doublenl = text.index('\n\n', nl3 + 1)
             self._rawfiles = text[nl3 + 1:doublenl]
+            self._rawdesc = text[doublenl + 2:]
 
         return self
 
     @property
     def manifest(self):
         return bin(self._rawmanifest)
 
     @property


More information about the Mercurial-devel mailing list