# HG changeset patch # User Siddharth Agarwal # Date 2014-08-02 05:05:16 # Node ID 977a0b9af5aca92f21f74202ce80da9dbc178c7a # Parent 52d34d5415c9c7d8d544169104d2c06fa6f41f5c dirstate: add a method to efficiently filter by match Current callers that require just this data call workingctx.walk, which calls dirstate.walk, which stats all the files. Even worse, workingctx.walk looks for unknown files, significantly slowing things down, even though callers might not be interested in them at all. diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -873,3 +873,21 @@ class dirstate(object): return (lookup, modified, added, removed, deleted, unknown, ignored, clean) + + def matches(self, match): + ''' + return files in the dirstate (in whatever state) filtered by match + ''' + dmap = self._map + if match.always(): + return dmap.keys() + files = match.files() + if match.matchfn == match.exact: + # fast path -- filter the other way around, since typically files is + # much smaller than dmap + return [f for f in files if f in dmap] + if not match.anypats() and util.all(fn in dmap for fn in files): + # fast path -- all the values are known to be files, so just return + # that + return list(files) + return [f for f in dmap if match(f)]