Rev 1971: Make SvnRepository threadsafe for cachedbs usage. in http://people.ubuntu.com/~robertc/baz2.0/plugins/svn/trunk

Robert Collins robertc at robertcollins.net
Fri Dec 5 05:59:00 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/plugins/svn/trunk

------------------------------------------------------------
revno: 1971
revision-id: robertc at robertcollins.net-20081205055858-shrq713uayb6t3kx
parent: jelmer at samba.org-20081203011859-1jndv9fy73ceawni
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Fri 2008-12-05 16:58:58 +1100
message:
  Make SvnRepository threadsafe for cachedbs usage.
modified:
  repository.py                  repository.py-20060306123302-1f8c5069b3fe0265
=== modified file 'repository.py'
--- a/repository.py	2008-11-30 22:17:51 +0000
+++ b/repository.py	2008-12-05 05:58:58 +0000
@@ -15,6 +15,8 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 """Subversion repository access."""
 
+import threading
+
 from bzrlib import (
         branch,
         errors as bzr_errors,
@@ -94,7 +96,15 @@
 
 CACHE_DB_VERSION = 5
 
-cachedbs = {}
+_cachedbs = threading.local()
+def cachedbs():
+    """Get a cache for this thread's db connections."""
+    try:
+        return _cachedbs.cache
+    except AttributeError:
+        _cachedbs.cache = {}
+        return _cachedbs.cache
+
 
 class SvnRepository(foreign.ForeignRepository):
     """
@@ -140,9 +150,9 @@
         if use_cache:
             cache_dir = self.create_cache_dir()
             cache_file = os.path.join(cache_dir, 'cache-v%d' % CACHE_DB_VERSION)
-            if not cachedbs.has_key(cache_file):
-                cachedbs[cache_file] = cache.connect_cachefile(cache_file)
-            self.cachedb = cachedbs[cache_file]
+            if not cachedbs().has_key(cache_file):
+                cachedbs()[cache_file] = cache.connect_cachefile(cache_file)
+            self.cachedb = cachedbs()[cache_file]
             self._log = logwalker.CachingLogWalker(self._log, cache_db=self.cachedb)
             cachedir_transport = get_transport(cache_dir)
             self.fileid_map = CachingFileIdMap(cachedir_transport, self.fileid_map)




More information about the bazaar-commits mailing list