Mercurial > hg-stable
changeset 15140:353a1ba928f6
revset: add 'l' flag to formatspec for args
This makes it easy to calculate a revset with lists:
good = [1, 2, 3]
bad = [10, 11, 12]
between = repo.set('%ld::%ld', good, bad)
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Mon, 19 Sep 2011 16:28:44 -0500 |
parents | 0834e0bb445a |
children | 16dc9a32ca04 |
files | mercurial/revset.py |
diffstat | 1 files changed, 22 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revset.py Sun Sep 18 23:57:49 2011 +0200 +++ b/mercurial/revset.py Mon Sep 19 16:28:44 2011 -0500 @@ -1059,6 +1059,8 @@ %n = hex(arg), single-quoted %% = a literal '%' + Prefixing the type with 'l' specifies a list of that type. + >>> formatspec('%d:: and not %d::', 10, 20) '10:: and not 20::' >>> formatspec('keyword(%s)', 'foo\\xe9') @@ -1067,11 +1069,23 @@ >>> b.branch = b >>> formatspec('branch(%b)', b) "branch('default')" + >>> formatspec('root(%ls)', ['a', 'b', 'c', 'd']) + "root(('a' or 'b' or 'c' or 'd'))" ''' def quote(s): return repr(str(s)) + def argtype(c, arg): + if c == 'd': + return str(int(arg)) + elif c == 's': + return quote(arg) + elif c == 'n': + return quote(node.hex(arg)) + elif c == 'b': + return quote(arg.branch()) + ret = '' pos = 0 arg = 0 @@ -1082,17 +1096,15 @@ d = expr[pos] if d == '%': ret += d - elif d == 'd': - ret += str(int(args[arg])) - arg += 1 - elif d == 's': - ret += quote(args[arg]) + elif d in 'dsnb': + ret += argtype(d, args[arg]) arg += 1 - elif d == 'n': - ret += quote(node.hex(args[arg])) - arg += 1 - elif d == 'b': - ret += quote(args[arg].branch()) + elif d == 'l': + # a list of some type + pos += 1 + d = expr[pos] + lv = ' or '.join(argtype(d, e) for e in args[arg]) + ret += '(%s)' % lv arg += 1 else: raise util.Abort('unexpected revspec format character %s' % d)