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

Alexis S. L. Carvalho alexis at cecm.usp.br
Sun Mar 4 08:07:49 CST 2007


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

I was a bit worried about possible (performance) impacts on e.g. hg
status, but things look ok from a (very) quick test.

The statwalk code is somewhat more subtle than I'd like, so I have a few
questions:

> 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))]

util.normpath already returns pconvert()ed paths.

And why is this new call to normpath needed here?  Can't you just
util.pconvert(s[common_prefix_len:])?  Hmm... but we do use
util.normpath a bit after that...  I'm guessing you're trying to be
consistent with some other (not-so-nice) code that ends up using '.' to
mean the repo root...

>              while work:
> -                top = work.pop()
> +                top, top_np, top_st = work.pop()
> +                if top_np != '.':
> +                    yield 'd', top_np, top_st

What's this special case about?  To avoid returning the repo root?
Wouldn't it be more consistent to return it, too?

Alexis


More information about the Mercurial-devel mailing list