[PATCH 03 of 13] Yield directories in dirstate.statwalk()

Emanuele Aina faina.mail at tiscali.it
Tue Feb 27 01:06:03 CST 2007


# HG changeset patch
# User Emanuele Aina <em at nerd.ocracy.org>
# Date 1172563536 -3600
# Node ID 342e9d3258d2637653f838175e0a34691105af23
# Parent  719dccfa8eaccc3071806fd82e80176328f79e3e
Yield directories in dirstate.statwalk()

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -354,7 +354,8 @@ class dirstate(object):
     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):
-            yield src, f
+            if src != 'd':
+                yield src, f
 
     def statwalk(self, files=None, match=util.always, ignored=False,
                  badmatch=None):
@@ -365,6 +366,7 @@ class dirstate(object):
         results are yielded in a tuple (src, filename, st), where src
         is one of:
         'f' the file was found in the directory tree
+        'd' the file is a directory of the tree
         'm' the file was only in the dirstate and not in the tree
         'b' file was not found and matched badmatch
 
@@ -393,9 +395,12 @@ class dirstate(object):
             common_prefix_len += 1
         # recursion free walker, faster than os.walk.
         def findfiles(s):
-            work = [s]
+            nd = util.normpath(s[common_prefix_len:])
+            work = [(s, util.pconvert(nd), os.lstat(s))]
             while work:
-                top = work.pop()
+                top, top_np, top_st = work.pop()
+                if top_np != '.':
+                    yield 'd', top_np, top_st
                 names = os.listdir(top)
                 names.sort()
                 # nd is the top of the repository dir tree
@@ -420,7 +425,7 @@ class dirstate(object):
                     if stat.S_ISDIR(st.st_mode):
                         ds = util.pconvert(os.path.join(nd, f +'/'))
                         if imatch(ds):
-                            work.append(p)
+                            work.append((p, np, st))
                         if imatch(np) and np in dc:
                             yield 'm', np, st
                     elif imatch(np):
@@ -482,6 +487,8 @@ class dirstate(object):
         removed, deleted, clean = [], [], []
 
         for src, fn, st in self.statwalk(files, match, ignored=list_ignored):
+            if src == 'd':
+                continue
             try:
                 type_, mode, size, time = self[fn]
             except KeyError:


More information about the Mercurial-devel mailing list