Преглед на файлове

Use StackedConfig in Repo.get_config.

Jelmer Vernooij преди 13 години
родител
ревизия
7b3d7c67e4
променени са 4 файла, в които са добавени 13 реда и са изтрити 15 реда
  1. 3 5
      dulwich/config.py
  2. 6 6
      dulwich/repo.py
  3. 2 2
      dulwich/tests/test_config.py
  4. 2 2
      dulwich/tests/test_repository.py

+ 3 - 5
dulwich/config.py

@@ -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:

+ 6 - 6
dulwich/repo.py

@@ -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.

+ 2 - 2
dulwich/tests/test_config.py

@@ -44,5 +44,5 @@ class ConfigFileTests(TestCase):
 
 class StackedConfigTests(TestCase):
 
-    def test_default(self):
-        StackedConfig.default()
+    def test_default_backends(self):
+        StackedConfig.default_backends()

+ 2 - 2
dulwich/tests/test_repository.py

@@ -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):
         """