debugfileset: backport --show-stage option from debugrevspec
authorYuya Nishihara <yuya@tcha.org>
Sat, 21 Jul 2018 14:52:36 +0900
changeset 38801 1d1c1645d7b9
parent 38800 7790cd70842a
child 38802 f0a574dbfae9
debugfileset: backport --show-stage option from debugrevspec I'll add some static optimizations to fileset.
mercurial/debugcommands.py
tests/test-completion.t
tests/test-fileset.t
--- a/mercurial/debugcommands.py	Sun Jul 22 16:03:48 2018 +0900
+++ b/mercurial/debugcommands.py	Sat Jul 21 14:52:36 2018 +0900
@@ -888,15 +888,39 @@
 @command('debugfileset',
     [('r', 'rev', '', _('apply the filespec on this revision'), _('REV')),
      ('', 'all-files', False,
-      _('test files from all revisions and working directory'))],
-    _('[-r REV] [--all-files] FILESPEC'))
+      _('test files from all revisions and working directory')),
+     ('p', 'show-stage', [],
+      _('print parsed tree at the given stage'), _('NAME'))],
+    _('[-r REV] [--all-files] [OPTION]... FILESPEC'))
 def debugfileset(ui, repo, expr, **opts):
     '''parse and apply a fileset specification'''
     opts = pycompat.byteskwargs(opts)
     ctx = scmutil.revsingle(repo, opts.get('rev'), None)
-    if ui.verbose:
-        tree = fileset.parse(expr)
-        ui.note(fileset.prettyformat(tree), "\n")
+
+    stages = [
+        ('parsed', pycompat.identity),
+    ]
+    stagenames = set(n for n, f in stages)
+
+    showalways = set()
+    if ui.verbose and not opts['show_stage']:
+        # show parsed tree by --verbose (deprecated)
+        showalways.add('parsed')
+    if opts['show_stage'] == ['all']:
+        showalways.update(stagenames)
+    else:
+        for n in opts['show_stage']:
+            if n not in stagenames:
+                raise error.Abort(_('invalid stage name: %s') % n)
+        showalways.update(opts['show_stage'])
+
+    tree = fileset.parse(expr)
+    for n, f in stages:
+        tree = f(tree)
+        if n in showalways:
+            if opts['show_stage'] or n != 'parsed':
+                ui.write(("* %s:\n") % n)
+            ui.write(fileset.prettyformat(tree), "\n")
 
     files = set()
     if opts['all_files']:
--- a/tests/test-completion.t	Sun Jul 22 16:03:48 2018 +0900
+++ b/tests/test-completion.t	Sat Jul 21 14:52:36 2018 +0900
@@ -274,7 +274,7 @@
   debugdiscovery: old, nonheads, rev, ssh, remotecmd, insecure
   debugdownload: output
   debugextensions: template
-  debugfileset: rev, all-files
+  debugfileset: rev, all-files, show-stage
   debugformat: template
   debugfsinfo: 
   debuggetbundle: head, common, type
--- a/tests/test-fileset.t	Sun Jul 22 16:03:48 2018 +0900
+++ b/tests/test-fileset.t	Sat Jul 21 14:52:36 2018 +0900
@@ -114,6 +114,44 @@
   hg: parse error: invalid pattern kind: foo
   [255]
 
+Show parsed tree at stages:
+
+  $ fileset -p unknown a
+  abort: invalid stage name: unknown
+  [255]
+
+  $ fileset -p parsed 'path:a1 or glob:b?'
+  * parsed:
+  (or
+    (kindpat
+      (symbol 'path')
+      (symbol 'a1'))
+    (kindpat
+      (symbol 'glob')
+      (symbol 'b?')))
+  a1
+  b1
+  b2
+
+  $ fileset -p all 'a1 or a2 or (grep("b") & clean())'
+  * parsed:
+  (or
+    (or
+      (symbol 'a1')
+      (symbol 'a2'))
+    (group
+      (and
+        (func
+          (symbol 'grep')
+          (string 'b'))
+        (func
+          (symbol 'clean')
+          None))))
+  a1
+  a2
+  b1
+  b2
+
 Test files status
 
   $ rm a1