[PATCH 2 of 3 STABLE V3] localrepository: use 'changectx.dirs()' in 'status()' for directory patterns

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Feb 22 09:09:40 CST 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1329923274 -32400
# Branch stable
# Node ID 1feded5e1cb7aba9310a7bad20f69a6508f27230
# Parent  caba21e946d5767ec29a0b7da32661d9d0a80e1d
localrepository: use 'changectx.dirs()' in 'status()' for directory patterns

when pattern which does not match against any files in working context
is specified, current implementation of 'localrepository.status()'
decides whether warning message about it should be shown or not by
'f not in context'

this works correctly for 'file pattern', but not for 'directory
pattern', because 'f not in context' always returns True for
directories, even if they are related to the context.

this patch uses 'changectx.dirs()' to examine whether specified
pattern is related to the context as a directory or not.

diff -r caba21e946d5 -r 1feded5e1cb7 mercurial/localrepo.py
--- a/mercurial/localrepo.py	Thu Feb 23 00:07:54 2012 +0900
+++ b/mercurial/localrepo.py	Thu Feb 23 00:07:54 2012 +0900
@@ -1351,7 +1351,9 @@
 
         if not parentworking:
             def bad(f, msg):
-                if f not in ctx1:
+                # 'f' may be a directory pattern from 'match.files()',
+                # so 'f not in ctx1' is not enough
+                if f not in ctx1 and f not in ctx1.dirs():
                     self.ui.warn('%s: %s\n' % (self.dirstate.pathto(f), msg))
             match.bad = bad
 
diff -r caba21e946d5 -r 1feded5e1cb7 tests/test-status.t
--- a/tests/test-status.t	Thu Feb 23 00:07:54 2012 +0900
+++ b/tests/test-status.t	Thu Feb 23 00:07:54 2012 +0900
@@ -295,3 +295,39 @@
   $ hg ci -q -A -m 'add another file'
   $ hg status -A --rev 1:2 010a
   C 010a
+
+  $ cd ..
+
+test "hg status" with "directory pattern" which matches against files
+only known on target revision.
+
+  $ hg init repo6
+  $ cd repo6
+
+  $ echo a > a.txt
+  $ hg add a.txt
+  $ hg commit -m '#0'
+  $ mkdir -p 1/2/3/4/5
+  $ echo b > 1/2/3/4/5/b.txt
+  $ hg add 1/2/3/4/5/b.txt
+  $ hg commit -m '#1'
+
+  $ hg update -C 0 > /dev/null
+  $ hg status -A
+  C a.txt
+
+the directory matching against specified pattern should be removed,
+because directory existence prevents 'dirstate.walk()' from showing
+warning message about such pattern.
+
+  $ test ! -d 1
+  $ hg status -A --rev 1 1/2/3/4/5/b.txt
+  R 1/2/3/4/5/b.txt
+  $ hg status -A --rev 1 1/2/3/4/5
+  R 1/2/3/4/5/b.txt
+  $ hg status -A --rev 1 1/2/3
+  R 1/2/3/4/5/b.txt
+  $ hg status -A --rev 1 1
+  R 1/2/3/4/5/b.txt
+
+  $ cd ..


More information about the Mercurial-devel mailing list