debugfileset: add option to show matcher representation
authorYuya Nishihara <yuya@tcha.org>
Sat, 21 Jul 2018 15:05:40 +0900
changeset 38802 f0a574dbfae9
parent 38801 1d1c1645d7b9
child 38803 4dc498d61d86
debugfileset: add option to show matcher representation
mercurial/debugcommands.py
tests/test-completion.t
tests/test-fileset.t
--- a/mercurial/debugcommands.py	Sat Jul 21 14:52:36 2018 +0900
+++ b/mercurial/debugcommands.py	Sat Jul 21 15:05:40 2018 +0900
@@ -889,6 +889,8 @@
     [('r', 'rev', '', _('apply the filespec on this revision'), _('REV')),
      ('', 'all-files', False,
       _('test files from all revisions and working directory')),
+     ('s', 'show-matcher', None,
+      _('print internal representation of matcher')),
      ('p', 'show-stage', [],
       _('print parsed tree at the given stage'), _('NAME'))],
     _('[-r REV] [--all-files] [OPTION]... FILESPEC'))
@@ -939,6 +941,8 @@
         files.update(ctx.substate)
 
     m = ctx.matchfileset(expr)
+    if opts['show_matcher'] or (opts['show_matcher'] is None and ui.verbose):
+        ui.write(('* matcher:\n'), stringutil.prettyrepr(m), '\n')
     for f in sorted(files):
         if not m(f):
             continue
--- a/tests/test-completion.t	Sat Jul 21 14:52:36 2018 +0900
+++ b/tests/test-completion.t	Sat Jul 21 15:05:40 2018 +0900
@@ -274,7 +274,7 @@
   debugdiscovery: old, nonheads, rev, ssh, remotecmd, insecure
   debugdownload: output
   debugextensions: template
-  debugfileset: rev, all-files, show-stage
+  debugfileset: rev, all-files, show-matcher, show-stage
   debugformat: template
   debugfsinfo: 
   debuggetbundle: head, common, type
--- a/tests/test-fileset.t	Sat Jul 21 14:52:36 2018 +0900
+++ b/tests/test-fileset.t	Sat Jul 21 15:05:40 2018 +0900
@@ -18,13 +18,19 @@
 
   $ fileset -v a1
   (symbol 'a1')
+  * matcher:
+  <patternmatcher patterns='(?:a1$)'>
   a1
   $ fileset -v 'a*'
   (symbol 'a*')
+  * matcher:
+  <patternmatcher patterns='(?:a[^/]*$)'>
   a1
   a2
   $ fileset -v '"re:a\d"'
   (string 're:a\\d')
+  * matcher:
+  <patternmatcher patterns='(?:a\\d)'>
   a1
   a2
   $ fileset -v '!re:"a\d"'
@@ -32,6 +38,10 @@
     (kindpat
       (symbol 're')
       (string 'a\\d')))
+  * matcher:
+  <predicatenmatcher
+    pred=<not
+      <patternmatcher patterns='(?:a\\d)'>>>
   b1
   b2
   $ fileset -v 'path:a1 or glob:b?'
@@ -42,10 +52,14 @@
     (kindpat
       (symbol 'glob')
       (symbol 'b?')))
+  * matcher:
+  <unionmatcher matchers=[
+    <patternmatcher patterns='(?:a1(?:/|$))'>,
+    <patternmatcher patterns='(?:b.$)'>]>
   a1
   b1
   b2
-  $ fileset -v 'a1 or a2'
+  $ fileset -v --no-show-matcher 'a1 or a2'
   (or
     (symbol 'a1')
     (symbol 'a2'))
@@ -133,7 +147,7 @@
   b1
   b2
 
-  $ fileset -p all 'a1 or a2 or (grep("b") & clean())'
+  $ fileset -p all -s 'a1 or a2 or (grep("b") & clean())'
   * parsed:
   (or
     (or
@@ -147,6 +161,14 @@
         (func
           (symbol 'clean')
           None))))
+  * matcher:
+  <unionmatcher matchers=[
+    <unionmatcher matchers=[
+      <patternmatcher patterns='(?:a1$)'>,
+      <patternmatcher patterns='(?:a2$)'>]>,
+    <intersectionmatcher
+      m1=<predicatenmatcher pred=grep('b')>,
+      m2=<predicatenmatcher pred=clean>>]>
   a1
   a2
   b1