[PATCH 1 of 2 STABLE] context: add 'changectx.dirs()' to recognize directory matching pattern

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Sun Feb 19 00:57:48 CST 2012


At Sat, 18 Feb 2012 13:58:47 -0600,
Matt Mackall wrote:
> 
> On Sun, 2012-02-19 at 00:15 +0900, FUJIWARA Katsunori wrote:
> > # HG changeset patch
> > # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> > # Date 1329577967 -32400
> > # Branch stable
> > # Node ID 0df295bc57a9dbf897fde6be438711dd56797591
> > # Parent  0e0060bf2f440d5cc33e5f36d99868a5380debd4
> > context: add 'changectx.dirs()' to recognize directory matching pattern
> > 
> > when patterns which does not match any files in working context is
> > specified, current implementation of 'localrepository.status()' decide
> > whether warning message about it should be shown or not
> > by 'f not in targetcontext'
> 
> > this works correctly for 'file pattern', but not for 'directory
> > pattern', because 'f not in targetcontext' always returns True for
> > directories.
> > 
> > this patch add 'changectx.dirs()', which returns map of all
> > directories deduced from manifest, to examine whether specified
> > directory is related to context or not quickly.
> 
> Interesting. There's probably a bit too much refactoring happening in
> this patch.
> 
> Note that the code in dirstate is specialized for reference counting so
> that add/remove does the right thing. For non-workingctx contexts, it's
> a lot slower than it need be. And for working contexts, well, we might
> as well be looking at the directory tree that dirstate has already
> built, right?
> 
> So for normal contexts, we want something like:
> 
> dirs = set()
> add = dirs.add
> for path in self:
>     pos = path.rfind('/')
>     while pos != -1:
> 	if path[:pos] in dirs:
> 	    break # seen this directory and above
> 	add(path[:pos])
>         pos = path.rfind('/', 0, pos)

Thank you for your comments.

I'll post patch series re-written as you described.

> But note that this is still pretty expensive, as it means unpacking a
> manifest: we don't want to call this function if we can avoid it.

----------------------------------------------------------------------
[FUJIWARA Katsunori]                             foozy at lares.dti.ne.jp


More information about the Mercurial-devel mailing list