|
17 | 17 | from pygit2 import Repository as Pygit2Repo
|
18 | 18 |
|
19 | 19 | 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 |
21 | 22 |
|
22 | 23 | from cStringIO import StringIO
|
23 | 24 | import os
|
@@ -49,23 +50,25 @@ def __getattr__(self, attr):
|
49 | 50 |
|
50 | 51 | #{ Object DBR
|
51 | 52 |
|
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 | + |
60 | 61 | # #}END object dbr
|
61 | 62 | #
|
62 | 63 | # #{ 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 |
69 | 72 |
|
70 | 73 | #}END object dbw
|
71 | 74 |
|
|
0 commit comments