[PATCH 2 of 5] revsetlang: use str.find() to scan expr in formatspec()

Yuya Nishihara yuya at tcha.org
Sun Jan 7 01:31:52 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1491033328 -32400
#      Sat Apr 01 16:55:28 2017 +0900
# Node ID cac1c609a310d403b4d1acefac35aa86d871b608
# Parent  48cdc456784aa0e7a39f89f63f1d5142b20637d7
revsetlang: use str.find() to scan expr in formatspec()

There should be no need to walk character one by one in Python.

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -624,9 +624,13 @@ def formatspec(expr, *args):
     pos = 0
     arg = 0
     while pos < len(expr):
-        c = expr[pos]
-        if c == '%':
-            pos += 1
+        q = expr.find('%', pos)
+        if q < 0:
+            ret.append(expr[pos:])
+            break
+        ret.append(expr[pos:q])
+        pos = q + 1
+        if True:
             d = expr[pos]
             if d == '%':
                 ret.append(d)
@@ -642,8 +646,6 @@ def formatspec(expr, *args):
             else:
                 raise error.Abort(_('unexpected revspec format character %s')
                                   % d)
-        else:
-            ret.append(c)
         pos += 1
 
     return ''.join(ret)


More information about the Mercurial-devel mailing list