Skip to content

Commit 16a1327

Browse files
committed
Added basic frame for pygit2 - it just needs some basic methods to be implemented now - depending on the performance, it might actually receive some more work
1 parent 023dc12 commit 16a1327

12 files changed

+209
-6
lines changed

git/db/interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ def root_path(self):
164164
def db_path(self, rela_path):
165165
"""
166166
:return: the given relative path relative to our database root, allowing
167-
to pontentially access datafiles"""
167+
to pontentially access datafiles
168+
:param rela_path: if not None or '', the relative path will be appended
169+
to the database root path. Otherwise you will obtain the database root path itself"""
168170
raise NotImplementedError()
169171
#} END interface
170172

git/db/py/base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ def __init__(self, root_path):
108108
def root_path(self):
109109
return self._root_path
110110

111-
def db_path(self, rela_path):
111+
def db_path(self, rela_path=None):
112+
if not rela_path:
113+
return self._root_path
112114
return join(self._root_path, rela_path)
113115
#} END interface
114116

git/db/pygit2/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""Pygit2 module initialization"""
2+
3+
def init_pygit2():
4+
""":raise ImportError: if pygit2 is not present"""
5+
try:
6+
import pygit2
7+
except ImportError:
8+
raise ImportError("Could not find 'pygit2' in the PYTHONPATH - pygit2 functionality is not available")
9+
#END handle pygit2 import
10+
11+
init_pygit2()

git/db/pygit2/complex.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
__all__ = ['Pygit2GitODB', 'Pygit2GitDB', 'Pygit2CompatibilityGitDB']
3+
4+
from git.db.py.complex import PureGitODB
5+
from git.db.py.base import (
6+
PureRepositoryPathsMixin,
7+
PureConfigurationMixin,
8+
PureIndexDB,
9+
)
10+
from git.db.py.resolve import PureReferencesMixin
11+
from git.db.py.transport import PureTransportDB
12+
from git.db.py.submodule import PureSubmoduleDB
13+
14+
from git.db.cmd.complex import CmdHighLevelRepository, GitCommandMixin
15+
from git.db.compat import RepoCompatibilityInterface
16+
17+
from pygit2 import Repository as Pygit2Repo
18+
19+
from git.base import OInfo, OStream
20+
from git.fun import type_id_to_type_map, type_to_type_id_map
21+
22+
from cStringIO import StringIO
23+
import os
24+
25+
26+
class Pygit2GitODB(PureGitODB):
27+
"""A full fledged database to read and write object files from all kinds of sources."""
28+
29+
def __init__(self, objects_root):
30+
"""Initalize this instance"""
31+
PureGitODB.__init__(self, objects_root)
32+
if hasattr(self, 'git_dir'):
33+
wd = self.git_dir
34+
else:
35+
wd = os.path.dirname(objects_root)
36+
#END try to figure out good entry for pygit2 - it needs the .gitdir
37+
print objects_root
38+
print wd
39+
self._py2_repo = Pygit2Repo(wd)
40+
41+
def __getattr__(self, attr):
42+
try:
43+
# supply LazyMixin with this call first
44+
return super(Pygit2GitODB, self).__getattr__(attr)
45+
except AttributeError:
46+
# now assume its on the pygit2 repository ... for now
47+
return getattr(self._py2_repo, attr)
48+
#END handle attr
49+
50+
#{ Object DBR
51+
52+
# def info(self, binsha):
53+
# type_id, uncomp_data = self._py2_repo.object_store.get_raw(binsha)
54+
# return OInfo(binsha, type_id_to_type_map[type_id], len(uncomp_data))
55+
#
56+
# def stream(self, binsha):
57+
# type_id, uncomp_data = self._py2_repo.object_store.get_raw(binsha)
58+
# return OStream(binsha, type_id_to_type_map[type_id], len(uncomp_data), StringIO(uncomp_data))
59+
#
60+
# #}END object dbr
61+
#
62+
# #{ Object DBW
63+
#
64+
# def store(self, istream):
65+
# obj = ShaFile.from_raw_string(type_to_type_id_map[istream.type], istream.read())
66+
# self._py2_repo.object_store.add_object(obj)
67+
# istream.binsha = obj.sha().digest()
68+
# return istream
69+
70+
#}END object dbw
71+
72+
class Pygit2GitDB( PureRepositoryPathsMixin, PureConfigurationMixin,
73+
PureReferencesMixin, PureSubmoduleDB,
74+
PureIndexDB,
75+
PureTransportDB, # not fully implemented
76+
GitCommandMixin,
77+
CmdHighLevelRepository,
78+
Pygit2GitODB): # must come last, as it doesn't pass on __init__ with super
79+
80+
81+
def __init__(self, root_path):
82+
"""Initialize ourselves on the .git directory, or the .git/objects directory."""
83+
PureRepositoryPathsMixin._initialize(self, root_path)
84+
super(Pygit2GitDB, self).__init__(self.objects_dir)
85+
86+
87+
class Pygit2CompatibilityGitDB(RepoCompatibilityInterface, Pygit2GitDB):
88+
"""Basic pygit2 compatibility database"""
89+
pass
90+

git/test/db/dulwich/test_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020

2121
#END handle imports
2222

23-
class TestPyDBBase(RepoBase):
23+
class TestDulwichDBBase(RepoBase):
2424
__metaclass__ = DulwichRequiredMetaMixin
2525
RepoCls = DulwichDB
2626

2727
@needs_dulwich_or_skip
2828
@with_rw_repo('HEAD', bare=False)
2929
def test_basics(self, rw_repo):
3030
db = DulwichDB(rw_repo.working_tree_dir)
31-
print db.git_dir
3231

3332

git/test/db/pygit2/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php

git/test/db/pygit2/lib.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""pygit2 specific utilities, as well as all the default ones"""
2+
3+
from git.test.lib import (
4+
InheritedTestMethodsOverrideWrapperMetaClsAutoMixin,
5+
needs_module_or_skip
6+
)
7+
8+
__all__ = ['needs_pygit2_or_skip', 'Pygit2RequiredMetaMixin']
9+
10+
#{ Decoorators
11+
12+
def needs_pygit2_or_skip(func):
13+
"""Skip this test if we have no pygit2 - print warning"""
14+
return needs_module_or_skip('pygit2')(func)
15+
16+
#}END decorators
17+
18+
#{ MetaClasses
19+
20+
class Pygit2RequiredMetaMixin(InheritedTestMethodsOverrideWrapperMetaClsAutoMixin):
21+
decorator = [needs_pygit2_or_skip]
22+
23+
#} END metaclasses

git/test/db/pygit2/test_base.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright (C) 2010, 2011 Sebastian Thiel (byronimo@gmail.com) and contributors
2+
#
3+
# This module is part of GitDB and is released under
4+
# the New BSD License: http://www.opensource.org/licenses/bsd-license.php
5+
from lib import *
6+
from git.test.lib import TestBase, with_rw_repo
7+
from git.test.db.base import RepoBase
8+
9+
10+
11+
try:
12+
import pygit2
13+
except ImportError:
14+
# om this case, all other pygit2 tests will be skipped
15+
# Need to properly initialize the class though, otherwise it would fail
16+
from git.db.complex import PureCompatibilityGitDB as Pygit2DB
17+
else:
18+
# now we know pygit2 is available, to do futher imports
19+
from git.db.pygit2.complex import Pygit2CompatibilityGitDB as Pygit2DB
20+
21+
#END handle imports
22+
23+
class TestPyGit2DBBase(RepoBase):
24+
__metaclass__ = Pygit2RequiredMetaMixin
25+
RepoCls = Pygit2DB
26+
27+
@needs_pygit2_or_skip
28+
@with_rw_repo('HEAD', bare=False)
29+
def test_basics(self, rw_repo):
30+
db = Pygit2DB(rw_repo.working_tree_dir)
31+
32+
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
from git.db.dulwich.complex import DulwichGitODB
1+
try:
2+
from git.db.dulwich.complex import DulwichGitODB
3+
except ImportError:
4+
from git.db.py.complex import PureGitODB as DulwichGitODB
5+
#END handle import
6+
7+
from git.test.db.dulwich.lib import DulwichRequiredMetaMixin
28
from looseodb_impl import TestLooseDBWPerformanceBase
39

410
class TestPureLooseDB(TestLooseDBWPerformanceBase):
11+
__metaclass__ = DulwichRequiredMetaMixin
512
LooseODBCls = DulwichGitODB
613

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try:
2+
from git.db.pygit2.complex import Pygit2GitODB
3+
except ImportError:
4+
from git.db.py.complex import PureGitODB as Pygit2GitODB
5+
#END handle import
6+
7+
from git.test.db.pygit2.lib import Pygit2RequiredMetaMixin
8+
from looseodb_impl import TestLooseDBWPerformanceBase
9+
10+
class TestPureLooseDB(TestLooseDBWPerformanceBase):
11+
__metaclass__ = Pygit2RequiredMetaMixin
12+
LooseODBCls = Pygit2GitODB
13+
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
from git.db.dulwich.complex import DulwichCompatibilityGitDB
1+
try:
2+
from git.db.dulwich.complex import DulwichCompatibilityGitDB
3+
except ImportError:
4+
from git.db.complex import PureCompatibilityGitDB as DulwichCompatibilityGitDB
5+
#END handle dulwich compatibility
6+
7+
from git.test.db.dulwich.lib import DulwichRequiredMetaMixin
28
from odb_impl import TestObjDBPerformanceBase
39

410
class TestPureDB(TestObjDBPerformanceBase):
11+
__metaclass__ = DulwichRequiredMetaMixin
512
RepoCls = DulwichCompatibilityGitDB
613

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
try:
2+
from git.db.dulwich.complex import DulwichCompatibilityGitDB
3+
except ImportError:
4+
from git.db.complex import PureCompatibilityGitDB as DulwichCompatibilityGitDB
5+
#END handle dulwich compatibility
6+
7+
from git.test.db.dulwich.lib import DulwichRequiredMetaMixin
8+
from odb_impl import TestObjDBPerformanceBase
9+
10+
class TestPureDB(TestObjDBPerformanceBase):
11+
__metaclass__ = DulwichRequiredMetaMixin
12+
RepoCls = DulwichCompatibilityGitDB
13+

0 commit comments

Comments
 (0)