diff mercurial/match.py @ 25188:2773540c3650

match: remove unnecessary optimization where visitdir() returns 'all' Match's visitdir() was prematurely optimized to return 'all' in some cases, so that the caller would not have to call it for directories within the current directory. This change makes the visitdir system less flexible for future changes, such as making visitdir consider the match's include and exclude patterns. As a demonstration of this optimization not actually improving performance, I ran 'hg files -r . media' on the Mozilla repository, stored as treemanifest revlogs. With best of ten tries, the command took 1.07s both with and without the optimization, even though the optimization reduced the calls from visitdir() from 987 to 51.
author Drew Gottlieb <drgott@google.com>
date Wed, 06 May 2015 15:59:35 -0700
parents 6f7048cc2419
children 1c8c33eaea0a
line wrap: on
line diff
--- a/mercurial/match.py	Thu Apr 16 17:12:33 2015 -0400
+++ b/mercurial/match.py	Wed May 06 15:59:35 2015 -0700
@@ -174,14 +174,10 @@
         return set(util.dirs(self._fmap)) | set(['.'])
 
     def visitdir(self, dir):
-        '''Helps while traversing a directory tree. Returns the string 'all' if
-        the given directory and all subdirectories should be visited. Otherwise
-        returns True or False indicating whether the given directory should be
-        visited. If 'all' is returned, calling this method on a subdirectory
-        gives an undefined result.'''
-        if not self._fmap or self.exact(dir):
-            return 'all'
-        return dir in self._dirs
+        return (not self._fmap or '.' in self._fmap or
+                dir in self._fmap or dir in self._dirs or
+                any(parentdir in self._fmap
+                    for parentdir in util.finddirs(dir)))
 
     def exact(self, f):
         '''Returns True if f is in .files().'''