Patchwork [3,of,6] fileset: make debugfileset filter repository files

login
register
mail settings
Submitter Yuya Nishihara
Date July 7, 2018, 8:38 a.m.
Message ID <f037e8dfa6c2047d0ef8.1530952727@mimosa>
Download mbox | patch
Permalink /patch/32678/
State New
Headers show

Comments

Yuya Nishihara - July 7, 2018, 8:38 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1528538296 -32400
#      Sat Jun 09 18:58:16 2018 +0900
# Node ID f037e8dfa6c2047d0ef86efc2e83fece0fa08d80
# Parent  8a86d134e5915eac84a1885254463d37b6feeaeb
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.

Patch

diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py
--- a/mercurial/debugcommands.py
+++ b/mercurial/debugcommands.py
@@ -875,16 +875,38 @@  def debugextensions(ui, repo, **opts):
     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',
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -273,7 +273,7 @@  Show all commands + options
   debugdiscovery: old, nonheads, rev, ssh, remotecmd, insecure
   debugdownload: output
   debugextensions: template
-  debugfileset: rev
+  debugfileset: rev, all-files
   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
@@ -1,5 +1,5 @@ 
   $ fileset() {
-  >   hg debugfileset "$@"
+  >   hg debugfileset --all-files "$@"
   > }
 
   $ hg init repo