Skip to content

Commit 1f71ed9

Browse files
committed
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
1 parent 024adf3 commit 1f71ed9

21 files changed

+118
-83
lines changed

git/db/cmd/base.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,26 @@
1313

1414
from git.util import (
1515
bin_to_hex,
16-
hex_to_bin
17-
)
18-
from git.db.compat import RepoCompatibilityInterface
19-
from git.util import RemoteProgress
16+
hex_to_bin,
17+
RemoteProgress,
18+
isfile,
19+
join_path,
20+
join,
21+
Actor
22+
)
2023
from git.db.interface import FetchInfo as GitdbFetchInfo
2124
from git.db.interface import PushInfo as GitdbPushInfo
2225
from git.db.interface import HighLevelRepository
23-
24-
from git.util import join_path
25-
from git.util import join
2626
from git.cmd import Git
2727
from git.refs import (
2828
Reference,
2929
RemoteReference,
3030
SymbolicReference,
3131
TagReference
3232
)
33-
33+
from git.objects.commit import Commit
3434
import re
35+
import os
3536
import sys
3637

3738

@@ -472,6 +473,11 @@ class CmdHighLevelRepository(HighLevelRepository):
472473
re_author_committer_start = re.compile(r'^(author|committer)')
473474
re_tab_full_line = re.compile(r'^\t(.*)$')
474475

476+
#{ Configuration
477+
CommitCls = Commit
478+
GitCls = Git
479+
#} END configuration
480+
475481
def daemon_export():
476482
def _get_daemon_export(self):
477483
filename = join(self.git_dir, self.DAEMON_EXPORT_FILE)
@@ -588,7 +594,7 @@ def blame(self, rev, file):
588594
sha = info['id']
589595
c = commits.get(sha)
590596
if c is None:
591-
c = Commit( self, hex_to_bin(sha),
597+
c = self.CommitCls( self, hex_to_bin(sha),
592598
author=Actor._from_string(info['author'] + ' ' + info['author_email']),
593599
authored_date=info['author_date'],
594600
committer=Actor._from_string(info['committer'] + ' ' + info['committer_email']),
@@ -619,9 +625,9 @@ def init(cls, path=None, mkdir=True, **kwargs):
619625
os.makedirs(path, 0755)
620626

621627
# git command automatically chdir into the directory
622-
git = Git(path)
628+
git = cls.GitCls(path)
623629
output = git.init(**kwargs)
624-
return Repo(path)
630+
return cls(path)
625631

626632
@classmethod
627633
def _clone(cls, git, url, path, **kwargs):
@@ -686,7 +692,7 @@ def clone_from(cls, url, to_path, **kwargs):
686692
"""
687693
:param kwargs: see the ``clone`` method
688694
For more information, see the respective method in the HighLevelRepository"""
689-
return cls._clone(type(self.git)(os.getcwd()), url, to_path, **kwargs)
695+
return cls._clone(cls.GitCls(os.getcwd()), url, to_path, **kwargs)
690696

691697
def archive(self, ostream, treeish=None, prefix=None, **kwargs):
692698
"""For all args see HighLevelRepository interface

git/db/cmd/complex.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"""Module with our own git implementation - it uses the git command"""
22

33
from git.db.compat import RepoCompatibilityInterface
4-
from git.db.py.complex import PureGitDB
5-
64
from base import *
75

86

9-
__all__ = ['GitCmdDB', 'CmdCompatibilityGitDB', 'CmdPartialGitDB']
7+
__all__ = ['CmdPartialGitDB']
108

119

1210
class CmdPartialGitDB( GitCommandMixin, CmdObjectDBRMixin, CmdTransportMixin,
@@ -16,12 +14,3 @@ class CmdPartialGitDB( GitCommandMixin, CmdObjectDBRMixin, CmdTransportMixin,
1614
implementations"""
1715
pass
1816

19-
20-
class CmdGitDB(CmdPartialGitDB, PureGitDB):
21-
"""A database which fills in its missing implementation using the pure python
22-
implementation"""
23-
pass
24-
25-
26-
class CmdCompatibilityGitDB(CmdGitDB, RepoCompatibilityInterface):
27-
"""Command git database with the compatabilty interface added for 0.3x code"""

git/db/complex.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
"""Module with many useful complex databases with different useful combinations of primary implementations"""
22

3-
from py.complex import PureGitDB
3+
from py.complex import PurePartialGitDB
44
from cmd.complex import CmdPartialGitDB
55
from compat import RepoCompatibilityInterface
66

7-
__all__ = ['CmdPartialGitDB', 'PureGitDB', 'PureCmdGitDB']
7+
__all__ = ['CmdGitDB', 'PureGitDB', 'CmdCompatibilityGitDB', 'PureCompatibilityGitDB']
88

9-
class PureCmdGitDB(PureGitDB, CmdPartialGitDB, RepoCompatibilityInterface):
9+
class CmdGitDB(CmdPartialGitDB, PurePartialGitDB):
10+
"""A database which uses primarily the git command implementation, but falls back
11+
to pure python where it is more feasible"""
12+
13+
class CmdCompatibilityGitDB(RepoCompatibilityInterface, CmdGitDB):
14+
"""A database which fills in its missing implementation using the pure python
15+
implementation"""
16+
pass
17+
18+
class PureGitDB(PurePartialGitDB, CmdPartialGitDB):
19+
"""A repository which uses the pure implementation primarily, but falls back
20+
on using the git command for high-level functionality"""
21+
22+
class PureCompatibilityGitDB(RepoCompatibilityInterface, PureGitDB):
1023
"""Repository which uses the pure implementation primarily, but falls back
1124
to the git command implementation. Please note that the CmdGitDB does it
1225
the opposite way around."""

git/db/py/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from git.util import (
99
pool,
1010
join,
11+
isfile,
1112
normpath,
1213
abspath,
1314
dirname,
@@ -25,7 +26,8 @@
2526
from git.exc import (
2627
BadObject,
2728
AmbiguousObjectName,
28-
InvalidDBRoot
29+
InvalidGitRepositoryError,
30+
NoSuchPathError
2931
)
3032

3133
from async import ChannelThreadTask
@@ -240,7 +242,7 @@ def _initialize(self, path):
240242
epath = abspath(expandvars(expanduser(path or os.getcwd())))
241243

242244
if not exists(epath):
243-
raise InvalidDBRoot(epath)
245+
raise NoSuchPathError(epath)
244246
#END check file
245247

246248
self._working_tree_dir = None
@@ -264,7 +266,7 @@ def _initialize(self, path):
264266
# END while curpath
265267

266268
if self._git_path is None:
267-
raise InvalidDBRoot(epath)
269+
raise InvalidGitRepositoryError(epath)
268270
# END path not found
269271

270272
self._bare = self._git_path.endswith(self.repo_dir)
@@ -351,6 +353,7 @@ class PureConfigurationMixin(ConfigurationMixin):
351353

352354
def __init__(self, *args, **kwargs):
353355
"""Verify prereqs"""
356+
super(PureConfigurationMixin, self).__init__(*args, **kwargs)
354357
assert hasattr(self, 'git_dir')
355358

356359
def _path_at_level(self, level ):

git/db/py/complex.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
22
#
3-
# This module is part of PureGitDB and is released under
3+
# This module is part of PurePartialGitDB and is released under
44
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
55
from git.db.interface import HighLevelRepository
66
from base import (
@@ -12,7 +12,7 @@
1212
PureAlternatesFileMixin,
1313
PureIndexDB,
1414
)
15-
15+
from transport import PureTransportDB
1616
from resolve import PureReferencesMixin
1717

1818
from loose import PureLooseObjectODB
@@ -35,14 +35,14 @@
3535
)
3636
import os
3737

38-
__all__ = ('PureGitODB', 'PureGitDB', 'PureCompatibilityGitDB')
38+
__all__ = ('PureGitODB', 'PurePartialGitDB', 'PureCompatibilityGitDB')
3939

4040

4141
class PureGitODB(PureRootPathDB, PureObjectDBW, PureCompoundDB):
4242
"""A git-style object-only database, which contains all objects in the 'objects'
4343
subdirectory.
4444
:note: The type needs to be initialized on the ./objects directory to function,
45-
as it deals solely with object lookup. Use a PureGitDB type if you need
45+
as it deals solely with object lookup. Use a PurePartialGitDB type if you need
4646
reference and push support."""
4747
# Configuration
4848
PackDBCls = PurePackedODB
@@ -103,10 +103,10 @@ def set_ostream(self, ostream):
103103

104104

105105

106-
class PureGitDB(PureGitODB,
106+
class PurePartialGitDB(PureGitODB,
107107
PureRepositoryPathsMixin, PureConfigurationMixin,
108108
PureReferencesMixin, PureSubmoduleDB, PureAlternatesFileMixin,
109-
PureIndexDB,
109+
PureIndexDB, PureTransportDB
110110
# HighLevelRepository Currently not implemented !
111111
):
112112
"""Git like database with support for object lookup as well as reference resolution.
@@ -119,10 +119,10 @@ class PureGitDB(PureGitODB,
119119
def __init__(self, root_path):
120120
"""Initialize ourselves on the .git directory, or the .git/objects directory."""
121121
PureRepositoryPathsMixin._initialize(self, root_path)
122-
super(PureGitDB, self).__init__(self.objects_dir)
122+
super(PurePartialGitDB, self).__init__(self.objects_dir)
123123

124124

125125

126-
class PureCompatibilityGitDB(PureGitDB, RepoCompatibilityInterface):
126+
class PureCompatibilityGitDB(PurePartialGitDB, RepoCompatibilityInterface):
127127
"""Pure git database with a compatability layer required by 0.3x code"""
128128

git/db/py/resolve.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ def tags(self):
320320
return self.TagReferenceCls.list_items(self)
321321

322322
def tag(self, name):
323-
return self.tags[name]
324-
323+
return self.TagReferenceCls(self, self.TagReferenceCls.to_full_path(name))
325324

326325
def commit(self, rev=None):
327326
if rev is None:

git/exc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ class UnsupportedOperation(ODBError):
4343
"""Thrown if the given operation cannot be supported by the object database"""
4444

4545

46-
class InvalidGitRepositoryError(GitPythonError):
46+
class InvalidGitRepositoryError(InvalidDBRoot):
4747
""" Thrown if the given repository appears to have an invalid format. """
4848

4949

50-
class NoSuchPathError(GitPythonError):
50+
class NoSuchPathError(InvalidDBRoot):
5151
""" Thrown if a path could not be access by the system. """
5252

5353

git/objects/base.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
join_path_native,
1515
stream_copy
1616
)
17-
17+
from git.db.interface import RepositoryPathsMixin
18+
from git.exc import UnsupportedOperation
1819
from git.typ import ObjectType
1920

2021
_assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r"
@@ -173,7 +174,15 @@ def abspath(self):
173174
Absolute path to this index object in the file system ( as opposed to the
174175
.path field which is a path relative to the git repository ).
175176
176-
The returned path will be native to the system and contains '\' on windows. """
177-
assert False, "Only works if repository is not bare - provide this check in an interface"
178-
return join_path_native(dirname(self.odb.root_path()), self.path)
177+
The returned path will be native to the system and contains '\' on windows.
178+
:raise UnsupportedOperation: if underlying odb does not support the required method to obtain a working dir"""
179+
# TODO: Here we suddenly need something better than a plain object database
180+
# which indicates our odb should better be named repo !
181+
root = ''
182+
if isinstance(self.odb, RepositoryPathsMixin):
183+
root = self.odb.working_tree_dir
184+
else:
185+
raise UnsupportedOperation("Cannot provide absolute path from a database without Repository path support")
186+
#END handle odb type
187+
return join_path_native(root, self.path)
179188

git/objects/submodule/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class UpdateProgress(RemoteProgress):
5858
# IndexObject comes via util module, its a 'hacky' fix thanks to pythons import
5959
# mechanism which cause plenty of trouble of the only reason for packages and
6060
# modules is refactoring - subpackages shoudn't depend on parent packages
61-
class Submodule(Iterable, Traversable, RepoAliasMixin):
61+
class Submodule(util.IndexObject, Iterable, Traversable, RepoAliasMixin):
6262
"""Implements access to a git submodule. They are special in that their sha
6363
represents a commit in the submodule's repository which is to be checked out
6464
at the path of this instance.

git/refs/reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, repo, path):
2828
Path relative to the .git/ directory pointing to the ref in question, i.e.
2929
refs/heads/master"""
3030
if not path.startswith(self._common_path_default+'/'):
31-
raise ValueError("Cannot instantiate %r from path %s" % ( self.__class__.__name__, path ))
31+
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__))
3232
super(Reference, self).__init__(repo, path)
3333

3434

git/refs/symbolic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def set_commit(self, commit, logmsg = None):
237237
is_invalid_type = commit.object.type != self.CommitCls.type
238238
else:
239239
try:
240-
is_invalid_type = self.repo.resolve(commit).type != self.CommitCls.type
240+
is_invalid_type = self.repo.resolve_object(commit).type != self.CommitCls.type
241241
except BadObject:
242242
raise ValueError("Invalid object: %s" % commit)
243243
#END handle exception
@@ -293,7 +293,7 @@ def set_reference(self, ref, logmsg = None):
293293
write_value = ref.hexsha
294294
elif isinstance(ref, basestring):
295295
try:
296-
obj = self.repo.resolve(ref+"^{}") # optionally deref tags
296+
obj = self.repo.resolve_object(ref+"^{}") # optionally deref tags
297297
write_value = obj.hexsha
298298
except BadObject:
299299
raise ValueError("Could not extract object from %s" % ref)
@@ -481,7 +481,7 @@ def _create(cls, repo, path, resolve, reference, force, logmsg=None):
481481
elif isinstance(reference, SymbolicReference):
482482
target = reference.object.hexsha
483483
else:
484-
target = repo.resolve(str(reference))
484+
target = repo.resolve_object(str(reference))
485485
#END handle resoltion
486486
#END need resolution
487487

git/repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66
"""This module is just to maintain compatibility to git-python 0.3x"""
77

8-
from git.db.cmd.complex import CmdCompatibilityGitDB
8+
from git.db.complex import CmdCompatibilityGitDB
99

1010

1111
import warnings

0 commit comments

Comments
 (0)