diff options
| author | Sebastian Thiel <byronimo@gmail.com> | 2011-05-04 19:33:36 +0200 |
|---|---|---|
| committer | Sebastian Thiel <byronimo@gmail.com> | 2011-05-04 19:33:36 +0200 |
| commit | d20dadfde5824dcabda351f75a6784d616b2fd23 (patch) | |
| tree | 8b75a3bab4a76d57cacb53b5cb54f20e23951a3a /gitdb | |
| parent | e24994109f01bd315fd6a2aaecbbfcdd05bd0586 (diff) | |
| download | gitdb-d20dadfde5824dcabda351f75a6784d616b2fd23.tar.gz | |
First rename session, db/test_base.py works, but there is much more work to do
Diffstat (limited to 'gitdb')
| -rw-r--r-- | gitdb/db/py/__init__.py | 3 | ||||
| -rw-r--r-- | gitdb/db/py/base.py | 8 | ||||
| -rw-r--r-- | gitdb/db/py/git.py | 46 | ||||
| -rw-r--r-- | gitdb/db/py/loose.py | 14 | ||||
| -rw-r--r-- | gitdb/db/py/mem.py | 18 | ||||
| -rw-r--r-- | gitdb/db/py/pack.py | 14 | ||||
| -rw-r--r-- | gitdb/db/py/ref.py | 16 | ||||
| -rw-r--r-- | gitdb/db/py/resolve.py | 2 | ||||
| -rw-r--r-- | gitdb/test/db/lib.py | 7 | ||||
| -rw-r--r-- | gitdb/test/db/test_loose.py | 4 | ||||
| -rw-r--r-- | gitdb/test/db/test_mem.py | 4 | ||||
| -rw-r--r-- | gitdb/test/lib.py | 13 | ||||
| -rw-r--r-- | gitdb/test/performance/test_stream.py | 2 | ||||
| -rw-r--r-- | gitdb/test/test_example.py | 4 | ||||
| -rw-r--r-- | gitdb/test/test_stream.py | 2 |
15 files changed, 81 insertions, 76 deletions
diff --git a/gitdb/db/py/__init__.py b/gitdb/db/py/__init__.py index e5935b7..046c699 100644 --- a/gitdb/db/py/__init__.py +++ b/gitdb/db/py/__init__.py @@ -9,4 +9,5 @@ from mem import * from pack import * from git import * from ref import * - +from resolve import * +from transport import * diff --git a/gitdb/db/py/base.py b/gitdb/db/py/base.py index a9296f0..a369552 100644 --- a/gitdb/db/py/base.py +++ b/gitdb/db/py/base.py @@ -35,8 +35,8 @@ import sys import os -__all__ = ( 'PureObjectDBR', 'PureObjectDBW', 'PureRootPathDBBase', 'PureCompoundDB', - 'NameResolveMixin', 'PureConfigurationMixin', 'PureRepositoryPathsMixin') +__all__ = ( 'PureObjectDBR', 'PureObjectDBW', 'PureRootPathDB', 'PureCompoundDB', + 'PureConfigurationMixin', 'PureRepositoryPathsMixin') class PureObjectDBR(ObjectDBR): @@ -83,10 +83,10 @@ class PureObjectDBW(ObjectDBW): #} END edit interface -class PureRootPathDBBase(RootPathDBBase): +class PureRootPathDB(RootPathDB): def __init__(self, root_path): - super(PureRootPathDBBase, self).__init__() + super(PureRootPathDB, self).__init__(root_path) self._root_path = root_path diff --git a/gitdb/db/py/git.py b/gitdb/db/py/git.py index d8eced5..bc148c6 100644 --- a/gitdb/db/py/git.py +++ b/gitdb/db/py/git.py @@ -1,20 +1,20 @@ # Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors # -# This module is part of GitDB and is released under +# This module is part of PureGitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php from base import ( - CompoundDB, - ObjectDBW, - RootPathDBBase, - RepositoryPathsMixin, - ConfigurationMixin, + PureCompoundDB, + PureObjectDBW, + PureRootPathDB, + PureRepositoryPathsMixin, + PureConfigurationMixin, ) -from resolve import NameResolvePureMixin +from resolve import PureReferencesMixin -from loose import LooseObjectDB -from pack import PackedDB -from ref import ReferenceDB +from loose import PureLooseObjectODB +from pack import PurePackedODB +from ref import PureReferenceDB from gitdb.util import ( LazyMixin, @@ -29,19 +29,19 @@ from gitdb.exc import ( ) import os -__all__ = ('GitODB', 'GitDB') +__all__ = ('PureGitODB', 'PureGitDB') -class GitODB(RootPathDBBase, ObjectDBW, CompoundDB): +class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB): """A git-style object-only database, which contains all objects in the 'objects' subdirectory. :note: The type needs to be initialized on the ./objects directory to function, - as it deals solely with object lookup. Use a GitDB type if you need + as it deals solely with object lookup. Use a PureGitDB type if you need reference and push support.""" # Configuration - PackDBCls = PackedDB - LooseDBCls = LooseObjectDB - ReferenceDBCls = ReferenceDB + PackDBCls = PurePackedODB + LooseDBCls = PureLooseObjectODB + PureReferenceDBCls = PureReferenceDB # Directories packs_dir = 'pack' @@ -50,7 +50,7 @@ class GitODB(RootPathDBBase, ObjectDBW, CompoundDB): def __init__(self, root_path): """Initialize ourselves on a git ./objects directory""" - super(GitODB, self).__init__(root_path) + super(PureGitODB, self).__init__(root_path) def _set_cache_(self, attr): if attr == '_dbs' or attr == '_loose_db': @@ -58,7 +58,7 @@ class GitODB(RootPathDBBase, ObjectDBW, CompoundDB): loose_db = None for subpath, dbcls in ((self.packs_dir, self.PackDBCls), (self.loose_dir, self.LooseDBCls), - (self.alternates_dir, self.ReferenceDBCls)): + (self.alternates_dir, self.PureReferenceDBCls)): path = self.db_path(subpath) if os.path.exists(path): self._dbs.append(dbcls(path)) @@ -79,10 +79,10 @@ class GitODB(RootPathDBBase, ObjectDBW, CompoundDB): # finally set the value self._loose_db = loose_db else: - super(GitODB, self)._set_cache_(attr) + super(PureGitODB, self)._set_cache_(attr) # END handle attrs - #{ ObjectDBW interface + #{ PureObjectDBW interface def store(self, istream): return self._loose_db.store(istream) @@ -96,7 +96,7 @@ class GitODB(RootPathDBBase, ObjectDBW, CompoundDB): #} END objectdbw interface -class GitDB(GitODB, RepositoryPathsMixin, ConfigurationMixin, NameResolvePureMixin): +class PureGitDB(PureGitODB, PureRepositoryPathsMixin, PureConfigurationMixin, PureReferencesMixin): """Git like database with support for object lookup as well as reference resolution. Our rootpath is set to the actual .git directory (bare on unbare). @@ -106,8 +106,8 @@ class GitDB(GitODB, RepositoryPathsMixin, ConfigurationMixin, NameResolvePureMix def __init__(self, root_path): """Initialize ourselves on the .git directory, or the .git/objects directory.""" - RepositoryPathsMixin._initialize(self, root_path) - super(GitDB, self).__init__(self.objects_path()) + PureRepositoryPathsMixin._initialize(self, root_path) + super(PureGitDB, self).__init__(self.objects_path()) diff --git a/gitdb/db/py/loose.py b/gitdb/db/py/loose.py index 16a3c4e..34e31da 100644 --- a/gitdb/db/py/loose.py +++ b/gitdb/db/py/loose.py @@ -3,9 +3,9 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php from base import ( - RootPathDBBase, - ObjectDBR, - ObjectDBW + PureRootPathDB, + PureObjectDBR, + PureObjectDBW ) @@ -57,10 +57,10 @@ import sys import os -__all__ = ( 'LooseObjectDB', ) +__all__ = ( 'PureLooseObjectODB', ) -class LooseObjectDB(RootPathDBBase, ObjectDBR, ObjectDBW): +class PureLooseObjectODB(PureRootPathDB, PureObjectDBR, PureObjectDBW): """A database which operates on loose object files""" # CONFIGURATION @@ -75,7 +75,7 @@ class LooseObjectDB(RootPathDBBase, ObjectDBR, ObjectDBW): def __init__(self, root_path): - super(LooseObjectDB, self).__init__(root_path) + super(PureLooseObjectODB, self).__init__(root_path) self._hexsha_to_file = dict() # Additional Flags - might be set to 0 after the first failure # Depending on the root, this might work for some mounts, for others not, which @@ -156,7 +156,7 @@ class LooseObjectDB(RootPathDBBase, ObjectDBR, ObjectDBW): """:raise TypeError: if the stream does not support the Sha1Writer interface""" if stream is not None and not isinstance(stream, Sha1Writer): raise TypeError("Output stream musst support the %s interface" % Sha1Writer.__name__) - return super(LooseObjectDB, self).set_ostream(stream) + return super(PureLooseObjectODB, self).set_ostream(stream) def info(self, sha): m = self._map_loose_object(sha) diff --git a/gitdb/db/py/mem.py b/gitdb/db/py/mem.py index 8012ad1..ba922e9 100644 --- a/gitdb/db/py/mem.py +++ b/gitdb/db/py/mem.py @@ -3,10 +3,10 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Contains the MemoryDatabase implementation""" -from loose import LooseObjectDB +from loose import PureLooseObjectODB from base import ( - ObjectDBR, - ObjectDBW + PureObjectDBR, + PureObjectDBW ) from gitdb.base import ( @@ -25,9 +25,9 @@ from gitdb.stream import ( from cStringIO import StringIO -__all__ = ("MemoryDB", ) +__all__ = ("PureMemoryDB", ) -class MemoryDB(ObjectDBR, ObjectDBW): +class PureMemoryDB(PureObjectDBR, PureObjectDBW): """A memory database stores everything to memory, providing fast IO and object retrieval. It should be used to buffer results and obtain SHAs before writing it to the actual physical storage, as it allows to query whether object already @@ -37,14 +37,14 @@ class MemoryDB(ObjectDBR, ObjectDBW): for storing""" def __init__(self): - super(MemoryDB, self).__init__() - self._db = LooseObjectDB("path/doesnt/matter") + super(PureMemoryDB, self).__init__() + self._db = PureLooseObjectODB("path/doesnt/matter") # maps 20 byte shas to their OStream objects self._cache = dict() def set_ostream(self, stream): - raise UnsupportedOperation("MemoryDB's always stream into memory") + raise UnsupportedOperation("PureMemoryDB's always stream into memory") def store(self, istream): zstream = ZippedStoreShaWriter() @@ -62,7 +62,7 @@ class MemoryDB(ObjectDBR, ObjectDBW): return istream def store_async(self, reader): - raise UnsupportedOperation("MemoryDBs cannot currently be used for async write access") + raise UnsupportedOperation("PureMemoryDBs cannot currently be used for async write access") def has_object(self, sha): return sha in self._cache diff --git a/gitdb/db/py/pack.py b/gitdb/db/py/pack.py index 53c912e..1d0e9bf 100644 --- a/gitdb/db/py/pack.py +++ b/gitdb/db/py/pack.py @@ -3,10 +3,10 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Module containing a database to deal with packs""" +from gitdb.db import CachingDB from base import ( - RootPathDBBase, - ObjectDBR, - CachingDB + PureRootPathDB, + PureObjectDBR ) from gitdb.util import LazyMixin @@ -22,12 +22,12 @@ from gitdb.pack import PackEntity import os import glob -__all__ = ('PackedDB', ) +__all__ = ('PurePackedODB', ) #{ Utilities -class PackedDB(RootPathDBBase, ObjectDBR, CachingDB, LazyMixin): +class PurePackedODB(PureRootPathDB, PureObjectDBR, CachingDB, LazyMixin): """A database operating on a set of object packs""" # the type to use when instantiating a pack entity @@ -39,7 +39,7 @@ class PackedDB(RootPathDBBase, ObjectDBR, CachingDB, LazyMixin): _sort_interval = 500 def __init__(self, root_path): - super(PackedDB, self).__init__(root_path) + super(PurePackedODB, self).__init__(root_path) # list of lists with three items: # * hits - number of times the pack was hit with a request # * entity - Pack entity instance @@ -127,7 +127,7 @@ class PackedDB(RootPathDBBase, ObjectDBR, CachingDB, LazyMixin): raise UnsupportedOperation() def store_async(self, reader): - # TODO: add ObjectDBRW before implementing this + # TODO: add PureObjectDBRW before implementing this raise NotImplementedError() #} END object db write diff --git a/gitdb/db/py/ref.py b/gitdb/db/py/ref.py index feb7fdc..5825d9e 100644 --- a/gitdb/db/py/ref.py +++ b/gitdb/db/py/ref.py @@ -2,14 +2,12 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from base import ( - CompoundDB, - ) +from base import PureCompoundDB import os -__all__ = ('ReferenceDB', ) +__all__ = ('PureReferenceDB', ) -class ReferenceDB(CompoundDB): +class PureReferenceDB(PureCompoundDB): """A database consisting of database referred to in a file""" # Configuration @@ -18,7 +16,7 @@ class ReferenceDB(CompoundDB): ObjectDBCls = None def __init__(self, ref_file): - super(ReferenceDB, self).__init__() + super(PureReferenceDB, self).__init__() self._ref_file = ref_file def _set_cache_(self, attr): @@ -26,7 +24,7 @@ class ReferenceDB(CompoundDB): self._dbs = list() self._update_dbs_from_ref_file() else: - super(ReferenceDB, self)._set_cache_(attr) + super(PureReferenceDB, self)._set_cache_(attr) # END handle attrs def _update_dbs_from_ref_file(self): @@ -64,7 +62,7 @@ class ReferenceDB(CompoundDB): try: db = dbcls(path) # force an update to verify path - if isinstance(db, CompoundDB): + if isinstance(db, PureCompoundDB): db.databases() # END verification self._dbs.append(db) @@ -76,4 +74,4 @@ class ReferenceDB(CompoundDB): def update_cache(self, force=False): # re-read alternates and update databases self._update_dbs_from_ref_file() - return super(ReferenceDB, self).update_cache(force) + return super(PureReferenceDB, self).update_cache(force) diff --git a/gitdb/db/py/resolve.py b/gitdb/db/py/resolve.py index b3d6e4b..1e7aece 100644 --- a/gitdb/db/py/resolve.py +++ b/gitdb/db/py/resolve.py @@ -17,7 +17,7 @@ from string import digits import os import re -__all__ = ["NameResolvePureMixin"] +__all__ = ["PureReferencesMixin"] #{ Utilities diff --git a/gitdb/test/db/lib.py b/gitdb/test/db/lib.py index 416c8c5..5f4f9c3 100644 --- a/gitdb/test/db/lib.py +++ b/gitdb/test/db/lib.py @@ -13,6 +13,10 @@ from gitdb.test.lib import ( from gitdb.stream import Sha1Writer +# import database types we want to support +# they will be set to None if the respective library could not be loaded +from gitdb.db.py import PureGitDB + from gitdb.base import ( IStream, OStream, @@ -36,6 +40,9 @@ class TestDBBase(TestBase): two_lines = "1234\nhello world" all_data = (two_lines, ) + # all supported database types. Add your own type + ref_db_types = (PureGitDB, ) + def _assert_object_writing_simple(self, db): # write a bunch of objects and query their streams and info null_objs = db.size() diff --git a/gitdb/test/db/test_loose.py b/gitdb/test/db/test_loose.py index ee2d78d..49353dc 100644 --- a/gitdb/test/db/test_loose.py +++ b/gitdb/test/db/test_loose.py @@ -3,7 +3,7 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php from lib import * -from gitdb.db import LooseObjectDB +from gitdb.db import PureLooseObjectODB from gitdb.exc import BadObject from gitdb.util import bin_to_hex @@ -11,7 +11,7 @@ class TestLooseDB(TestDBBase): @with_rw_directory def test_basics(self, path): - ldb = LooseObjectDB(path) + ldb = PureLooseObjectODB(path) # write data self._assert_object_writing(ldb) diff --git a/gitdb/test/db/test_mem.py b/gitdb/test/db/test_mem.py index 188cb0a..f88fca7 100644 --- a/gitdb/test/db/test_mem.py +++ b/gitdb/test/db/test_mem.py @@ -5,7 +5,7 @@ from lib import * from gitdb.db import ( MemoryDB, - LooseObjectDB + PureLooseObjectODB ) class TestMemoryDB(TestDBBase): @@ -18,7 +18,7 @@ class TestMemoryDB(TestDBBase): self._assert_object_writing_simple(mdb) # test stream copy - ldb = LooseObjectDB(path) + ldb = PureLooseObjectODB(path) assert ldb.size() == 0 num_streams_copied = mdb.stream_copy(mdb.sha_iter(), ldb) assert num_streams_copied == mdb.size() diff --git a/gitdb/test/lib.py b/gitdb/test/lib.py index cdadaa7..9224f5f 100644 --- a/gitdb/test/lib.py +++ b/gitdb/test/lib.py @@ -1,12 +1,10 @@ # Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors # -# This module is part of GitDB and is released under +# This module is part of PureGitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Utilities used in ODB testing""" -from gitdb import ( - OStream, - GitDB - ) +from gitdb import OStream +from gitdb.db.py import PureGitDB from gitdb.stream import ( Sha1Writer, ZippedStoreShaWriter @@ -72,7 +70,7 @@ def with_rw_repo(func): shutil.copytree(src_dir, path) target_gitdir = os.path.join(path, '.git') assert os.path.isdir(target_gitdir) - return func(self, GitDB(target_gitdir)) + return func(self, PureGitDB(target_gitdir)) #END wrapper wrapper.__name__ = func.__name__ return with_rw_directory(wrapper) @@ -195,7 +193,8 @@ class DeriveTest(OStream): class TestBase(unittest.TestCase): """Base class for all tests""" - rorepo = GitDB(repo_dir()) + # The non-database specific tests just provides a default pure git database + rorepo = PureGitDB(repo_dir()) #} END bases diff --git a/gitdb/test/performance/test_stream.py b/gitdb/test/performance/test_stream.py index f5f2e2e..0a5537c 100644 --- a/gitdb/test/performance/test_stream.py +++ b/gitdb/test/performance/test_stream.py @@ -65,7 +65,7 @@ class TestObjDBPerformance(TestBigRepoR): @with_rw_directory def test_large_data_streaming(self, path): - ldb = LooseObjectDB(path) + ldb = PureLooseObjectODB(path) string_ios = list() # list of streams we previously created # serial mode diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index 7531775..e1a489e 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -5,7 +5,7 @@ """Module with examples from the tutorial section of the docs""" from lib import * from gitdb import IStream -from gitdb.db import LooseObjectDB +from gitdb.db import PureLooseObjectODB from gitdb.util import pool from cStringIO import StringIO @@ -15,7 +15,7 @@ from async import IteratorReader class TestExamples(TestBase): def test_base(self): - ldb = LooseObjectDB(fixture_path("../../../.git/objects")) + ldb = PureLooseObjectODB(fixture_path("../../../.git/objects")) for sha1 in ldb.sha_iter(): oinfo = ldb.info(sha1) diff --git a/gitdb/test/test_stream.py b/gitdb/test/test_stream.py index 523f770..50534d0 100644 --- a/gitdb/test/test_stream.py +++ b/gitdb/test/test_stream.py @@ -145,7 +145,7 @@ class TestStream(TestBase): # END for each os def test_decompress_reader_special_case(self): - odb = LooseObjectDB(fixture_path('objects')) + odb = PureLooseObjectODB(fixture_path('objects')) ostream = odb.stream(hex_to_bin('7bb839852ed5e3a069966281bb08d50012fb309b')) # if there is a bug, we will be missing one byte exactly ! |
