[PATCH 3 of 5] parser: move prettyformat() function from revset module
Yuya Nishihara
yuya at tcha.org
Fri May 22 14:11:46 UTC 2015
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1430054403 -32400
# Sun Apr 26 22:20:03 2015 +0900
# Node ID a903a8ec32f1191b94077de850384f2eb8771f07
# Parent 82c474fa3f0e744f8fe63a00c9657c6998886cd5
parser: move prettyformat() function from revset module
I want to use it in doctests that I'll add by future patches. Also, it can
be used in "hg debugfileset" command.
diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -93,3 +93,18 @@ class parser(object):
if self._methods:
return self.eval(t)
return t
+
+def prettyformat(tree, leafnodes):
+ def _prettyformat(tree, level, lines):
+ if not isinstance(tree, tuple) or tree[0] in leafnodes:
+ 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
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2635,19 +2635,7 @@ 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
+ return parser.prettyformat(tree, ('string', 'symbol'))
def depth(tree):
if isinstance(tree, tuple):
More information about the Mercurial-devel
mailing list