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

Commita848569

Browse files
committed
Merge branch 'pygit2'
2 parents023dc12 +a5a0fa2 commita848569

File tree

12 files changed

+213
-7
lines changed

12 files changed

+213
-7
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: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
fromgit.utilimporthex_to_bin
22+
23+
fromcStringIOimportStringIO
24+
importos
25+
26+
27+
classPygit2GitODB(PureGitODB):
28+
"""A full fledged database to read and write object files from all kinds of sources."""
29+
30+
def__init__(self,objects_root):
31+
"""Initalize this instance"""
32+
PureGitODB.__init__(self,objects_root)
33+
ifhasattr(self,'git_dir'):
34+
wd=self.git_dir
35+
else:
36+
wd=os.path.dirname(objects_root)
37+
#END try to figure out good entry for pygit2 - it needs the .gitdir
38+
printobjects_root
39+
printwd
40+
self._py2_repo=Pygit2Repo(wd)
41+
42+
def__getattr__(self,attr):
43+
try:
44+
# supply LazyMixin with this call first
45+
returnsuper(Pygit2GitODB,self).__getattr__(attr)
46+
exceptAttributeError:
47+
# now assume its on the pygit2 repository ... for now
48+
returngetattr(self._py2_repo,attr)
49+
#END handle attr
50+
51+
#{ Object DBR
52+
53+
definfo(self,binsha):
54+
type_id,uncomp_data=self._py2_repo.read(binsha)
55+
returnOInfo(binsha,type_id_to_type_map[type_id],len(uncomp_data))
56+
57+
defstream(self,binsha):
58+
type_id,uncomp_data=self._py2_repo.read(binsha)
59+
returnOStream(binsha,type_id_to_type_map[type_id],len(uncomp_data),StringIO(uncomp_data))
60+
61+
# #}END object dbr
62+
#
63+
# #{ Object DBW
64+
defstore(self,istream):
65+
# TODO: remove this check once the required functionality was merged in pygit2
66+
ifhasattr(self._py2_repo,'write'):
67+
istream.binsha=hex_to_bin(self._py2_repo.write(type_to_type_id_map[istream.type],istream.read()))
68+
returnistream
69+
else:
70+
returnsuper(Pygit2GitODB,self).store(istream)
71+
#END handle write support
72+
73+
#}END object dbw
74+
75+
classPygit2GitDB(PureRepositoryPathsMixin,PureConfigurationMixin,
76+
PureReferencesMixin,PureSubmoduleDB,
77+
PureIndexDB,
78+
PureTransportDB,# not fully implemented
79+
GitCommandMixin,
80+
CmdHighLevelRepository,
81+
Pygit2GitODB):# must come last, as it doesn't pass on __init__ with super
82+
83+
84+
def__init__(self,root_path):
85+
"""Initialize ourselves on the .git directory, or the .git/objects directory."""
86+
PureRepositoryPathsMixin._initialize(self,root_path)
87+
super(Pygit2GitDB,self).__init__(self.objects_dir)
88+
89+
90+
classPygit2CompatibilityGitDB(RepoCompatibilityInterface,Pygit2GitDB):
91+
"""Basic pygit2 compatibility database"""
92+
pass
93+

‎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: 9 additions & 2 deletions
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

4-
classTestPureDB(TestObjDBPerformanceBase):
10+
classTestDulwichDB(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.pygit2.compleximportPygit2CompatibilityGitDB
3+
exceptImportError:
4+
fromgit.db.compleximportPureCompatibilityGitDBasPygit2CompatibilityGitDB
5+
#END handle pygit2 compatibility
6+
7+
fromgit.test.db.pygit2.libimportPygit2RequiredMetaMixin
8+
fromodb_implimportTestObjDBPerformanceBase
9+
10+
classTestPygit2DB(TestObjDBPerformanceBase):
11+
__metaclass__=Pygit2RequiredMetaMixin
12+
RepoCls=Pygit2CompatibilityGitDB
13+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp