Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16a1327

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 parent023dc12 commit16a1327

File tree

12 files changed

+209
-6
lines changed

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
defdb_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
raiseNotImplementedError()
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
defroot_path(self):
109109
returnself._root_path
110110

111-
defdb_path(self,rela_path):
111+
defdb_path(self,rela_path=None):
112+
ifnotrela_path:
113+
returnself._root_path
112114
returnjoin(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+
definit_pygit2():
4+
""":raise ImportError: if pygit2 is not present"""
5+
try:
6+
importpygit2
7+
exceptImportError:
8+
raiseImportError("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+
fromgit.db.py.compleximportPureGitODB
5+
fromgit.db.py.baseimport (
6+
PureRepositoryPathsMixin,
7+
PureConfigurationMixin,
8+
PureIndexDB,
9+
)
10+
fromgit.db.py.resolveimportPureReferencesMixin
11+
fromgit.db.py.transportimportPureTransportDB
12+
fromgit.db.py.submoduleimportPureSubmoduleDB
13+
14+
fromgit.db.cmd.compleximportCmdHighLevelRepository,GitCommandMixin
15+
fromgit.db.compatimportRepoCompatibilityInterface
16+
17+
frompygit2importRepositoryasPygit2Repo
18+
19+
fromgit.baseimportOInfo,OStream
20+
fromgit.funimporttype_id_to_type_map,type_to_type_id_map
21+
22+
fromcStringIOimportStringIO
23+
importos
24+
25+
26+
classPygit2GitODB(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+
ifhasattr(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+
printobjects_root
38+
printwd
39+
self._py2_repo=Pygit2Repo(wd)
40+
41+
def__getattr__(self,attr):
42+
try:
43+
# supply LazyMixin with this call first
44+
returnsuper(Pygit2GitODB,self).__getattr__(attr)
45+
exceptAttributeError:
46+
# now assume its on the pygit2 repository ... for now
47+
returngetattr(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+
classPygit2GitDB(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+
classPygit2CompatibilityGitDB(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-
classTestPyDBBase(RepoBase):
23+
classTestDulwichDBBase(RepoBase):
2424
__metaclass__=DulwichRequiredMetaMixin
2525
RepoCls=DulwichDB
2626

2727
@needs_dulwich_or_skip
2828
@with_rw_repo('HEAD',bare=False)
2929
deftest_basics(self,rw_repo):
3030
db=DulwichDB(rw_repo.working_tree_dir)
31-
printdb.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+
fromgit.test.libimport (
4+
InheritedTestMethodsOverrideWrapperMetaClsAutoMixin,
5+
needs_module_or_skip
6+
)
7+
8+
__all__= ['needs_pygit2_or_skip','Pygit2RequiredMetaMixin']
9+
10+
#{ Decoorators
11+
12+
defneeds_pygit2_or_skip(func):
13+
"""Skip this test if we have no pygit2 - print warning"""
14+
returnneeds_module_or_skip('pygit2')(func)
15+
16+
#}END decorators
17+
18+
#{ MetaClasses
19+
20+
classPygit2RequiredMetaMixin(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+
fromlibimport*
6+
fromgit.test.libimportTestBase,with_rw_repo
7+
fromgit.test.db.baseimportRepoBase
8+
9+
10+
11+
try:
12+
importpygit2
13+
exceptImportError:
14+
# om this case, all other pygit2 tests will be skipped
15+
# Need to properly initialize the class though, otherwise it would fail
16+
fromgit.db.compleximportPureCompatibilityGitDBasPygit2DB
17+
else:
18+
# now we know pygit2 is available, to do futher imports
19+
fromgit.db.pygit2.compleximportPygit2CompatibilityGitDBasPygit2DB
20+
21+
#END handle imports
22+
23+
classTestPyGit2DBBase(RepoBase):
24+
__metaclass__=Pygit2RequiredMetaMixin
25+
RepoCls=Pygit2DB
26+
27+
@needs_pygit2_or_skip
28+
@with_rw_repo('HEAD',bare=False)
29+
deftest_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-
fromgit.db.dulwich.compleximportDulwichGitODB
1+
try:
2+
fromgit.db.dulwich.compleximportDulwichGitODB
3+
exceptImportError:
4+
fromgit.db.py.compleximportPureGitODBasDulwichGitODB
5+
#END handle import
6+
7+
fromgit.test.db.dulwich.libimportDulwichRequiredMetaMixin
28
fromlooseodb_implimportTestLooseDBWPerformanceBase
39

410
classTestPureLooseDB(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+
fromgit.db.pygit2.compleximportPygit2GitODB
3+
exceptImportError:
4+
fromgit.db.py.compleximportPureGitODBasPygit2GitODB
5+
#END handle import
6+
7+
fromgit.test.db.pygit2.libimportPygit2RequiredMetaMixin
8+
fromlooseodb_implimportTestLooseDBWPerformanceBase
9+
10+
classTestPureLooseDB(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-
fromgit.db.dulwich.compleximportDulwichCompatibilityGitDB
1+
try:
2+
fromgit.db.dulwich.compleximportDulwichCompatibilityGitDB
3+
exceptImportError:
4+
fromgit.db.compleximportPureCompatibilityGitDBasDulwichCompatibilityGitDB
5+
#END handle dulwich compatibility
6+
7+
fromgit.test.db.dulwich.libimportDulwichRequiredMetaMixin
28
fromodb_implimportTestObjDBPerformanceBase
39

410
classTestPureDB(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+
fromgit.db.dulwich.compleximportDulwichCompatibilityGitDB
3+
exceptImportError:
4+
fromgit.db.compleximportPureCompatibilityGitDBasDulwichCompatibilityGitDB
5+
#END handle dulwich compatibility
6+
7+
fromgit.test.db.dulwich.libimportDulwichRequiredMetaMixin
8+
fromodb_implimportTestObjDBPerformanceBase
9+
10+
classTestPureDB(TestObjDBPerformanceBase):
11+
__metaclass__=DulwichRequiredMetaMixin
12+
RepoCls=DulwichCompatibilityGitDB
13+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp