Patchwork [2,of,5] context.walk: walk all files when file and '.' given

login
register
mail settings
Submitter Martin von Zweigbergk
Date March 18, 2015, 8:27 p.m.
Message ID <1c7d90d9ea3020b4ddf9.1426710461@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/8152/
State Accepted
Commit 82b82168d0451f1284578000c536750f92381342
Headers show

Comments

Martin von Zweigbergk - March 18, 2015, 8:27 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1426704129 25200
#      Wed Mar 18 11:42:09 2015 -0700
# Node ID 1c7d90d9ea3020b4ddf98de59046ab6dc1577794
# Parent  2ecdb84c187ea3044f61fec65ceaeb1193a72582
context.walk: walk all files when file and '.' given

When both '.' (the working copy root) and an explicit file (or files)
are in match.files(), we only walk the explicitly listed files. This
is because we remove the '.' from the set too early. Move later and
add a test for it. Before this change, the last test would print only
"3".

Patch

diff -r 2ecdb84c187e -r 1c7d90d9ea30 mercurial/context.py
--- a/mercurial/context.py	Wed Mar 18 09:26:26 2015 -0700
+++ b/mercurial/context.py	Wed Mar 18 11:42:09 2015 -0700
@@ -588,10 +588,6 @@ 
 
     def walk(self, match):
         fset = set(match.files())
-        # for dirstate.walk, files=['.'] means "walk the whole tree".
-        # follow that here, too
-        fset.discard('.')
-
         # avoid the entire walk if we're only looking for specific files
         if fset and not match.anypats():
             if util.all(fn in self for fn in fset):
@@ -606,6 +602,9 @@ 
                 fset.remove(fn)
             if match(fn):
                 yield fn
+        # for dirstate.walk, files=['.'] means "walk the whole tree".
+        # follow that here, too
+        fset.discard('.')
         for fn in sorted(fset):
             if not self.hasdir(fn):
                 match.bad(fn, _('no such file in rev %s') % self)
diff -r 2ecdb84c187e -r 1c7d90d9ea30 tests/test-cat.t
--- a/tests/test-cat.t	Wed Mar 18 09:26:26 2015 -0700
+++ b/tests/test-cat.t	Wed Mar 18 11:42:09 2015 -0700
@@ -22,10 +22,22 @@ 
   $ hg cat -r 1 b
   1
 
-Test fileset
+Test multiple files
 
   $ echo 3 > c
   $ hg ci -Am addmore c
+  $ hg cat b c
+  1
+  3
+  $ hg cat .
+  1
+  3
+  $ hg cat . c
+  1
+  3
+
+Test fileset
+
   $ hg cat 'set:not(b) or a'
   3
   $ hg cat 'set:c or b'