[RFC] walkdirs skip api

Robert Collins robertc at robertcollins.net
Wed Aug 16 03:49:19 BST 2006


On Tue, 2006-08-15 at 21:41 -0500, John Arbash Meinel wrote:
> Robert Collins wrote:
> > Hi,
> > 	I've figured out what I think is a reasonable API for skipping dirs
> > with walkdirs.
> > 
> > Currently we do a del on the dirblock to remove things we dont want to
> > iterate over. This is somewhat expensive, and very expensive when we try
> > to stack walkdirs - as we do in WorkingTree.walkdirs (we stack walking a
> > RevisionTree and the osutils.walkdirs together to show
> > versioned/unversioned file state etc).
> > 
> > I propose the following:
> > walkdirs() will return a Walker object which has two methods:
> > walk()
> > skip(basename)
> > 
> > walk() will return the current generator
> > skip(basename) will schedule basename to be skipped when next() is
> > invoked on the generator.
> > 
> > How does that sounds ?
> > 
> > -Rob
> 
> I'm a little confused about next() versus walk(), but I think you mean
> it works like this:
> 
> walker = osutils.walkdirs()
> for dirinfo, entries in walker.walk():
>   for relpath, name, kind, st, ..., abspath in entries:
>     if name == '.bzr':
>       walker.skip('.bzr')
>       continue
> 
> 
> And then the use for WorkingTree.walk() would be more like:
> 
> walker = wt.walkdirs()
> for dirinfo, entries in walker.walk():
>   for relpath, name, version_type, ie in entries:
>     if version_type in ('I', '?'):
>       walker.skip(name)
>     else:
>       ... do whatever it is you do ...
> 
> I think that works quite well as an api. I feel like Tree.walkdirs()
> needs to return different objects than a plain osutils.walkdirs(), so I
> wonder if it shouldn't be a different function name.
> 
> I also wonder if we don't want a working-tree specific walk function,
> that lets us iterate over the current tree and all parent trees
> simultaneously. 'dirstate' is being designed around this, explicitly to
> make commit fast. (Since it already has all parent info sorted out per
> file).

http://bazaar-vcs.org/Specs/WorkingTreeParentApi

discusses such an api - walkdirs_with_parents.

Generally I think we agree here - cool.

I'm not sure about the naming. I think that Tree.walkdirs must be
consistent, but its ok for osutils.walkdirs to differ - it will be clear
what function is being called, and having the same name for the same
basic intent is quite useful.

Rob

-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060816/bf703ced/attachment.pgp 


More information about the bazaar mailing list