From 1f71ed94578799ee1667ba54b66a369e307f415b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 30 May 2011 16:32:56 +0200 Subject: git cmd implementation of repository appears to work, at least this is what the test suggests. Pure python implementation still has some trouble, but this should be very fixable --- git/db/cmd/base.py | 30 ++++++++++-------- git/db/cmd/complex.py | 13 +------- git/db/complex.py | 19 ++++++++++-- git/db/py/base.py | 9 ++++-- git/db/py/complex.py | 16 +++++----- git/db/py/resolve.py | 3 +- git/exc.py | 4 +-- git/objects/base.py | 17 +++++++--- git/objects/submodule/base.py | 2 +- git/refs/reference.py | 2 +- git/refs/symbolic.py | 6 ++-- git/repo.py | 2 +- git/test/db/base.py | 32 ++++++++++--------- git/test/db/cmd/test_base.py | 23 ++++++++------ git/test/db/py/test_base.py | 21 +++++++++---- git/test/db/py/test_git.py | 47 ++++++++++++++++++++++++++++ git/test/db/py/test_loose.py | 34 ++++++++++++++++++++ git/test/db/py/test_mem.py | 30 ++++++++++++++++++ git/test/db/py/test_pack.py | 72 +++++++++++++++++++++++++++++++++++++++++++ git/test/db/py/test_ref.py | 60 ++++++++++++++++++++++++++++++++++++ git/test/db/test_git.py | 47 ---------------------------- git/test/db/test_loose.py | 34 -------------------- git/test/db/test_mem.py | 30 ------------------ git/test/db/test_pack.py | 72 ------------------------------------------- git/test/db/test_ref.py | 60 ------------------------------------ git/test/lib/base.py | 2 +- 26 files changed, 361 insertions(+), 326 deletions(-) create mode 100644 git/test/db/py/test_git.py create mode 100644 git/test/db/py/test_loose.py create mode 100644 git/test/db/py/test_mem.py create mode 100644 git/test/db/py/test_pack.py create mode 100644 git/test/db/py/test_ref.py delete mode 100644 git/test/db/test_git.py delete mode 100644 git/test/db/test_loose.py delete mode 100644 git/test/db/test_mem.py delete mode 100644 git/test/db/test_pack.py delete mode 100644 git/test/db/test_ref.py (limited to 'git') diff --git a/git/db/cmd/base.py b/git/db/cmd/base.py index 6a2473a3..b3354b0a 100644 --- a/git/db/cmd/base.py +++ b/git/db/cmd/base.py @@ -13,16 +13,16 @@ from git.base import ( from git.util import ( bin_to_hex, - hex_to_bin - ) -from git.db.compat import RepoCompatibilityInterface -from git.util import RemoteProgress + hex_to_bin, + RemoteProgress, + isfile, + join_path, + join, + Actor + ) from git.db.interface import FetchInfo as GitdbFetchInfo from git.db.interface import PushInfo as GitdbPushInfo from git.db.interface import HighLevelRepository - -from git.util import join_path -from git.util import join from git.cmd import Git from git.refs import ( Reference, @@ -30,8 +30,9 @@ from git.refs import ( SymbolicReference, TagReference ) - +from git.objects.commit import Commit import re +import os import sys @@ -472,6 +473,11 @@ class CmdHighLevelRepository(HighLevelRepository): re_author_committer_start = re.compile(r'^(author|committer)') re_tab_full_line = re.compile(r'^\t(.*)$') + #{ Configuration + CommitCls = Commit + GitCls = Git + #} END configuration + def daemon_export(): def _get_daemon_export(self): filename = join(self.git_dir, self.DAEMON_EXPORT_FILE) @@ -588,7 +594,7 @@ class CmdHighLevelRepository(HighLevelRepository): sha = info['id'] c = commits.get(sha) if c is None: - c = Commit( self, hex_to_bin(sha), + c = self.CommitCls( self, hex_to_bin(sha), author=Actor._from_string(info['author'] + ' ' + info['author_email']), authored_date=info['author_date'], committer=Actor._from_string(info['committer'] + ' ' + info['committer_email']), @@ -619,9 +625,9 @@ class CmdHighLevelRepository(HighLevelRepository): os.makedirs(path, 0755) # git command automatically chdir into the directory - git = Git(path) + git = cls.GitCls(path) output = git.init(**kwargs) - return Repo(path) + return cls(path) @classmethod def _clone(cls, git, url, path, **kwargs): @@ -686,7 +692,7 @@ class CmdHighLevelRepository(HighLevelRepository): """ :param kwargs: see the ``clone`` method For more information, see the respective method in the HighLevelRepository""" - return cls._clone(type(self.git)(os.getcwd()), url, to_path, **kwargs) + return cls._clone(cls.GitCls(os.getcwd()), url, to_path, **kwargs) def archive(self, ostream, treeish=None, prefix=None, **kwargs): """For all args see HighLevelRepository interface diff --git a/git/db/cmd/complex.py b/git/db/cmd/complex.py index 3e6804f5..49e8c590 100644 --- a/git/db/cmd/complex.py +++ b/git/db/cmd/complex.py @@ -1,12 +1,10 @@ """Module with our own git implementation - it uses the git command""" from git.db.compat import RepoCompatibilityInterface -from git.db.py.complex import PureGitDB - from base import * -__all__ = ['GitCmdDB', 'CmdCompatibilityGitDB', 'CmdPartialGitDB'] +__all__ = ['CmdPartialGitDB'] class CmdPartialGitDB( GitCommandMixin, CmdObjectDBRMixin, CmdTransportMixin, @@ -16,12 +14,3 @@ class CmdPartialGitDB( GitCommandMixin, CmdObjectDBRMixin, CmdTransportMixin, implementations""" pass - -class CmdGitDB(CmdPartialGitDB, PureGitDB): - """A database which fills in its missing implementation using the pure python - implementation""" - pass - - -class CmdCompatibilityGitDB(CmdGitDB, RepoCompatibilityInterface): - """Command git database with the compatabilty interface added for 0.3x code""" diff --git a/git/db/complex.py b/git/db/complex.py index ef2013e3..71a39c45 100644 --- a/git/db/complex.py +++ b/git/db/complex.py @@ -1,12 +1,25 @@ """Module with many useful complex databases with different useful combinations of primary implementations""" -from py.complex import PureGitDB +from py.complex import PurePartialGitDB from cmd.complex import CmdPartialGitDB from compat import RepoCompatibilityInterface -__all__ = ['CmdPartialGitDB', 'PureGitDB', 'PureCmdGitDB'] +__all__ = ['CmdGitDB', 'PureGitDB', 'CmdCompatibilityGitDB', 'PureCompatibilityGitDB'] -class PureCmdGitDB(PureGitDB, CmdPartialGitDB, RepoCompatibilityInterface): +class CmdGitDB(CmdPartialGitDB, PurePartialGitDB): + """A database which uses primarily the git command implementation, but falls back + to pure python where it is more feasible""" + +class CmdCompatibilityGitDB(RepoCompatibilityInterface, CmdGitDB): + """A database which fills in its missing implementation using the pure python + implementation""" + pass + +class PureGitDB(PurePartialGitDB, CmdPartialGitDB): + """A repository which uses the pure implementation primarily, but falls back + on using the git command for high-level functionality""" + +class PureCompatibilityGitDB(RepoCompatibilityInterface, PureGitDB): """Repository which uses the pure implementation primarily, but falls back to the git command implementation. Please note that the CmdGitDB does it the opposite way around.""" diff --git a/git/db/py/base.py b/git/db/py/base.py index 74b8beb9..4d9b6e14 100644 --- a/git/db/py/base.py +++ b/git/db/py/base.py @@ -8,6 +8,7 @@ from git.db.interface import * from git.util import ( pool, join, + isfile, normpath, abspath, dirname, @@ -25,7 +26,8 @@ from git.config import GitConfigParser from git.exc import ( BadObject, AmbiguousObjectName, - InvalidDBRoot + InvalidGitRepositoryError, + NoSuchPathError ) from async import ChannelThreadTask @@ -240,7 +242,7 @@ class PureRepositoryPathsMixin(RepositoryPathsMixin): epath = abspath(expandvars(expanduser(path or os.getcwd()))) if not exists(epath): - raise InvalidDBRoot(epath) + raise NoSuchPathError(epath) #END check file self._working_tree_dir = None @@ -264,7 +266,7 @@ class PureRepositoryPathsMixin(RepositoryPathsMixin): # END while curpath if self._git_path is None: - raise InvalidDBRoot(epath) + raise InvalidGitRepositoryError(epath) # END path not found self._bare = self._git_path.endswith(self.repo_dir) @@ -351,6 +353,7 @@ class PureConfigurationMixin(ConfigurationMixin): def __init__(self, *args, **kwargs): """Verify prereqs""" + super(PureConfigurationMixin, self).__init__(*args, **kwargs) assert hasattr(self, 'git_dir') def _path_at_level(self, level ): diff --git a/git/db/py/complex.py b/git/db/py/complex.py index 9d891537..a51118b3 100644 --- a/git/db/py/complex.py +++ b/git/db/py/complex.py @@ -1,6 +1,6 @@ # Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors # -# This module is part of PureGitDB and is released under +# This module is part of PurePartialGitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php from git.db.interface import HighLevelRepository from base import ( @@ -12,7 +12,7 @@ from base import ( PureAlternatesFileMixin, PureIndexDB, ) - +from transport import PureTransportDB from resolve import PureReferencesMixin from loose import PureLooseObjectODB @@ -35,14 +35,14 @@ from git.exc import ( ) import os -__all__ = ('PureGitODB', 'PureGitDB', 'PureCompatibilityGitDB') +__all__ = ('PureGitODB', 'PurePartialGitDB', 'PureCompatibilityGitDB') 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 PureGitDB type if you need + as it deals solely with object lookup. Use a PurePartialGitDB type if you need reference and push support.""" # Configuration PackDBCls = PurePackedODB @@ -103,10 +103,10 @@ class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB): -class PureGitDB(PureGitODB, +class PurePartialGitDB(PureGitODB, PureRepositoryPathsMixin, PureConfigurationMixin, PureReferencesMixin, PureSubmoduleDB, PureAlternatesFileMixin, - PureIndexDB, + PureIndexDB, PureTransportDB # HighLevelRepository Currently not implemented ! ): """Git like database with support for object lookup as well as reference resolution. @@ -119,10 +119,10 @@ class PureGitDB(PureGitODB, def __init__(self, root_path): """Initialize ourselves on the .git directory, or the .git/objects directory.""" PureRepositoryPathsMixin._initialize(self, root_path) - super(PureGitDB, self).__init__(self.objects_dir) + super(PurePartialGitDB, self).__init__(self.objects_dir) -class PureCompatibilityGitDB(PureGitDB, RepoCompatibilityInterface): +class PureCompatibilityGitDB(PurePartialGitDB, RepoCompatibilityInterface): """Pure git database with a compatability layer required by 0.3x code""" diff --git a/git/db/py/resolve.py b/git/db/py/resolve.py index 7194149c..7bea779e 100644 --- a/git/db/py/resolve.py +++ b/git/db/py/resolve.py @@ -320,8 +320,7 @@ class PureReferencesMixin(ReferencesMixin): return self.TagReferenceCls.list_items(self) def tag(self, name): - return self.tags[name] - + return self.TagReferenceCls(self, self.TagReferenceCls.to_full_path(name)) def commit(self, rev=None): if rev is None: diff --git a/git/exc.py b/git/exc.py index 412f82f0..e14fb7f1 100644 --- a/git/exc.py +++ b/git/exc.py @@ -43,11 +43,11 @@ class UnsupportedOperation(ODBError): """Thrown if the given operation cannot be supported by the object database""" -class InvalidGitRepositoryError(GitPythonError): +class InvalidGitRepositoryError(InvalidDBRoot): """ Thrown if the given repository appears to have an invalid format. """ -class NoSuchPathError(GitPythonError): +class NoSuchPathError(InvalidDBRoot): """ Thrown if a path could not be access by the system. """ diff --git a/git/objects/base.py b/git/objects/base.py index 24967e7b..e51afbed 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -14,7 +14,8 @@ from git.util import ( join_path_native, stream_copy ) - +from git.db.interface import RepositoryPathsMixin +from git.exc import UnsupportedOperation from git.typ import ObjectType _assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r" @@ -173,7 +174,15 @@ class IndexObject(Object): Absolute path to this index object in the file system ( as opposed to the .path field which is a path relative to the git repository ). - The returned path will be native to the system and contains '\' on windows. """ - assert False, "Only works if repository is not bare - provide this check in an interface" - return join_path_native(dirname(self.odb.root_path()), self.path) + The returned path will be native to the system and contains '\' on windows. + :raise UnsupportedOperation: if underlying odb does not support the required method to obtain a working dir""" + # TODO: Here we suddenly need something better than a plain object database + # which indicates our odb should better be named repo ! + root = '' + if isinstance(self.odb, RepositoryPathsMixin): + root = self.odb.working_tree_dir + else: + raise UnsupportedOperation("Cannot provide absolute path from a database without Repository path support") + #END handle odb type + return join_path_native(root, self.path) diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index a57111d3..e38b94f8 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -58,7 +58,7 @@ UPDWKTREE = UpdateProgress.UPDWKTREE # IndexObject comes via util module, its a 'hacky' fix thanks to pythons import # mechanism which cause plenty of trouble of the only reason for packages and # modules is refactoring - subpackages shoudn't depend on parent packages -class Submodule(Iterable, Traversable, RepoAliasMixin): +class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin): """Implements access to a git submodule. They are special in that their sha represents a commit in the submodule's repository which is to be checked out at the path of this instance. diff --git a/git/refs/reference.py b/git/refs/reference.py index 838a29e3..5cff74bb 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -28,7 +28,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable): Path relative to the .git/ directory pointing to the ref in question, i.e. refs/heads/master""" if not path.startswith(self._common_path_default+'/'): - raise ValueError("Cannot instantiate %r from path %s" % ( self.__class__.__name__, path )) + raise ValueError("Cannot instantiate %r from path %s, maybe use %s.to_full_path(name) to safely generate a valid full path from a name" % ( self.__class__.__name__, path, type(self).__name__)) super(Reference, self).__init__(repo, path) diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index d670bd47..ddee3809 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -237,7 +237,7 @@ class SymbolicReference(object): is_invalid_type = commit.object.type != self.CommitCls.type else: try: - is_invalid_type = self.repo.resolve(commit).type != self.CommitCls.type + is_invalid_type = self.repo.resolve_object(commit).type != self.CommitCls.type except BadObject: raise ValueError("Invalid object: %s" % commit) #END handle exception @@ -293,7 +293,7 @@ class SymbolicReference(object): write_value = ref.hexsha elif isinstance(ref, basestring): try: - obj = self.repo.resolve(ref+"^{}") # optionally deref tags + obj = self.repo.resolve_object(ref+"^{}") # optionally deref tags write_value = obj.hexsha except BadObject: raise ValueError("Could not extract object from %s" % ref) @@ -481,7 +481,7 @@ class SymbolicReference(object): elif isinstance(reference, SymbolicReference): target = reference.object.hexsha else: - target = repo.resolve(str(reference)) + target = repo.resolve_object(str(reference)) #END handle resoltion #END need resolution diff --git a/git/repo.py b/git/repo.py index 8973dbd2..8d5c4021 100644 --- a/git/repo.py +++ b/git/repo.py @@ -5,7 +5,7 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php """This module is just to maintain compatibility to git-python 0.3x""" -from git.db.cmd.complex import CmdCompatibilityGitDB +from git.db.complex import CmdCompatibilityGitDB import warnings diff --git a/git/test/db/base.py b/git/test/db/base.py index 470565b9..b0bc76f9 100644 --- a/git/test/db/base.py +++ b/git/test/db/base.py @@ -5,7 +5,11 @@ # the BSD License: http://www.opensource.org/licenses/bsd-license.php from lib import TestDBBase from git.test.lib import * -from git import * +from git.cmd import Git +from git.objects import * +from git.exc import * +from git.index import * +from git.refs import * from git.util import join_path_native from git.exc import BadObject from git.util import hex_to_bin, bin_to_hex @@ -15,6 +19,8 @@ import tempfile import shutil from cStringIO import StringIO +from git.db.compat import RepoCompatibilityInterface + class RepoGlobalsItemDeletorMetaCls(GlobalsItemDeletorMetaCls): ModuleToDelete = 'RepoBase' @@ -138,8 +144,8 @@ class RepoBase(TestDBBase): try: # with specific path for path in (git_dir_rela, git_dir_abs): - r = Repo.init(path=path, bare=True) - assert isinstance(r, Repo) + r = self.RepoCls.init(path=path, bare=True) + assert isinstance(r, self.RepoCls) assert r.bare == True assert os.path.isdir(r.git_dir) @@ -160,7 +166,7 @@ class RepoBase(TestDBBase): # END exception handling # try again, this time with the absolute version - rc = Repo.clone_from(r.git_dir, clone_path) + rc = self.RepoCls.clone_from(r.git_dir, clone_path) self._assert_empty_repo(rc) shutil.rmtree(git_dir_abs) @@ -176,7 +182,7 @@ class RepoBase(TestDBBase): os.makedirs(git_dir_rela) os.chdir(git_dir_rela) - r = Repo.init(bare=False) + r = self.RepoCls.init(bare=False) r.bare == False self._assert_empty_repo(r) @@ -212,8 +218,7 @@ class RepoBase(TestDBBase): self.rorepo.alternates = cur_alternates def test_repr(self): - path = os.path.join(os.path.abspath(rorepo_dir()), '.git') - assert_equal('' % path, repr(self.rorepo)) + assert_equal('' % rorepo_dir(), repr(self.rorepo)) def test_is_dirty_with_bare_repository(self): orig_value = self.rorepo._bare @@ -243,6 +248,7 @@ class RepoBase(TestDBBase): assert isinstance(index, IndexFile) def test_tag(self): + assert self.rorepo.tag('0.1.5').commit assert self.rorepo.tag('refs/tags/0.1.5').commit def test_archive(self): @@ -587,17 +593,13 @@ class RepoBase(TestDBBase): # currently, nothing more is supported self.failUnlessRaises(NotImplementedError, rev_parse, "@{1 week ago}") - def test_repo_odbtype(self): - target_type = GitDB - if sys.version_info[1] < 5: - target_type = CmdGitDB - assert isinstance(self.rorepo.odb, target_type) - def test_submodules(self): assert len(self.rorepo.submodules) == 1 # non-recursive - assert len(list(self.rorepo.iter_submodules())) == 2 + # in previous configurations, we had recursive repositories so this would compare to 2 + # now there is only one left, as gitdb was merged + assert len(list(self.rorepo.iter_submodules())) == 1 - assert isinstance(self.rorepo.submodule("git"), Submodule) + assert isinstance(self.rorepo.submodule("git/ext/async"), Submodule) self.failUnlessRaises(ValueError, self.rorepo.submodule, "doesn't exist") @with_rw_repo('HEAD', bare=False) diff --git a/git/test/db/cmd/test_base.py b/git/test/db/cmd/test_base.py index 1404eca0..8d00f57f 100644 --- a/git/test/db/cmd/test_base.py +++ b/git/test/db/cmd/test_base.py @@ -2,12 +2,17 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from git.test.lib import * -from git.db import RefSpec - -class TestBase(TestDBBase): - - @with_rw_directory - def test_basics(self, path): - assert False - +from git.test.lib import rorepo_dir +from git.test.db.base import RepoBase + +# immport test +from git.db.cmd.base import * +from git.db.cmd.complex import * + +from git.db.complex import CmdCompatibilityGitDB + +class TestBase(RepoBase): + RepoCls = CmdCompatibilityGitDB + + def test_basics(self): + pass diff --git a/git/test/db/py/test_base.py b/git/test/db/py/test_base.py index 84899651..ade05c8d 100644 --- a/git/test/db/py/test_base.py +++ b/git/test/db/py/test_base.py @@ -2,17 +2,26 @@ # # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php -from git.test.lib import * +from git.test.lib import rorepo_dir from git.test.db.base import RepoBase + +# import test +from git.db.py.base import * +from git.db.py.loose import * +from git.db.py.mem import * +from git.db.py.pack import * +from git.db.py.ref import * +from git.db.py.resolve import * +from git.db.py.submodule import * +from git.db.py.transport import * from git.db.py.complex import * -from git.db.complex import PureCmdGitDB +from git.db.complex import PureCompatibilityGitDB class TestPyDBBase(RepoBase): - RepoCls = PureCmdGitDB + RepoCls = PureCompatibilityGitDB - def test_instantiation(self): - db = PureGitDB(rorepo_dir()) - cdb = PureCompatibilityGitDB(rorepo_dir()) + def test_basics(self): + pass diff --git a/git/test/db/py/test_git.py b/git/test/db/py/test_git.py new file mode 100644 index 00000000..46a2d24f --- /dev/null +++ b/git/test/db/py/test_git.py @@ -0,0 +1,47 @@ +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors +# +# 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 git.exc import BadObject +from git.db.py import PureGitODB +from git.base import OStream, OInfo +from git.util import hex_to_bin, bin_to_hex + +class TestGitDB(TestDBBase): + + def test_reading(self): + gdb = PureGitODB(fixture_path('../../../.git/objects')) + + # we have packs and loose objects, alternates doesn't necessarily exist + assert 1 < len(gdb.databases()) < 4 + + # access should be possible + git_sha = hex_to_bin("5690fd0d3304f378754b23b098bd7cb5f4aa1976") + assert isinstance(gdb.info(git_sha), OInfo) + assert isinstance(gdb.stream(git_sha), OStream) + assert gdb.size() > 200 + sha_list = list(gdb.sha_iter()) + assert len(sha_list) == gdb.size() + + + # This is actually a test for compound functionality, but it doesn't + # have a separate test module + # test partial shas + # this one as uneven and quite short + assert gdb.partial_to_complete_sha_hex('155b6') == hex_to_bin("155b62a9af0aa7677078331e111d0f7aa6eb4afc") + + # mix even/uneven hexshas + for i, binsha in enumerate(sha_list): + assert gdb.partial_to_complete_sha_hex(bin_to_hex(binsha)[:8-(i%2)]) == binsha + # END for each sha + + self.failUnlessRaises(BadObject, gdb.partial_to_complete_sha_hex, "0000") + + @with_rw_directory + def test_writing(self, path): + gdb = PureGitODB(path) + + # its possible to write objects + self._assert_object_writing(gdb) + self._assert_object_writing_async(gdb) diff --git a/git/test/db/py/test_loose.py b/git/test/db/py/test_loose.py new file mode 100644 index 00000000..16c12d8e --- /dev/null +++ b/git/test/db/py/test_loose.py @@ -0,0 +1,34 @@ +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors +# +# 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 git.db.py import PureLooseObjectODB +from git.exc import BadObject +from git.util import bin_to_hex + +class TestLooseDB(TestDBBase): + + @with_rw_directory + def test_basics(self, path): + ldb = PureLooseObjectODB(path) + + # write data + self._assert_object_writing(ldb) + self._assert_object_writing_async(ldb) + + # verify sha iteration and size + shas = list(ldb.sha_iter()) + assert shas and len(shas[0]) == 20 + + assert len(shas) == ldb.size() + + # verify find short object + long_sha = bin_to_hex(shas[-1]) + for short_sha in (long_sha[:20], long_sha[:5]): + assert bin_to_hex(ldb.partial_to_complete_sha_hex(short_sha)) == long_sha + # END for each sha + + self.failUnlessRaises(BadObject, ldb.partial_to_complete_sha_hex, '0000') + # raises if no object could be foudn + diff --git a/git/test/db/py/test_mem.py b/git/test/db/py/test_mem.py new file mode 100644 index 00000000..ed14cc21 --- /dev/null +++ b/git/test/db/py/test_mem.py @@ -0,0 +1,30 @@ +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors +# +# 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 git.db.py import ( + PureMemoryDB, + PureLooseObjectODB + ) + +class TestPureMemoryDB(TestDBBase): + + @with_rw_directory + def test_writing(self, path): + mdb = PureMemoryDB() + + # write data + self._assert_object_writing_simple(mdb) + + # test stream copy + ldb = PureLooseObjectODB(path) + assert ldb.size() == 0 + num_streams_copied = mdb.stream_copy(mdb.sha_iter(), ldb) + assert num_streams_copied == mdb.size() + + assert ldb.size() == mdb.size() + for sha in mdb.sha_iter(): + assert ldb.has_object(sha) + assert ldb.stream(sha).read() == mdb.stream(sha).read() + # END verify objects where copied and are equal diff --git a/git/test/db/py/test_pack.py b/git/test/db/py/test_pack.py new file mode 100644 index 00000000..4854c4e7 --- /dev/null +++ b/git/test/db/py/test_pack.py @@ -0,0 +1,72 @@ +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors +# +# 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 git.db.py import PurePackedODB +from git.test.lib import fixture_path + +from git.exc import BadObject, AmbiguousObjectName + +import os +import random + +class TestPackDB(TestDBBase): + + @with_packs_rw + def test_writing(self, path): + pdb = PurePackedODB(path) + + # on demand, we init our pack cache + num_packs = len(pdb.entities()) + assert pdb._st_mtime != 0 + + # test pack directory changed: + # packs removed - rename a file, should affect the glob + pack_path = pdb.entities()[0].pack().path() + new_pack_path = pack_path + "renamed" + os.rename(pack_path, new_pack_path) + + pdb.update_cache(force=True) + assert len(pdb.entities()) == num_packs - 1 + + # packs added + os.rename(new_pack_path, pack_path) + pdb.update_cache(force=True) + assert len(pdb.entities()) == num_packs + + # bang on the cache + # access the Entities directly, as there is no iteration interface + # yet ( or required for now ) + sha_list = list(pdb.sha_iter()) + assert len(sha_list) == pdb.size() + + # hit all packs in random order + random.shuffle(sha_list) + + for sha in sha_list: + info = pdb.info(sha) + stream = pdb.stream(sha) + # END for each sha to query + + + # test short finding - be a bit more brutal here + max_bytes = 19 + min_bytes = 2 + num_ambiguous = 0 + for i, sha in enumerate(sha_list): + short_sha = sha[:max((i % max_bytes), min_bytes)] + try: + assert pdb.partial_to_complete_sha(short_sha, len(short_sha)*2) == sha + except AmbiguousObjectName: + num_ambiguous += 1 + pass # valid, we can have short objects + # END exception handling + # END for each sha to find + + # we should have at least one ambiguous, considering the small sizes + # but in our pack, there is no ambigious ... + # assert num_ambiguous + + # non-existing + self.failUnlessRaises(BadObject, pdb.partial_to_complete_sha, "\0\0", 4) diff --git a/git/test/db/py/test_ref.py b/git/test/db/py/test_ref.py new file mode 100644 index 00000000..43fbb48f --- /dev/null +++ b/git/test/db/py/test_ref.py @@ -0,0 +1,60 @@ +# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors +# +# 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 git.db.py import PureReferenceDB + +from git.util import ( + NULL_BIN_SHA, + hex_to_bin + ) + +import os + +class TestPureReferenceDB(TestDBBase): + + def make_alt_file(self, alt_path, alt_list): + """Create an alternates file which contains the given alternates. + The list can be empty""" + alt_file = open(alt_path, "wb") + for alt in alt_list: + alt_file.write(alt + "\n") + alt_file.close() + + @with_rw_directory + def test_writing(self, path): + NULL_BIN_SHA = '\0' * 20 + + alt_path = os.path.join(path, 'alternates') + rdb = PureReferenceDB(alt_path) + assert len(rdb.databases()) == 0 + assert rdb.size() == 0 + assert len(list(rdb.sha_iter())) == 0 + + # try empty, non-existing + assert not rdb.has_object(NULL_BIN_SHA) + + + # setup alternate file + # add two, one is invalid + own_repo_path = fixture_path('../../../.git/objects') # use own repo + self.make_alt_file(alt_path, [own_repo_path, "invalid/path"]) + rdb.update_cache() + assert len(rdb.databases()) == 1 + + # we should now find a default revision of ours + git_sha = hex_to_bin("5690fd0d3304f378754b23b098bd7cb5f4aa1976") + assert rdb.has_object(git_sha) + + # remove valid + self.make_alt_file(alt_path, ["just/one/invalid/path"]) + rdb.update_cache() + assert len(rdb.databases()) == 0 + + # add valid + self.make_alt_file(alt_path, [own_repo_path]) + rdb.update_cache() + assert len(rdb.databases()) == 1 + + diff --git a/git/test/db/test_git.py b/git/test/db/test_git.py deleted file mode 100644 index 46a2d24f..00000000 --- a/git/test/db/test_git.py +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors -# -# 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 git.exc import BadObject -from git.db.py import PureGitODB -from git.base import OStream, OInfo -from git.util import hex_to_bin, bin_to_hex - -class TestGitDB(TestDBBase): - - def test_reading(self): - gdb = PureGitODB(fixture_path('../../../.git/objects')) - - # we have packs and loose objects, alternates doesn't necessarily exist - assert 1 < len(gdb.databases()) < 4 - - # access should be possible - git_sha = hex_to_bin("5690fd0d3304f378754b23b098bd7cb5f4aa1976") - assert isinstance(gdb.info(git_sha), OInfo) - assert isinstance(gdb.stream(git_sha), OStream) - assert gdb.size() > 200 - sha_list = list(gdb.sha_iter()) - assert len(sha_list) == gdb.size() - - - # This is actually a test for compound functionality, but it doesn't - # have a separate test module - # test partial shas - # this one as uneven and quite short - assert gdb.partial_to_complete_sha_hex('155b6') == hex_to_bin("155b62a9af0aa7677078331e111d0f7aa6eb4afc") - - # mix even/uneven hexshas - for i, binsha in enumerate(sha_list): - assert gdb.partial_to_complete_sha_hex(bin_to_hex(binsha)[:8-(i%2)]) == binsha - # END for each sha - - self.failUnlessRaises(BadObject, gdb.partial_to_complete_sha_hex, "0000") - - @with_rw_directory - def test_writing(self, path): - gdb = PureGitODB(path) - - # its possible to write objects - self._assert_object_writing(gdb) - self._assert_object_writing_async(gdb) diff --git a/git/test/db/test_loose.py b/git/test/db/test_loose.py deleted file mode 100644 index 16c12d8e..00000000 --- a/git/test/db/test_loose.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors -# -# 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 git.db.py import PureLooseObjectODB -from git.exc import BadObject -from git.util import bin_to_hex - -class TestLooseDB(TestDBBase): - - @with_rw_directory - def test_basics(self, path): - ldb = PureLooseObjectODB(path) - - # write data - self._assert_object_writing(ldb) - self._assert_object_writing_async(ldb) - - # verify sha iteration and size - shas = list(ldb.sha_iter()) - assert shas and len(shas[0]) == 20 - - assert len(shas) == ldb.size() - - # verify find short object - long_sha = bin_to_hex(shas[-1]) - for short_sha in (long_sha[:20], long_sha[:5]): - assert bin_to_hex(ldb.partial_to_complete_sha_hex(short_sha)) == long_sha - # END for each sha - - self.failUnlessRaises(BadObject, ldb.partial_to_complete_sha_hex, '0000') - # raises if no object could be foudn - diff --git a/git/test/db/test_mem.py b/git/test/db/test_mem.py deleted file mode 100644 index ed14cc21..00000000 --- a/git/test/db/test_mem.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors -# -# 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 git.db.py import ( - PureMemoryDB, - PureLooseObjectODB - ) - -class TestPureMemoryDB(TestDBBase): - - @with_rw_directory - def test_writing(self, path): - mdb = PureMemoryDB() - - # write data - self._assert_object_writing_simple(mdb) - - # test stream copy - ldb = PureLooseObjectODB(path) - assert ldb.size() == 0 - num_streams_copied = mdb.stream_copy(mdb.sha_iter(), ldb) - assert num_streams_copied == mdb.size() - - assert ldb.size() == mdb.size() - for sha in mdb.sha_iter(): - assert ldb.has_object(sha) - assert ldb.stream(sha).read() == mdb.stream(sha).read() - # END verify objects where copied and are equal diff --git a/git/test/db/test_pack.py b/git/test/db/test_pack.py deleted file mode 100644 index 4854c4e7..00000000 --- a/git/test/db/test_pack.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors -# -# 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 git.db.py import PurePackedODB -from git.test.lib import fixture_path - -from git.exc import BadObject, AmbiguousObjectName - -import os -import random - -class TestPackDB(TestDBBase): - - @with_packs_rw - def test_writing(self, path): - pdb = PurePackedODB(path) - - # on demand, we init our pack cache - num_packs = len(pdb.entities()) - assert pdb._st_mtime != 0 - - # test pack directory changed: - # packs removed - rename a file, should affect the glob - pack_path = pdb.entities()[0].pack().path() - new_pack_path = pack_path + "renamed" - os.rename(pack_path, new_pack_path) - - pdb.update_cache(force=True) - assert len(pdb.entities()) == num_packs - 1 - - # packs added - os.rename(new_pack_path, pack_path) - pdb.update_cache(force=True) - assert len(pdb.entities()) == num_packs - - # bang on the cache - # access the Entities directly, as there is no iteration interface - # yet ( or required for now ) - sha_list = list(pdb.sha_iter()) - assert len(sha_list) == pdb.size() - - # hit all packs in random order - random.shuffle(sha_list) - - for sha in sha_list: - info = pdb.info(sha) - stream = pdb.stream(sha) - # END for each sha to query - - - # test short finding - be a bit more brutal here - max_bytes = 19 - min_bytes = 2 - num_ambiguous = 0 - for i, sha in enumerate(sha_list): - short_sha = sha[:max((i % max_bytes), min_bytes)] - try: - assert pdb.partial_to_complete_sha(short_sha, len(short_sha)*2) == sha - except AmbiguousObjectName: - num_ambiguous += 1 - pass # valid, we can have short objects - # END exception handling - # END for each sha to find - - # we should have at least one ambiguous, considering the small sizes - # but in our pack, there is no ambigious ... - # assert num_ambiguous - - # non-existing - self.failUnlessRaises(BadObject, pdb.partial_to_complete_sha, "\0\0", 4) diff --git a/git/test/db/test_ref.py b/git/test/db/test_ref.py deleted file mode 100644 index 43fbb48f..00000000 --- a/git/test/db/test_ref.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors -# -# 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 git.db.py import PureReferenceDB - -from git.util import ( - NULL_BIN_SHA, - hex_to_bin - ) - -import os - -class TestPureReferenceDB(TestDBBase): - - def make_alt_file(self, alt_path, alt_list): - """Create an alternates file which contains the given alternates. - The list can be empty""" - alt_file = open(alt_path, "wb") - for alt in alt_list: - alt_file.write(alt + "\n") - alt_file.close() - - @with_rw_directory - def test_writing(self, path): - NULL_BIN_SHA = '\0' * 20 - - alt_path = os.path.join(path, 'alternates') - rdb = PureReferenceDB(alt_path) - assert len(rdb.databases()) == 0 - assert rdb.size() == 0 - assert len(list(rdb.sha_iter())) == 0 - - # try empty, non-existing - assert not rdb.has_object(NULL_BIN_SHA) - - - # setup alternate file - # add two, one is invalid - own_repo_path = fixture_path('../../../.git/objects') # use own repo - self.make_alt_file(alt_path, [own_repo_path, "invalid/path"]) - rdb.update_cache() - assert len(rdb.databases()) == 1 - - # we should now find a default revision of ours - git_sha = hex_to_bin("5690fd0d3304f378754b23b098bd7cb5f4aa1976") - assert rdb.has_object(git_sha) - - # remove valid - self.make_alt_file(alt_path, ["just/one/invalid/path"]) - rdb.update_cache() - assert len(rdb.databases()) == 0 - - # add valid - self.make_alt_file(alt_path, [own_repo_path]) - rdb.update_cache() - assert len(rdb.databases()) == 1 - - diff --git a/git/test/lib/base.py b/git/test/lib/base.py index 221395c9..7bd9215e 100644 --- a/git/test/lib/base.py +++ b/git/test/lib/base.py @@ -1,6 +1,6 @@ # Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors # -# This module is part of PureCmdGitDB and is released under +# This module is part of PureCompatibilityGitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Utilities used in ODB testing""" from git.base import OStream -- cgit v1.2.1