changeset 16218:81a1a00f5738

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
author Patrick Mezard <patrick@mezard.eu>
date Fri, 24 Feb 2012 11:02:21 +0100
parents df5ecb813426
children 4fc9fcd991c1
files mercurial/commands.py mercurial/revset.py tests/test-revset-dirstate-parents.t tests/test-revset.t
diffstat 4 files changed, 168 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Mar 02 21:43:55 2012 +0200
+++ b/mercurial/commands.py	Fri Feb 24 11:02:21 2012 +0100
@@ -2161,10 +2161,10 @@
     """
     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)
--- a/mercurial/revset.py	Fri Mar 02 21:43:55 2012 +0200
+++ b/mercurial/revset.py	Fri Feb 24 11:02:21 2012 +0100
@@ -1319,5 +1319,20 @@
 
     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()
--- a/tests/test-revset-dirstate-parents.t	Fri Mar 02 21:43:55 2012 +0200
+++ b/tests/test-revset-dirstate-parents.t	Fri Feb 24 11:02:21 2012 +0100
@@ -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()'
--- a/tests/test-revset.t	Fri Mar 02 21:43:55 2012 +0200
+++ b/tests/test-revset.t	Fri Feb 24 11:02:21 2012 +0100
@@ -94,19 +94,25 @@
   ('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 @@
   $ 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 @@
 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 @@
   $ 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 @@
   $ 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 @@
 
   $ 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 @@
   $ 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 @@
   $ 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