Patchwork [13,of,17] match: optimize visitdir() for when no explicit files are listed

login
register
mail settings
Submitter via Mercurial-devel
Date May 25, 2017, 6:24 p.m.
Message ID <85bcfda434b272bbbedf.1495736694@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20915/
State Accepted
Headers show

Comments

via Mercurial-devel - May 25, 2017, 6:24 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495349354 25200
#      Sat May 20 23:49:14 2017 -0700
# Node ID 85bcfda434b272bbbedffcf0037c5008759fb748
# Parent  58c5c82d358e618cfadabd79d0a47b3f0812c3ea
match: optimize visitdir() for when no explicit files are listed

In patternmatcher, we used to say that all directories should be
visited if no explicit files were listed, because the case of empty
_files usually implied that no patterns were given. However, this made
e.g. "hg files -r .  rootfilesin:."  slower than necessary, because
that also ended up with an empty list in _files. Now that
patternmatcher does not handle includes, the only remaining case where
its _files/_fileset fields will be empty is when it's matching
everything. We can therefore treat the always-case specially and stop
treating the empty _files case specially. This makes the case
mentioned above faster on treemanifest repos.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -354,10 +354,11 @@ 
         return set(util.dirs(self._fileset)) | {'.'}
 
     def visitdir(self, dir):
+        if self.always():
+            return 'all'
         if self.prefix() and dir in self._fileset:
             return 'all'
-        return (not self._fileset or
-                '.' in self._fileset or
+        return ('.' in self._fileset or
                 dir in self._fileset or
                 dir in self._dirs or
                 any(parentdir in self._fileset