# HG changeset patch # User Matt Mackall # Date 2011-09-19 21:28:44 # Node ID 353a1ba928f682a0a3e29bf54b90c7cdc2f98fef # Parent 0834e0bb445a0f384d362e909857cb77dd5c6a9c 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) diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1059,6 +1059,8 @@ def formatspec(expr, *args): %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 @@ def formatspec(expr, *args): >>> 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 @@ def formatspec(expr, *args): 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)