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

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 7, 2018, 6:31 a.m.
Message ID <cac1c609a310d403b4d1.1515306712@mimosa>
Download mbox | patch
Permalink /patch/26595/
State Accepted
Headers show

Comments

Yuya Nishihara - Jan. 7, 2018, 6:31 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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)