diff mercurial/changelog.py @ 28494:63653147e9bb

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sun, 06 Mar 2016 13:13:54 -0800
parents 7796473c11b3
children 70c2f8a98276
line wrap: on
line diff
--- a/mercurial/changelog.py	Sun Mar 06 14:31:06 2016 -0800
+++ b/mercurial/changelog.py	Sun Mar 06 13:13:54 2016 -0800
@@ -184,9 +184,6 @@
         #
         # 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]
 
@@ -198,10 +195,13 @@
 
         # 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