fileset: make debugfileset filter repository files
authorYuya Nishihara <yuya@tcha.org>
Sat, 09 Jun 2018 18:58:16 +0900
changeset 38611 3d8ef60569d8
parent 38610 d474b3b44d4f
child 38612 0ba4cf3f088f
fileset: make debugfileset filter repository files This prepares for the structural change of the fileset. A computed fileset will no longer be a set of files, but a boolean function (i.e. matcher) to test if an input file matches the given fileset expression. --all-files option is added because some examples in the test need to scan files across revisions.
mercurial/debugcommands.py
tests/test-completion.t
tests/test-fileset.t
--- a/mercurial/debugcommands.py	Sun Jul 08 19:24:18 2018 +0900
+++ b/mercurial/debugcommands.py	Sat Jun 09 18:58:16 2018 +0900
@@ -875,16 +875,38 @@
     fm.end()
 
 @command('debugfileset',
-    [('r', 'rev', '', _('apply the filespec on this revision'), _('REV'))],
-    _('[-r REV] FILESPEC'))
+    [('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'))
 def debugfileset(ui, repo, expr, **opts):
     '''parse and apply a fileset specification'''
-    ctx = scmutil.revsingle(repo, opts.get(r'rev'), None)
+    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")
 
-    for f in sorted(ctx.getfileset(expr)):
+    files = set()
+    if opts['all_files']:
+        for r in repo:
+            c = repo[r]
+            files.update(c.files())
+            files.update(c.substate)
+    if opts['all_files'] or ctx.rev() is None:
+        wctx = repo[None]
+        files.update(repo.dirstate.walk(scmutil.matchall(repo),
+                                        subrepos=list(wctx.substate),
+                                        unknown=True, ignored=True))
+        files.update(wctx.substate)
+    else:
+        files.update(ctx.files())
+        files.update(ctx.substate)
+
+    m = scmutil.matchfiles(repo, ctx.getfileset(expr))
+    for f in sorted(files):
+        if not m(f):
+            continue
         ui.write("%s\n" % f)
 
 @command('debugformat',
--- a/tests/test-completion.t	Sun Jul 08 19:24:18 2018 +0900
+++ b/tests/test-completion.t	Sat Jun 09 18:58:16 2018 +0900
@@ -273,7 +273,7 @@
   debugdiscovery: old, nonheads, rev, ssh, remotecmd, insecure
   debugdownload: output
   debugextensions: template
-  debugfileset: rev
+  debugfileset: rev, all-files
   debugformat: template
   debugfsinfo: 
   debuggetbundle: head, common, type
--- a/tests/test-fileset.t	Sun Jul 08 19:24:18 2018 +0900
+++ b/tests/test-fileset.t	Sat Jun 09 18:58:16 2018 +0900
@@ -1,5 +1,5 @@
   $ fileset() {
-  >   hg debugfileset "$@"
+  >   hg debugfileset --all-files "$@"
   > }
 
   $ hg init repo