Use StackedConfig in Repo.get_config.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 26 Dec 2011 17:11:47 +0000 (18:11 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 26 Dec 2011 17:11:47 +0000 (18:11 +0100)
dulwich/config.py
dulwich/repo.py
dulwich/tests/test_config.py
dulwich/tests/test_repository.py

index e14c7d8d057c26044f3a72a6611115219ee19888..c0640f7649d84a5c581cdcaa5b1234760042f38f 100644 (file)
@@ -158,7 +158,7 @@ class StackedConfig(Config):
         return "<%s for %r>" % (self.__class__.__name__, self._backends)
 
     @classmethod
-    def default(cls, for_path=None):
+    def default_backends(cls):
         """Retrieve the default configuration.
 
         This will look in the repository configuration (if for_path is
@@ -166,21 +166,19 @@ class StackedConfig(Config):
         configuration.
         """
         paths = []
-        if for_path is not None:
-            paths.append(for_path)
         paths.append(os.path.expanduser("~/.gitconfig"))
         paths.append("/etc/gitconfig")
         backends = []
         for path in paths:
             try:
                 cf = ConfigFile.from_path(path)
-            except IOError, e:
+            except (IOError, OSError), e:
                 if e.errno != errno.ENOENT:
                     raise
                 else:
                     continue
             backends.append(cf)
-        return cls(backends)
+        return backends
 
     def get(self, name):
         for backend in self._backends:
index 81730c930539209131a96aa85f1a7d95c0faed59..42c3c2a00289e29c43d91aa3d8cd2d7a49db84df 100644 (file)
@@ -921,15 +921,15 @@ class BaseRepo(object):
         return self.commit(sha).parents
 
     def get_config(self):
-        from dulwich.config import ConfigFile
+        from dulwich.config import ConfigFile, StackedConfig
+        backends = []
         try:
             p = ConfigFile.from_path(os.path.join(self._controldir, 'config'))
         except (IOError, OSError), e:
-            if e.errno == errno.ENOENT:
-                return ConfigFile()
-            raise
-        return dict((section, dict(p.items(section)))
-                    for section in p.sections())
+            if e.errno != errno.ENOENT:
+                raise
+        backends.extend(StackedConfig.default_backends())
+        return StackedConfig(backends)
 
     def commit(self, sha):
         """Retrieve the commit with a particular SHA.
index 3830b1b4dd815a51434c4e0effc97d58d6c9570b..15c92229808a6e0c2d1cc331b20b0e74b7a2033b 100644 (file)
@@ -44,5 +44,5 @@ class ConfigFileTests(TestCase):
 
 class StackedConfigTests(TestCase):
 
-    def test_default(self):
-        StackedConfig.default()
+    def test_default_backends(self):
+        StackedConfig.default_backends()
index d40249ec298b28bfc068814136c5691aa1368b5e..30ec2da2c4e1842d6e4abe697553297e36498afc 100644 (file)
@@ -33,7 +33,7 @@ from dulwich.object_store import (
     tree_lookup_path,
     )
 from dulwich import objects
-from dulwich.config import ConfigFile
+from dulwich.config import Config
 from dulwich.repo import (
     check_ref_format,
     DictRefsContainer,
@@ -321,7 +321,7 @@ class RepositoryTests(TestCase):
 
     def test_get_config(self):
         r = self._repo = open_repo('ooo_merge.git')
-        self.assertEquals(ConfigFile(), r.get_config())
+        self.assertIsInstance(r.get_config(), Config)
 
     def test_common_revisions(self):
         """