# HG changeset patch # User Patrick Mezard # Date 2012-02-24 10:02:21 # Node ID 81a1a00f5738f40250fd6ac7d3dc563ca03bfd34 # Parent df5ecb813426641f2f8645e01b0fe676b1c39592 debugrevspec: pretty print output Before: ('func', ('symbol', 'reverse'), ('func', ('symbol', 'sort'), ('list', ('or', ('symbol', '2'), ('symbol', '3')), ('symbol', 'date')))) After: (func ('symbol', 'reverse') (func ('symbol', 'sort') (list (or ('symbol', '2') ('symbol', '3')) ('symbol', 'date')))) v2: - Rebased on stable to avoid having to merge tests output diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2161,10 +2161,10 @@ def debugrevspec(ui, repo, expr): """ if ui.verbose: tree = revset.parse(expr)[0] - ui.note(tree, "\n") + ui.note(revset.prettyformat(tree), "\n") newtree = revset.findaliases(ui, tree) if newtree != tree: - ui.note(newtree, "\n") + ui.note(revset.prettyformat(newtree), "\n") func = revset.match(ui, expr) for c in func(repo, range(len(repo))): ui.write("%s\n" % c) diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1319,5 +1319,20 @@ def formatspec(expr, *args): return ret +def prettyformat(tree): + def _prettyformat(tree, level, lines): + if not isinstance(tree, tuple) or tree[0] in ('string', 'symbol'): + lines.append((level, str(tree))) + else: + lines.append((level, '(%s' % tree[0])) + for s in tree[1:]: + _prettyformat(s, level + 1, lines) + lines[-1:] = [(lines[-1][0], lines[-1][1] + ')')] + + lines = [] + _prettyformat(tree, 0, lines) + output = '\n'.join((' '*l + s) for l, s in lines) + return output + # tell hggettext to extract docstrings from these functions: i18nfunctions = symbols.values() diff --git a/tests/test-revset-dirstate-parents.t b/tests/test-revset-dirstate-parents.t --- a/tests/test-revset-dirstate-parents.t +++ b/tests/test-revset-dirstate-parents.t @@ -13,11 +13,17 @@ $ cd repo $ try 'p1()' - ('func', ('symbol', 'p1'), None) + (func + ('symbol', 'p1') + None) $ try 'p2()' - ('func', ('symbol', 'p2'), None) + (func + ('symbol', 'p2') + None) $ try 'parents()' - ('func', ('symbol', 'parents'), None) + (func + ('symbol', 'parents') + None) null revision $ log 'p1()' diff --git a/tests/test-revset.t b/tests/test-revset.t --- a/tests/test-revset.t +++ b/tests/test-revset.t @@ -94,19 +94,25 @@ names that should work without quoting ('symbol', 'a') 0 $ try b-a - ('minus', ('symbol', 'b'), ('symbol', 'a')) + (minus + ('symbol', 'b') + ('symbol', 'a')) 1 $ try _a_b_c_ ('symbol', '_a_b_c_') 6 $ try _a_b_c_-a - ('minus', ('symbol', '_a_b_c_'), ('symbol', 'a')) + (minus + ('symbol', '_a_b_c_') + ('symbol', 'a')) 6 $ try .a.b.c. ('symbol', '.a.b.c.') 7 $ try .a.b.c.-a - ('minus', ('symbol', '.a.b.c.'), ('symbol', 'a')) + (minus + ('symbol', '.a.b.c.') + ('symbol', 'a')) 7 $ try -- '-a-b-c-' # complains hg: parse error at 7: not a prefix: end @@ -114,7 +120,15 @@ names that should work without quoting $ log -a-b-c- # succeeds with fallback 4 $ try -- -a-b-c--a # complains - ('minus', ('minus', ('minus', ('negate', ('symbol', 'a')), ('symbol', 'b')), ('symbol', 'c')), ('negate', ('symbol', 'a'))) + (minus + (minus + (minus + (negate + ('symbol', 'a')) + ('symbol', 'b')) + ('symbol', 'c')) + (negate + ('symbol', 'a'))) abort: unknown revision '-a'! [255] $ try é @@ -124,7 +138,9 @@ names that should work without quoting quoting needed $ try '"-a-b-c-"-a' - ('minus', ('string', '-a-b-c-'), ('symbol', 'a')) + (minus + ('string', '-a-b-c-') + ('symbol', 'a')) 4 $ log '1 or 2' @@ -136,15 +152,32 @@ quoting needed $ log '1 and 2' $ log '1&2' $ try '1&2|3' # precedence - and is higher - ('or', ('and', ('symbol', '1'), ('symbol', '2')), ('symbol', '3')) + (or + (and + ('symbol', '1') + ('symbol', '2')) + ('symbol', '3')) 3 $ try '1|2&3' - ('or', ('symbol', '1'), ('and', ('symbol', '2'), ('symbol', '3'))) + (or + ('symbol', '1') + (and + ('symbol', '2') + ('symbol', '3'))) 1 $ try '1&2&3' # associativity - ('and', ('and', ('symbol', '1'), ('symbol', '2')), ('symbol', '3')) + (and + (and + ('symbol', '1') + ('symbol', '2')) + ('symbol', '3')) $ try '1|(2|3)' - ('or', ('symbol', '1'), ('group', ('or', ('symbol', '2'), ('symbol', '3')))) + (or + ('symbol', '1') + (group + (or + ('symbol', '2') + ('symbol', '3')))) 1 2 3 @@ -226,13 +259,19 @@ quoting needed $ log 'grep("issue\d+")' 6 $ try 'grep("(")' # invalid regular expression - ('func', ('symbol', 'grep'), ('string', '(')) + (func + ('symbol', 'grep') + ('string', '(')) hg: parse error: invalid match pattern: unbalanced parenthesis [255] $ try 'grep("\bissue\d+")' - ('func', ('symbol', 'grep'), ('string', '\x08issue\\d+')) + (func + ('symbol', 'grep') + ('string', '\x08issue\\d+')) $ try 'grep(r"\bissue\d+")' - ('func', ('symbol', 'grep'), ('string', '\\bissue\\d+')) + (func + ('symbol', 'grep') + ('string', '\\bissue\\d+')) 6 $ try 'grep(r"\")' hg: parse error at 7: unterminated string @@ -437,14 +476,20 @@ aliases: $ try m ('symbol', 'm') - ('func', ('symbol', 'merge'), None) + (func + ('symbol', 'merge') + None) 6 test alias recursion $ try sincem ('symbol', 'sincem') - ('func', ('symbol', 'descendants'), ('func', ('symbol', 'merge'), None)) + (func + ('symbol', 'descendants') + (func + ('symbol', 'merge') + None)) 6 7 @@ -463,8 +508,16 @@ test nesting and variable passing $ echo 'nested2($1) = nested3($1)' >> .hg/hgrc $ echo 'nested3($1) = max($1)' >> .hg/hgrc $ try 'nested(2:5)' - ('func', ('symbol', 'nested'), ('range', ('symbol', '2'), ('symbol', '5'))) - ('func', ('symbol', 'max'), ('range', ('symbol', '2'), ('symbol', '5'))) + (func + ('symbol', 'nested') + (range + ('symbol', '2') + ('symbol', '5'))) + (func + ('symbol', 'max') + (range + ('symbol', '2') + ('symbol', '5'))) 5 test variable isolation, variable placeholders are rewritten as string @@ -474,38 +527,100 @@ far away. $ echo 'injectparamasstring = max("$1")' >> .hg/hgrc $ echo 'callinjection($1) = descendants(injectparamasstring)' >> .hg/hgrc $ try 'callinjection(2:5)' - ('func', ('symbol', 'callinjection'), ('range', ('symbol', '2'), ('symbol', '5'))) - ('func', ('symbol', 'descendants'), ('func', ('symbol', 'max'), ('string', '$1'))) + (func + ('symbol', 'callinjection') + (range + ('symbol', '2') + ('symbol', '5'))) + (func + ('symbol', 'descendants') + (func + ('symbol', 'max') + ('string', '$1'))) abort: unknown revision '$1'! [255] $ try 'd(2:5)' - ('func', ('symbol', 'd'), ('range', ('symbol', '2'), ('symbol', '5'))) - ('func', ('symbol', 'reverse'), ('func', ('symbol', 'sort'), ('list', ('range', ('symbol', '2'), ('symbol', '5')), ('symbol', 'date')))) + (func + ('symbol', 'd') + (range + ('symbol', '2') + ('symbol', '5'))) + (func + ('symbol', 'reverse') + (func + ('symbol', 'sort') + (list + (range + ('symbol', '2') + ('symbol', '5')) + ('symbol', 'date')))) 4 5 3 2 $ try 'rs(2 or 3, date)' - ('func', ('symbol', 'rs'), ('list', ('or', ('symbol', '2'), ('symbol', '3')), ('symbol', 'date'))) - ('func', ('symbol', 'reverse'), ('func', ('symbol', 'sort'), ('list', ('or', ('symbol', '2'), ('symbol', '3')), ('symbol', 'date')))) + (func + ('symbol', 'rs') + (list + (or + ('symbol', '2') + ('symbol', '3')) + ('symbol', 'date'))) + (func + ('symbol', 'reverse') + (func + ('symbol', 'sort') + (list + (or + ('symbol', '2') + ('symbol', '3')) + ('symbol', 'date')))) 3 2 $ try 'rs()' - ('func', ('symbol', 'rs'), None) + (func + ('symbol', 'rs') + None) hg: parse error: invalid number of arguments: 0 [255] $ try 'rs(2)' - ('func', ('symbol', 'rs'), ('symbol', '2')) + (func + ('symbol', 'rs') + ('symbol', '2')) hg: parse error: invalid number of arguments: 1 [255] $ try 'rs(2, data, 7)' - ('func', ('symbol', 'rs'), ('list', ('list', ('symbol', '2'), ('symbol', 'data')), ('symbol', '7'))) + (func + ('symbol', 'rs') + (list + (list + ('symbol', '2') + ('symbol', 'data')) + ('symbol', '7'))) hg: parse error: invalid number of arguments: 3 [255] $ try 'rs4(2 or 3, x, x, date)' - ('func', ('symbol', 'rs4'), ('list', ('list', ('list', ('or', ('symbol', '2'), ('symbol', '3')), ('symbol', 'x')), ('symbol', 'x')), ('symbol', 'date'))) - ('func', ('symbol', 'reverse'), ('func', ('symbol', 'sort'), ('list', ('or', ('symbol', '2'), ('symbol', '3')), ('symbol', 'date')))) + (func + ('symbol', 'rs4') + (list + (list + (list + (or + ('symbol', '2') + ('symbol', '3')) + ('symbol', 'x')) + ('symbol', 'x')) + ('symbol', 'date'))) + (func + ('symbol', 'reverse') + (func + ('symbol', 'sort') + (list + (or + ('symbol', '2') + ('symbol', '3')) + ('symbol', 'date')))) 3 2