Patchwork [5,of,5] fileset: pretty print syntax tree in debug output

login
register
mail settings
Submitter Yuya Nishihara
Date May 22, 2015, 2:11 p.m.
Message ID <b20af4c65c86115ada63.1432303908@mimosa>
Download mbox | patch
Permalink /patch/9239/
State Accepted
Headers show

Comments

Yuya Nishihara - May 22, 2015, 2:11 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1430054804 -32400
#      Sun Apr 26 22:26:44 2015 +0900
# Node ID b20af4c65c86115ada63ebc011d985c514aaba80
# Parent  e8998439901c3ed2ffe9cf22022f1f1f0d984be9
fileset: pretty print syntax tree in debug output
Pierre-Yves David - May 22, 2015, 9:11 p.m.
On 05/22/2015 09:11 AM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1430054804 -32400
> #      Sun Apr 26 22:26:44 2015 +0900
> # Node ID b20af4c65c86115ada63ebc011d985c514aaba80
> # Parent  e8998439901c3ed2ffe9cf22022f1f1f0d984be9
> fileset: pretty print syntax tree in debug output

This sounds reasonable and have been pushed to the clowncopter.

I'm not so familliar with this part of the code so I'm CC Matt expecting 
him to have a closer look when validating the clowcopter.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2165,7 +2165,7 @@  def debugfileset(ui, repo, expr, **opts)
     ctx = scmutil.revsingle(repo, opts.get('rev'), None)
     if ui.verbose:
         tree = fileset.parse(expr)
-        ui.note(tree, "\n")
+        ui.note(fileset.prettyformat(tree), "\n")
 
     for f in ctx.getfileset(expr):
         ui.write("%s\n" % f)
diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -517,5 +517,8 @@  def getfileset(ctx, expr):
 
     return getset(matchctx(ctx, subset, status), tree)
 
+def prettyformat(tree):
+    return parser.prettyformat(tree, ('string', 'symbol'))
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()
diff --git a/tests/test-fileset.t b/tests/test-fileset.t
--- a/tests/test-fileset.t
+++ b/tests/test-fileset.t
@@ -16,15 +16,21 @@ 
 
 Test operators and basic patterns
 
-  $ fileset a1
+  $ fileset -v a1
+  ('symbol', 'a1')
   a1
-  $ fileset 'a*'
+  $ fileset -v 'a*'
+  ('symbol', 'a*')
   a1
   a2
-  $ fileset '"re:a\d"'
+  $ fileset -v '"re:a\d"'
+  ('string', 're:a\\d')
   a1
   a2
-  $ fileset 'a1 or a2'
+  $ fileset -v 'a1 or a2'
+  (or
+    ('symbol', 'a1')
+    ('symbol', 'a2'))
   a1
   a2
   $ fileset 'a1 | a2'