From 230323f5d441b182467e624cd93b3fc07d8ecbf7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 11 Apr 2010 02:43:17 +0200 Subject: [PATCH] Add DiskObjectStore.init. --- dulwich/object_store.py | 11 +++++++++++ dulwich/repo.py | 4 +--- dulwich/tests/test_object_store.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dulwich/object_store.py b/dulwich/object_store.py index d3e7031..6456f6b 100644 --- a/dulwich/object_store.py +++ b/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.""" diff --git a/dulwich/repo.py b/dulwich/repo.py index cff17e7..a69760e 100644 --- a/dulwich/repo.py +++ b/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") diff --git a/dulwich/tests/test_object_store.py b/dulwich/tests/test_object_store.py index 94dbe6a..d8bd45c 100644 --- a/dulwich/tests/test_object_store.py +++ b/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) -- 2.34.1