diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2011-05-30 16:32:56 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2011-05-30 16:32:56 +0200 |
commit | 1f71ed94578799ee1667ba54b66a369e307f415b (patch) | |
tree | f8e1c3a8507b5306a6a04efa94ffec3c22731bcc /git | |
parent | 024adf37acddd6a5d8293b6b5d15795c59a142c0 (diff) | |
download | gitpython-1f71ed94578799ee1667ba54b66a369e307f415b.tar.gz |
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
Diffstat (limited to 'git')
-rw-r--r-- | git/db/cmd/base.py | 30 | ||||
-rw-r--r-- | git/db/cmd/complex.py | 13 | ||||
-rw-r--r-- | git/db/complex.py | 19 | ||||
-rw-r--r-- | git/db/py/base.py | 9 | ||||
-rw-r--r-- | git/db/py/complex.py | 16 | ||||
-rw-r--r-- | git/db/py/resolve.py | 3 | ||||
-rw-r--r-- | git/exc.py | 4 | ||||
-rw-r--r-- | git/objects/base.py | 17 | ||||
-rw-r--r-- | git/objects/submodule/base.py | 2 | ||||
-rw-r--r-- | git/refs/reference.py | 2 | ||||
-rw-r--r-- | git/refs/symbolic.py | 6 | ||||
-rw-r--r-- | git/repo.py | 2 | ||||
-rw-r--r-- | git/test/db/base.py | 32 | ||||
-rw-r--r-- | git/test/db/cmd/test_base.py | 23 | ||||
-rw-r--r-- | git/test/db/py/test_base.py | 21 | ||||
-rw-r--r-- | git/test/db/py/test_git.py (renamed from git/test/db/test_git.py) | 0 | ||||
-rw-r--r-- | git/test/db/py/test_loose.py (renamed from git/test/db/test_loose.py) | 0 | ||||
-rw-r--r-- | git/test/db/py/test_mem.py (renamed from git/test/db/test_mem.py) | 0 | ||||
-rw-r--r-- | git/test/db/py/test_pack.py (renamed from git/test/db/test_pack.py) | 0 | ||||
-rw-r--r-- | git/test/db/py/test_ref.py (renamed from git/test/db/test_ref.py) | 0 | ||||
-rw-r--r-- | git/test/lib/base.py | 2 |
21 files changed, 118 insertions, 83 deletions
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: @@ -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('<git.Repo "%s">' % path, repr(self.rorepo)) + assert_equal('<git.Repo "%s">' % 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/test_git.py b/git/test/db/py/test_git.py index 46a2d24f..46a2d24f 100644 --- a/git/test/db/test_git.py +++ b/git/test/db/py/test_git.py diff --git a/git/test/db/test_loose.py b/git/test/db/py/test_loose.py index 16c12d8e..16c12d8e 100644 --- a/git/test/db/test_loose.py +++ b/git/test/db/py/test_loose.py diff --git a/git/test/db/test_mem.py b/git/test/db/py/test_mem.py index ed14cc21..ed14cc21 100644 --- a/git/test/db/test_mem.py +++ b/git/test/db/py/test_mem.py diff --git a/git/test/db/test_pack.py b/git/test/db/py/test_pack.py index 4854c4e7..4854c4e7 100644 --- a/git/test/db/test_pack.py +++ b/git/test/db/py/test_pack.py diff --git a/git/test/db/test_ref.py b/git/test/db/py/test_ref.py index 43fbb48f..43fbb48f 100644 --- a/git/test/db/test_ref.py +++ b/git/test/db/py/test_ref.py 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 |