[Checkins] SVN: zc.buildout/trunk/ Introduce a cache for the expensive `buildout._dir_hash` function.

Hanno Schlichting hannosch at hannosch.eu
Sat Mar 12 03:05:52 EST 2011


Log message for revision 120884:
  Introduce a cache for the expensive `buildout._dir_hash` function.
  

Changed:
  U   zc.buildout/trunk/CHANGES.txt
  U   zc.buildout/trunk/src/zc/buildout/buildout.py

-=-
Modified: zc.buildout/trunk/CHANGES.txt
===================================================================
--- zc.buildout/trunk/CHANGES.txt	2011-03-12 07:51:11 UTC (rev 120883)
+++ zc.buildout/trunk/CHANGES.txt	2011-03-12 08:05:52 UTC (rev 120884)
@@ -4,6 +4,8 @@
 1.5.3 (unreleased)
 ==================
 
+- Introduce a cache for the expensive `buildout._dir_hash` function.
+
 - Remove duplicate path from script's sys.path setup.
 
 - changed broken dash S check to pass the configuration options

Modified: zc.buildout/trunk/src/zc/buildout/buildout.py
===================================================================
--- zc.buildout/trunk/src/zc/buildout/buildout.py	2011-03-12 07:51:11 UTC (rev 120883)
+++ zc.buildout/trunk/src/zc/buildout/buildout.py	2011-03-12 08:05:52 UTC (rev 120884)
@@ -1467,7 +1467,11 @@
 
 
 ignore_directories = '.svn', 'CVS'
+_dir_hashes = {}
 def _dir_hash(dir):
+    dir_hash = _dir_hashes.get(dir, None)
+    if dir_hash is not None:
+        return dir_hash
     hash = md5()
     for (dirpath, dirnames, filenames) in os.walk(dir):
         dirnames[:] = [n for n in dirnames if n not in ignore_directories]
@@ -1479,7 +1483,8 @@
         hash.update(' '.join(filenames))
         for name in filenames:
             hash.update(open(os.path.join(dirpath, name)).read())
-    return hash.digest().encode('base64').strip()
+    _dir_hashes[dir] = dir_hash = hash.digest().encode('base64').strip()
+    return dir_hash
 
 def _dists_sig(dists):
     result = []



More information about the checkins mailing list