[PATCH 2 of 2 STABLE V2] context: use 'changectx.dirs()' to examine wheter specified patterns are valid

Matt Mackall mpm at selenic.com
Mon Feb 20 20:35:11 UTC 2012


On Sun, 2012-02-19 at 19:25 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1329646846 -32400
> # Branch stable
> # Node ID dab4c1d7f1e0fdf1bc09d03410ac1efc18323363
> # Parent  59430cdb845b58c916547dd5623ee438abcb2814
> context: use 'changectx.dirs()' to examine wheter specified patterns are valid

'whether'.

This diff is hard to read because you're doing too much refactoring.

> diff -r 59430cdb845b -r dab4c1d7f1e0 mercurial/context.py
> --- a/mercurial/context.py	Sun Feb 19 19:20:46 2012 +0900
> +++ b/mercurial/context.py	Sun Feb 19 19:20:46 2012 +0900
> @@ -201,19 +201,16 @@
>          return changectx(self._repo, n)
>  
>      def walk(self, match):
> -        fset = set(match.files())
> -        # for dirstate.walk, files=['.'] means "walk the whole tree".
> -        # follow that here, too
> -        fset.discard('.')
>          for fn in self:
> -            for ffn in fset:
> -                # match if the file is the exact name or a directory
> -                if ffn == fn or fn.startswith("%s/" % ffn):
> -                    fset.remove(ffn)

You've ditched the set removal..

> -                    break
>              if match(fn):
>                  yield fn
> -        for fn in sorted(fset):
> +        # omit below entries:
> +        #   - '.' meaning "walk the whole tree" for dirstate.walk
> +        #   - files exactly matched to manifest
> +        #   - directories related to manifest
> +        files = [f for f in match.files()
> +                 if not ((f == '.') or (f in self) or (f in self._dirs))]

..which means we now when we get to the error handling step, we don't
have an empty list to check against, which means we always build
self._dirs.

So now if I don 'hg add somefile' and it _succeeds_, I still need to
loop over the entire manifest to build a directory set, so that I can..
do nothing.

> +        for fn in sorted(files):
>              if match.bad(fn, _('no such file in rev %s') % self) and match(fn):
>                  yield fn

(Note that ideally this code would have a fast path that detected when
there were no patterns and tried to avoid walking the whole manifest and
thus go from O(manifest files) to O(command args). This is a step in the
other direction.)

-- 
Mathematics is the supreme nostalgia of our time.





More information about the Mercurial-devel mailing list