[PATCH STABLE v2] debugrevspec: pretty print output
Patrick Mezard
patrick at mezard.eu
Fri Feb 24 10:03:42 UTC 2012
# HG changeset patch
# User Patrick Mezard <patrick at mezard.eu>
# Date 1330077741 -3600
# Branch stable
# Node ID d78004a769e8f6b6283b5430684d4a99f80e9d12
# Parent 616c2e278f18984dc48b80bc56b55da626130709
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
@@ -2157,10 +2157,10 @@
'''parse and apply a revision specification'''
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
@@ -1221,5 +1221,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()
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 @@
('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
@@ -436,35 +475,91 @@
$ try m
('symbol', 'm')
- ('func', ('symbol', 'merge'), None)
+ (func
+ ('symbol', 'merge')
+ None)
6
$ 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
More information about the Mercurial-devel
mailing list