[PATCH 4 of 4 PoC issue4497] fileset: add wdir(set) to evaluate set in working directory (issue4497)

Yuya Nishihara yuya at tcha.org
Tue Mar 24 11:36:47 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1422098310 -32400
#      Sat Jan 24 20:18:30 2015 +0900
# Node ID 17865e7c47fda81763799c9a143b4452b874225f
# Parent  9b86951b17b05684797489000c1e2df904f2edcc
fileset: add wdir(set) to evaluate set in working directory (issue4497)

"wdir()" can be used to avoid the ambiguity caused by evaluating a fileset
in both workingctx and target changectx.

  $ hg revert 'set:wdir(added())'

Unlike other functions, "wdir()" does not select files but switches the
evaluation context. Maybe we can add "rev(set, revspec)" function or
"revspec:set" operator as well.

The main goal of this patch series is to solve the issue4497. If there is a
better alternative, I won't stick to these patches.

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -390,6 +390,14 @@ def copied(mctx, x):
             s.append(f)
     return s
 
+def wdir(mctx, x):
+    """``wdir(set)``
+    Evaluate set in the working directory.
+    """
+    repo = mctx.ctx.repo()
+    wctx = repo[None]
+    return getset(mctx.switch(wctx, _buildstatus(wctx, x)), x)
+
 def subrepo(mctx, x):
     """``subrepo([pattern])``
     Subrepositories whose paths match the given pattern.
@@ -434,6 +442,7 @@ symbols = {
     'unknown': unknown,
     'unresolved': unresolved,
     'subrepo': subrepo,
+    'wdir': wdir,
 }
 
 methods = {
@@ -476,6 +485,7 @@ class matchctx(object):
 
 # filesets using matchctx.switch()
 _switchcallers = [
+    'wdir',
 ]
 
 def _intree(funcs, tree):
diff --git a/mercurial/help/filesets.txt b/mercurial/help/filesets.txt
--- a/mercurial/help/filesets.txt
+++ b/mercurial/help/filesets.txt
@@ -58,6 +58,10 @@ Some sample queries:
 
     hg revert "set:copied() and binary() and size('>1M')"
 
+- Revert files that were added to the working directory::
+
+    hg revert "set:wdir(added())"
+
 - Remove files listed in foo.lst that contain the letter a or b::
 
     hg remove "set: 'listfile:foo.lst' and (**a* or **b*)"
diff --git a/tests/test-fileset.t b/tests/test-fileset.t
--- a/tests/test-fileset.t
+++ b/tests/test-fileset.t
@@ -77,6 +77,20 @@ Test files status
   $ fileset 'copied()'
   c1
 
+Test files status in different revisions
+(currently files absent at -r0 are not listed)
+
+  $ fileset -r0 'wdir(modified())'
+  b2
+  $ fileset -r0 'wdir(added())'
+  $ fileset -r0 'added() and wdir(modified() or removed() or unknown())'
+  b2
+  a2
+  $ fileset -r0 'added() and a* or wdir(modified())'
+  a1
+  a2
+  b2
+
 Test files properties
 
   >>> file('bin', 'wb').write('\0a')
@@ -278,3 +292,10 @@ Test with a revision
   mixed
   $ fileset 'eol(mac)'
   mac
+
+Test files at -r0 should be filtered by files at wdir
+
+  $ fileset -r0 '* and wdir(*)'
+  a1
+  b1
+  b2


More information about the Mercurial-devel mailing list