changeset 41220:8d26026b3335

revert: extract "%ld" formatting in a _formatintlist function We'll have to reuse this logic in different places.
author Boris Feld <boris.feld@octobus.net>
date Fri, 04 Jan 2019 05:16:57 +0100
parents e5b227f41e4a
children 73203cdfe3fe
files mercurial/revsetlang.py
diffstat 1 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revsetlang.py	Fri Jan 04 02:29:04 2019 +0100
+++ b/mercurial/revsetlang.py	Fri Jan 04 05:16:57 2019 +0100
@@ -607,7 +607,7 @@
     elif l == 1:
         return _formatargtype(t, s[0])
     elif t == 'd':
-        return "_intlist('%s')" % "\0".join('%d' % int(a) for a in s)
+        return _formatintlist(s)
     elif t == 's':
         return "_list(%s)" % _quote("\0".join(s))
     elif t == 'n':
@@ -621,6 +621,17 @@
     m = l // 2
     return '(%s or %s)' % (_formatlistexp(s[:m], t), _formatlistexp(s[m:], t))
 
+def _formatintlist(data):
+    try:
+        l = len(data)
+        if l == 0:
+            return "_list('')"
+        elif l == 1:
+            return _formatargtype('d', data[0])
+        return "_intlist('%s')" % "\0".join('%d' % int(a) for a in data)
+    except (TypeError, ValueError):
+        raise error.ParseError(_('invalid argument for revspec'))
+
 def _formatparamexp(args, t):
     return ', '.join(_formatargtype(t, a) for a in args)