Patchwork [4,of,5] revsetlang: use iterator to track current argument in formatspec()

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

Comments

Yuya Nishihara - Jan. 7, 2018, 6:31 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1491033889 -32400
#      Sat Apr 01 17:04:49 2017 +0900
# Node ID 235156e876401ee955e2db5b4cc1bae17f39e3f5
# Parent  11003d3f4751eb00f04c43bbeed25fe044a3db87
revsetlang: use iterator to track current argument in formatspec()

Patch

diff --git a/mercurial/revsetlang.py b/mercurial/revsetlang.py
--- a/mercurial/revsetlang.py
+++ b/mercurial/revsetlang.py
@@ -620,9 +620,9 @@  def formatspec(expr, *args):
         return '(%s or %s)' % (listexp(s[:m], t), listexp(s[m:], t))
 
     expr = pycompat.bytestr(expr)
+    argiter = iter(args)
     ret = []
     pos = 0
-    arg = 0
     while pos < len(expr):
         q = expr.find('%', pos)
         if q < 0:
@@ -634,14 +634,12 @@  def formatspec(expr, *args):
         if d == '%':
             ret.append(d)
         elif d in 'dsnbr':
-            ret.append(argtype(d, args[arg]))
-            arg += 1
+            ret.append(argtype(d, next(argiter)))
         elif d == 'l':
             # a list of some type
             pos += 1
             d = expr[pos]
-            ret.append(listexp(list(args[arg]), d))
-            arg += 1
+            ret.append(listexp(list(next(argiter)), d))
         else:
             raise error.Abort(_('unexpected revspec format character %s') % d)
         pos += 1