Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5a0fa2

Browse files
committed
Fixed up tests to actually use pygit2. Its worth noting that the performance tests only work reliably in a patched up version, or the next point release.
1 parent 16a1327 commit a5a0fa2

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

git/db/pygit2/complex.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
from pygit2 import Repository as Pygit2Repo
1818

1919
from git.base import OInfo, OStream
20-
from git.fun import type_id_to_type_map, type_to_type_id_map
20+
from git.fun import type_id_to_type_map, type_to_type_id_map
21+
from git.util import hex_to_bin
2122

2223
from cStringIO import StringIO
2324
import os
@@ -49,23 +50,25 @@ def __getattr__(self, attr):
4950

5051
#{ Object DBR
5152

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-
#
53+
def info(self, binsha):
54+
type_id, uncomp_data = self._py2_repo.read(binsha)
55+
return OInfo(binsha, type_id_to_type_map[type_id], len(uncomp_data))
56+
57+
def stream(self, binsha):
58+
type_id, uncomp_data = self._py2_repo.read(binsha)
59+
return OStream(binsha, type_id_to_type_map[type_id], len(uncomp_data), StringIO(uncomp_data))
60+
6061
# #}END object dbr
6162
#
6263
# #{ 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
64+
def store(self, istream):
65+
# TODO: remove this check once the required functionality was merged in pygit2
66+
if hasattr(self._py2_repo, 'write'):
67+
istream.binsha = hex_to_bin(self._py2_repo.write(type_to_type_id_map[istream.type], istream.read()))
68+
return istream
69+
else:
70+
return super(Pygit2GitODB, self).store(istream)
71+
#END handle write support
6972

7073
#}END object dbw
7174

git/test/performance/db/test_odb_dulwich.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from git.test.db.dulwich.lib import DulwichRequiredMetaMixin
88
from odb_impl import TestObjDBPerformanceBase
99

10-
class TestPureDB(TestObjDBPerformanceBase):
10+
class TestDulwichDB(TestObjDBPerformanceBase):
1111
__metaclass__ = DulwichRequiredMetaMixin
1212
RepoCls = DulwichCompatibilityGitDB
1313

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
try:
2-
from git.db.dulwich.complex import DulwichCompatibilityGitDB
2+
from git.db.pygit2.complex import Pygit2CompatibilityGitDB
33
except ImportError:
4-
from git.db.complex import PureCompatibilityGitDB as DulwichCompatibilityGitDB
5-
#END handle dulwich compatibility
4+
from git.db.complex import PureCompatibilityGitDB as Pygit2CompatibilityGitDB
5+
#END handle pygit2 compatibility
66

7-
from git.test.db.dulwich.lib import DulwichRequiredMetaMixin
7+
from git.test.db.pygit2.lib import Pygit2RequiredMetaMixin
88
from odb_impl import TestObjDBPerformanceBase
99

10-
class TestPureDB(TestObjDBPerformanceBase):
11-
__metaclass__ = DulwichRequiredMetaMixin
12-
RepoCls = DulwichCompatibilityGitDB
10+
class TestPygit2DB(TestObjDBPerformanceBase):
11+
__metaclass__ = Pygit2RequiredMetaMixin
12+
RepoCls = Pygit2CompatibilityGitDB
1313

0 commit comments

Comments
 (0)