changeset 38686:131aae58a316

fileset: add "tracked()" to explicitly select files in the revision I'm going to rewrite filesets to be match predicates, which means basic patterns such as '*' will no longer be "closed" to the subset constructed from the ctx. Good thing is that 'hg status "set:not binary()"' can include unknown files out of the box, and fileset computation will likely to be faster as we won't have to walk dirstate twice, for example. Bad thing is that we can't select files at a certain revision by 'set:revs(REV, **)' since '**' is "open" to any paths. So, this patch introduces "tracked()" as a replacement for the '**' in the example above.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 10 Jun 2018 22:19:56 +0900
parents 80466fd85ac9
children 1500cbe22d53
files mercurial/fileset.py tests/test-fileset.t
diffstat 2 files changed, 12 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/fileset.py	Sat Jun 09 18:11:49 2018 +0900
+++ b/mercurial/fileset.py	Sun Jun 10 22:19:56 2018 +0900
@@ -284,6 +284,13 @@
     s = set(mctx.status().clean)
     return [f for f in mctx.subset if f in s]
 
+@predicate('tracked()')
+def tracked(mctx, x):
+    """File that is under Mercurial control."""
+    # i18n: "tracked" is a keyword
+    getargs(x, 0, 0, _("tracked takes no arguments"))
+    return [f for f in mctx.subset if f in mctx.ctx]
+
 @predicate('binary()', callexisting=True)
 def binary(mctx, x):
     """File that appears to be binary (contains NUL bytes).
--- a/tests/test-fileset.t	Sat Jun 09 18:11:49 2018 +0900
+++ b/tests/test-fileset.t	Sun Jun 10 22:19:56 2018 +0900
@@ -524,7 +524,7 @@
 Test files at -r0 should be filtered by files at wdir
 -----------------------------------------------------
 
-  $ fileset -r0 '* and revs("wdir()", *)'
+  $ fileset -r0 'tracked() and revs("wdir()", tracked())'
   a1
   b1
   b2
@@ -590,12 +590,12 @@
   R a2
   $ fileset "status(0, 1, removed())"
   a2
-  $ fileset "* and status(0, 1, removed())"
+  $ fileset "tracked() and status(0, 1, removed())"
   $ fileset -r 4 "status(0, 1, removed())"
   a2
-  $ fileset -r 4 "* and status(0, 1, removed())"
-  $ fileset "revs('4', * and status(0, 1, removed()))"
-  $ fileset "revs('0', * and status(0, 1, removed()))"
+  $ fileset -r 4 "tracked() and status(0, 1, removed())"
+  $ fileset "revs('4', tracked() and status(0, 1, removed()))"
+  $ fileset "revs('0', tracked() and status(0, 1, removed()))"
   a2
 
 check wdir()