Ver código fonte

Add DiskObjectStore.init.

Jelmer Vernooij 15 anos atrás
pai
commit
bcecb9cbf4
3 arquivos alterados com 13 adições e 4 exclusões
  1. 11 0
      dulwich/object_store.py
  2. 1 3
      dulwich/repo.py
  3. 1 1
      dulwich/tests/test_object_store.py

+ 11 - 0
dulwich/object_store.py

@@ -477,6 +477,17 @@ class DiskObjectStore(PackBasedObjectStore):
         finally:
             f.close()
 
+    @classmethod
+    def init(cls, path):
+        try:
+            os.mkdir(path)
+        except OSError, e:
+            if e.errno != errno.EEXIST:
+                raise
+        os.mkdir(os.path.join(path, "info"))
+        os.mkdir(os.path.join(path, PACKDIR))
+        return cls(path)
+
 
 class MemoryObjectStore(BaseObjectStore):
     """Object store that keeps all objects in memory."""

+ 1 - 3
dulwich/repo.py

@@ -62,9 +62,6 @@ REFSDIR_HEADS = 'heads'
 INDEX_FILENAME = "index"
 
 BASE_DIRECTORIES = [
-    [OBJECTDIR], 
-    [OBJECTDIR, "info"], 
-    [OBJECTDIR, "pack"],
     ["branches"],
     [REFSDIR],
     [REFSDIR, REFSDIR_TAGS],
@@ -1016,6 +1013,7 @@ class Repo(BaseRepo):
     def init_bare(cls, path, mkdir=True):
         for d in BASE_DIRECTORIES:
             os.mkdir(os.path.join(path, *d))
+        DiskObjectStore.init(os.path.join(path, OBJECTDIR))
         ret = cls(path)
         ret.refs.set_symbolic_ref("HEAD", "refs/heads/master")
         ret._put_named_file('description', "Unnamed repository")

+ 1 - 1
dulwich/tests/test_object_store.py

@@ -103,7 +103,7 @@ class DiskObjectStoreTests(ObjectStoreTests,TestCase):
     def setUp(self):
         TestCase.setUp(self)
         self.store_dir = tempfile.mkdtemp()
-        self.store = DiskObjectStore(self.store_dir)
+        self.store = DiskObjectStore.init(self.store_dir)
 
     def tearDown(self):
         TestCase.tearDown(self)