Support custom user options for repository config.
authorJelmer Vernooij <jelmer@samba.org>
Tue, 30 Oct 2007 19:49:37 +0000 (20:49 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 30 Oct 2007 19:49:37 +0000 (20:49 +0100)
config.py
repository.py
tests/test_repos.py

index 5ffba744ab76c2156d73ccc25c4de86173a543d2..91836e2e1bac53fb8153b41e67fe784b73990faf 100644 (file)
--- a/config.py
+++ b/config.py
@@ -16,7 +16,7 @@
 """Stores per-repository settings."""
 
 from bzrlib import osutils
-from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists
+from bzrlib.config import IniBasedConfig, config_dir, ensure_config_dir_exists, GlobalConfig
 
 import os
 
@@ -30,6 +30,7 @@ def subversion_config_filename():
     """Return per-user configuration ini file filename."""
     return osutils.pathjoin(config_dir(), 'subversion.conf')
 
+
 class SvnRepositoryConfig(IniBasedConfig):
     """Per-repository settings."""
 
@@ -47,25 +48,30 @@ class SvnRepositoryConfig(IniBasedConfig):
         """
         self.set_user_option('branching-scheme', str(scheme))
 
+    def _get_user_option(self, name, use_global=True):
+        try:
+            return self._get_parser()[self.uuid][name]
+        except KeyError:
+            if not use_global:
+                return None
+            return GlobalConfig()._get_user_option(name)
+
     def get_branching_scheme(self):
         """Get the branching scheme.
 
         :return: BranchingScheme instance.
         """
-        try:
-            return BranchingScheme.find_scheme(self._get_parser()[self.uuid]['branching-scheme'])
-        except KeyError:
-            return None
+        return BranchingScheme.find_scheme(self._get_user_option("branching-scheme", use_global=False))
 
     def get_locations(self):
         """Find the locations this repository has been seen at.
 
         :return: Set with URLs.
         """
-        try:
-            return set(self._get_parser()[self.uuid]['locations'].split(";"))
-        except KeyError:
+        val = self._get_user_option("locations", use_global=False)
+        if val is None:
             return set()
+        return set(val.split(";"))
 
     def add_location(self, location):
         """Add a location for this repository.
index 2941291d0db89d1dae9ad0b1476da984e21c972b..c69089a0b427e753453ec033a4410f95a262a417 100644 (file)
@@ -287,8 +287,7 @@ class SvnRepository(Repository):
         self._serializer = None
         self.dir_cache = {}
         self.pool = Pool()
-        self.config = SvnRepositoryConfig(self.uuid)
-        self.config.add_location(self.base)
+        self.get_config().add_location(self.base)
         self._revids_seen = {}
         cache_dir = self.create_cache_dir()
         cachedir_transport = get_transport(cache_dir)
@@ -327,7 +326,7 @@ class SvnRepository(Repository):
         if self._scheme is not None:
             return self._scheme
 
-        scheme = self.config.get_branching_scheme()
+        scheme = self.get_config().get_branching_scheme()
         if scheme is not None:
             self._scheme = scheme
             return scheme
@@ -375,7 +374,7 @@ class SvnRepository(Repository):
     def set_branching_scheme(self, scheme, store=True):
         self._scheme = scheme
         if store:
-            self.config.set_branching_scheme(str(scheme))
+            self.get_config().set_branching_scheme(str(scheme))
 
     def _warn_if_deprecated(self):
         # This class isn't deprecated
@@ -945,6 +944,9 @@ class SvnRepository(Repository):
                      
             yield (bp, paths, revnum)
 
+    def get_config(self):
+        return SvnRepositoryConfig(self.uuid)
+
     def has_signature_for_revision_id(self, revision_id):
         """Check whether a signature exists for a particular revision id.
 
index 6e5104a8a0bbba628555f1d6e22245de6aae14f7..d49da6f1bcbc56e5608704e1c5670918b169a361 100644 (file)
@@ -20,6 +20,7 @@
 
 from bzrlib.branch import Branch
 from bzrlib.bzrdir import BzrDir, format_registry
+from bzrlib.config import GlobalConfig
 from bzrlib.errors import NoSuchRevision, UninitializableFormat, BzrError
 from bzrlib.inventory import Inventory
 from bzrlib.repository import Repository
@@ -74,6 +75,25 @@ class TestSubversionRepositoryWorks(TestCaseWithSubversionRepository):
         repos = Repository.open(repos_url)
         self.assertFalse(repos.make_working_trees())
 
+    def test_get_config_global_set(self):
+        repos_url = self.make_client("a", "dc")
+        cfg = GlobalConfig()
+        cfg.set_user_option("foo", "Still Life")
+
+        repos = Repository.open(repos_url)
+        self.assertEquals("Still Life", 
+                repos.get_config().get_user_option("foo"))
+
+    def test_get_config(self):
+        repos_url = self.make_client("a", "dc")
+        repos = Repository.open(repos_url)
+        repos.get_config().set_user_option("foo", "Van Der Graaf Generator")
+
+        repos = Repository.open(repos_url)
+        self.assertEquals("Van Der Graaf Generator", 
+                repos.get_config().get_user_option("foo"))
+
+
     def test_get_physical_lock_status(self):
         repos_url = self.make_client("a", "dc")
         repos = Repository.open(repos_url)