Support caching properties set on branch paths.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 14 Jul 2006 00:47:02 +0000 (02:47 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 14 Jul 2006 00:47:02 +0000 (02:47 +0200)
checkout.py
commit.py
logwalker.py
repository.py

index eb9a7a84bac1323e29ef4ebc9a95934aeefeeaa7..3d78150ef020a77a51942658d6e5cf3199592c92 100644 (file)
@@ -391,12 +391,12 @@ class SvnWorkingTree(WorkingTree):
         return fingerprint_file(open(self.abspath(path)))['sha1']
 
     def _get_bzr_merges(self):
-        return self.branch.repository._get_dir_prop(self.branch.branch_path, 
+        return self.branch.repository._get_branch_prop(self.branch.branch_path, 
                                             self.base_revnum, 
                                             SVN_PROP_BZR_MERGE, "")
 
     def _get_svk_merges(self):
-        return self.branch.repository._get_dir_prop(self.branch.branch_path, 
+        return self.branch.repository._get_branch_prop(self.branch.branch_path, 
                                             self.base_revnum, 
                                             SVN_PROP_SVK_MERGE, "")
 
index d11eedb02c16b0b2096a3b1af1f6b73541507fb3..0355e1c0ef01a63a5065a93006759f0da37cf76a 100644 (file)
--- a/commit.py
+++ b/commit.py
@@ -58,13 +58,13 @@ class SvnCommitBuilder(CommitBuilder):
             # Bazaar Parents
             if branch.last_revision():
                 (bp, revnum) = repository.parse_revision_id(branch.last_revision())
-                old = repository._get_dir_prop(bp, revnum, SVN_PROP_BZR_MERGE, "")
+                old = repository._get_branch_prop(bp, revnum, SVN_PROP_BZR_MERGE, "")
             else:
                 old = ""
             self._svnprops[SVN_PROP_BZR_MERGE] = old + "\t".join(self.merges) + "\n"
 
             if branch.last_revision() is not None:
-                old = repository._get_dir_prop(bp, revnum, SVN_PROP_SVK_MERGE)
+                old = repository._get_branch_prop(bp, revnum, SVN_PROP_SVK_MERGE)
             else:
                 old = ""
 
index cf4fe7cedcf3cf840b327e5089a721696bde133e..8080da6878bd1491d73fd73e55212482803a4ead 100644 (file)
@@ -14,7 +14,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-from bzrlib.config import config_dir
 from bzrlib.errors import NoSuchRevision, BzrError, NotBranchError
 from bzrlib.progress import ProgressBar, DummyProgress
 from bzrlib.trace import mutter
@@ -26,25 +25,6 @@ from cStringIO import StringIO
 from svn.core import SubversionException
 import svn.ra
 
-cache_dir = os.path.join(config_dir(), 'svn-cache')
-
-def create_cache_dir(uuid):
-    if not os.path.exists(cache_dir):
-        os.mkdir(cache_dir)
-
-        open(os.path.join(cache_dir, "README"), 'w').write(
-"""This directory contains information cached by the bzr-svn plugin.
-
-It is used for performance reasons only and can be removed 
-without losing data.
-""")
-
-    dir = os.path.join(cache_dir, uuid)
-    if not os.path.exists(dir):
-        os.mkdir(dir)
-    return dir
-
-
 class NotSvnBranchPath(BzrError):
     def __init__(self, branch_path):
         BzrError.__init__(self, 
@@ -54,7 +34,7 @@ class NotSvnBranchPath(BzrError):
 
 
 class LogWalker(object):
-    def __init__(self, scheme, ra=None, uuid=None, last_revnum=None, repos_url=None, pb=None):
+    def __init__(self, scheme, ra=None, cache_dir=None, last_revnum=None, repos_url=None, pb=None):
         if ra is None:
             callbacks = svn.ra.callbacks2_t()
             ra = svn.ra.open2(repos_url.encode('utf8'), callbacks, None, None)
@@ -62,20 +42,17 @@ class LogWalker(object):
             if root != repos_url:
                 svn.ra.reparent(ra, root.encode('utf8'))
 
-        if not uuid:
-            uuid = svn.ra.get_uuid(ra)
-
-        self.uuid = uuid
-
         if last_revnum is None:
             last_revnum = svn.ra.get_latest_revnum(ra)
 
-        self.cache_file = os.path.join(create_cache_dir(uuid), 'log')
         self.ra = ra
         self.scheme = scheme
 
         # Try to load cache from file
-        self.revisions = shelve.open(self.cache_file)
+        if cache_dir is not None:
+            self.revisions = shelve.open(os.path.join(cache_dir, 'log'))
+        else:
+            self.revisions = {}
         self.saved_revnum = max(len(self.revisions)-1, 0)
 
         if self.saved_revnum < last_revnum:
@@ -125,9 +102,6 @@ class LogWalker(object):
 
         self.save()
 
-    def save(self):
-        pickle.dump(self.revisions, open(self.cache_file, 'w'))
-
     def follow_history(self, branch_path, revnum):
         for (branch, paths, rev, _, _, _) in self.get_branch_log(branch_path, 
                                                                  revnum):
index 295380832b4fe66e2a6cc736c38b8f0040c7db8d..9cfe7809d8fea002266cf17863aaea2f80adc294 100644 (file)
@@ -16,6 +16,7 @@
 
 import bzrlib
 from bzrlib.branch import BranchCheckResult
+from bzrlib.config import config_dir
 from bzrlib.errors import (BzrError, InvalidRevisionId, NoSuchFile, 
                            NoSuchRevision)
 from bzrlib.graph import Graph
@@ -34,6 +35,7 @@ import svn.core
 
 import os
 from cStringIO import StringIO
+import shelve
 
 import branch
 import logwalker
@@ -46,6 +48,8 @@ SVN_PROP_SVK_MERGE = 'svk:merge'
 SVN_PROP_BZR_REVPROP_PREFIX = 'bzr:revprop:'
 SVN_REVPROP_BZR_SIGNATURE = 'bzr:gpg-signature'
 
+cache_dir = os.path.join(config_dir(), 'svn-cache')
+
 _unsafe = "%/-\t "
 def escape_svn_path(id):
     r = [((c in _unsafe) and ('%%%02x' % ord(c)) or c)
@@ -177,8 +181,31 @@ class SvnRepository(Repository):
 
         self._latest_revnum = svn.ra.get_latest_revnum(self.ra)
 
-        self._log = logwalker.LogWalker(self.scheme, self.ra, self.uuid, 
-                self._latest_revnum)
+        self._log = logwalker.LogWalker(self.scheme, self.ra, 
+                                        self.create_cache_dir(), 
+                                        self._latest_revnum)
+
+        self.branchprop_cache = shelve.open(os.path.join(
+                                            self.create_cache_dir(),
+                                            'branchprops'))
+
+    def create_cache_dir(self):
+        if not os.path.exists(cache_dir):
+            os.mkdir(cache_dir)
+
+            open(os.path.join(cache_dir, "README"), 'w').write(
+    """This directory contains information cached by the bzr-svn plugin.
+
+It is used for performance reasons only and can be removed 
+without losing data.
+
+See http://bazaar-vcs.org/BzrSvn for details.
+""")
+
+        dir = os.path.join(cache_dir, self.uuid)
+        if not os.path.exists(dir):
+            os.mkdir(dir)
+        return dir
 
     def _check(self, revision_ids):
         return BranchCheckResult(self)
@@ -285,7 +312,7 @@ class SvnRepository(Repository):
 
         ancestry = []
 
-        for l in self._get_dir_prop(path, revnum, 
+        for l in self._get_branch_prop(path, revnum, 
                                     SVN_PROP_BZR_MERGE, "").splitlines():
             ancestry.extend(l.split("\n"))
 
@@ -339,9 +366,9 @@ class SvnRepository(Repository):
             if parent_path is None:
                 old_merge = ""
             else:
-                old_merge = self._get_dir_prop(parent_path, parent_revnum, 
+                old_merge = self._get_branch_prop(parent_path, parent_revnum, 
                         SVN_PROP_BZR_MERGE, "").splitlines()
-            new_merge = self._get_dir_prop(path, revnum, 
+            new_merge = self._get_branch_prop(path, revnum, 
                                            SVN_PROP_BZR_MERGE, "").splitlines()
 
             assert (len(old_merge) == len(new_merge) or 
@@ -373,7 +400,7 @@ class SvnRepository(Repository):
         # Commit SVN revision properties to a Revision object
         rev = Revision(revision_id=revision_id, parent_ids=parent_ids)
 
-        svn_props = self._get_dir_proplist(path, revnum)
+        svn_props = self._get_branch_proplist(path, revnum)
         bzr_props = {}
         for name in svn_props:
             if not name.startswith(SVN_PROP_BZR_REVPROP_PREFIX):
@@ -556,6 +583,18 @@ class SvnRepository(Repository):
             return props[name]
         return None
 
+    def _get_branch_proplist(self, path, revnum):
+        key = "%s:%d" % (path, revnum)
+        if not self.branchprop_cache.has_key(key):
+            self.branchprop_cache[key] = self._get_dir_proplist(path, revnum)
+        return self.branchprop_cache[key]
+
+    def _get_branch_prop(self, path, revnum, name, default=None):
+        props = self._get_branch_proplist(path, revnum)
+        if props.has_key(name):
+            return props[name]
+        return default
+
     def _get_dir_proplist(self, path, revnum):
         (props, _) = self._cache_get_dir(path, revnum)
         return props
@@ -568,7 +607,7 @@ class SvnRepository(Repository):
         assert isinstance(revnum, int)
         assert isinstance(path, basestring)
 
-        (props, _) = self._cache_get_dir(path, revnum)
+        props = self._get_dir_proplist(path, revnum)
         if props.has_key(name):
             return props[name]
         return default