[PATCH 3 of 6] debugfileset: add option to show matcher representation

Yuya Nishihara yuya at tcha.org
Thu Aug 2 09:26:03 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1532153140 -32400
#      Sat Jul 21 15:05:40 2018 +0900
# Node ID 75b53fecd632963175bc86d20fd8458774583211
# Parent  75b419d263b70188d50c80f83704d9207654911a
debugfileset: add option to show matcher representation

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -889,6 +889,8 @@ def debugextensions(ui, repo, **opts):
     [('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 @@ def debugfileset(ui, repo, expr, **opts)
         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
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -274,7 +274,7 @@ Show all commands + options
   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
diff --git a/tests/test-fileset.t b/tests/test-fileset.t
--- a/tests/test-fileset.t
+++ b/tests/test-fileset.t
@@ -18,13 +18,19 @@ Test operators and basic patterns
 
   $ 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 @@ Test operators and basic patterns
     (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 @@ Test operators and basic patterns
     (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 @@ Show parsed tree at stages:
   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 @@ Show parsed tree at stages:
         (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


More information about the Mercurial-devel mailing list