浏览代码

Split out Repo.get_config_stack().

Jelmer Vernooij 13 年之前
父节点
当前提交
31cd7d9256
共有 2 个文件被更改,包括 15 次插入9 次删除
  1. 11 9
      dulwich/repo.py
  2. 4 0
      dulwich/tests/test_repository.py

+ 11 - 9
dulwich/repo.py

@@ -921,19 +921,21 @@ class BaseRepo(object):
         return self.commit(sha).parents
 
     def get_config(self):
-        from dulwich.config import ConfigFile, StackedConfig
-        backends = []
+        from dulwich.config import ConfigFile
+        path = os.path.join(self._controldir, 'config')
         try:
-            p = ConfigFile.from_path(os.path.join(self._controldir, 'config'))
+            return ConfigFile.from_path(path)
         except (IOError, OSError), e:
             if e.errno != errno.ENOENT:
                 raise
-            writable = None
-        else:
-            writable = p
-            backends.append(p)
-        backends.extend(StackedConfig.default_backends())
-        return StackedConfig(backends)
+            ret = ConfigFile()
+            ret.path = path
+            return ret
+
+    def get_config_stack(self):
+        from dulwich.config import StackedConfig
+        backends = [self.get_config()] + StackedConfig.default_backends()
+        return StackedConfig(backends, writable=backends[0])
 
     def commit(self, sha):
         """Retrieve the commit with a particular SHA.

+ 4 - 0
dulwich/tests/test_repository.py

@@ -323,6 +323,10 @@ class RepositoryTests(TestCase):
         r = self._repo = open_repo('ooo_merge.git')
         self.assertIsInstance(r.get_config(), Config)
 
+    def test_get_config_stack(self):
+        r = self._repo = open_repo('ooo_merge.git')
+        self.assertIsInstance(r.get_config_stack(), Config)
+
     def test_common_revisions(self):
         """
         This test demonstrates that ``find_common_revisions()`` actually returns