# HG changeset patch # User Alexis S. L. Carvalho # Date 2008-02-08 20:07:55 # Node ID b41f0d6a74fcaa9ce558c0a1110e03a743ab1570 # Parent 7383384793fbff4bb0ff643f15d0717975b6f87a dirstate: don't walk ignored directories With a pattern like '^directory$' in .hgignore, a "hg status directory" would still walk "directory" and all its subdirs. This is the first half of a fix for issue886. diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -369,6 +369,14 @@ class dirstate(object): % (self.pathto(f), kind)) return False + def _dirignore(self, f): + if self._ignore(f): + return True + for c in strutil.findall(f, '/'): + if self._ignore(f[:c]): + return True + return False + def walk(self, files=None, match=util.always, badmatch=None): # filter out the stat for src, f, st in self.statwalk(files, match, badmatch=badmatch): @@ -404,9 +412,11 @@ class dirstate(object): return match(file_) ignore = self._ignore + dirignore = self._dirignore if ignored: imatch = match ignore = util.never + dirignore = util.never # self._root may end with a path separator when self._root == '/' common_prefix_len = len(self._root) @@ -492,8 +502,9 @@ class dirstate(object): yield 'b', ff, None continue if s_isdir(st.st_mode): - for f, src, st in findfiles(f): - yield src, f, st + if not dirignore(nf): + for f, src, st in findfiles(f): + yield src, f, st else: if nf in known: continue diff --git a/tests/test-walk b/tests/test-walk --- a/tests/test-walk +++ b/tests/test-walk @@ -92,6 +92,13 @@ hg rm fenugreek debugwalk fenugreek touch new debugwalk new + +mkdir ignored +touch ignored/file +echo '^ignored$' > .hgignore +debugwalk ignored +debugwalk ignored/file + chdir .. debugwalk -R t t/mammals/skunk mkdir t2 diff --git a/tests/test-walk.out b/tests/test-walk.out --- a/tests/test-walk.out +++ b/tests/test-walk.out @@ -278,6 +278,11 @@ m fenugreek fenugreek exact hg debugwalk new f new new exact +hg debugwalk ignored + +hg debugwalk ignored/file +f ignored/file ignored/file exact + cd .. hg debugwalk -R t t/mammals/skunk