1414 )
1515
1616from util import (
17+ pool ,
1718 ENOENT ,
1819 to_hex_sha ,
1920 exists ,
3233 stream_copy
3334 )
3435
36+
37+ from async import (
38+ ChannelThreadTask
39+ )
40+
3541import tempfile
3642import mmap
3743import os
4046__all__ = ('ObjectDBR' , 'ObjectDBW' , 'FileDBBase' , 'LooseObjectDB' , 'PackedDB' ,
4147 'CompoundDB' , 'ReferenceDB' , 'GitObjectDB' )
4248
49+
4350class ObjectDBR (object ):
4451 """Defines an interface for object database lookup.
4552 Objects are identified either by hex-sha (40 bytes) or
@@ -52,34 +59,48 @@ def __contains__(self, sha):
5259 def has_object (self , sha ):
5360 """
5461 :return: True if the object identified by the given 40 byte hexsha or 20 bytes
55- binary sha is contained in the database
56- :raise BadObject:"""
62+ binary sha is contained in the database"""
5763 raise NotImplementedError ("To be implemented in subclass" )
5864
65+ def has_object_async (self , reader ):
66+ """Return a reader yielding information about the membership of objects
67+ as identified by shas
68+ :param reader: Reader yielding 20 byte or 40 byte shas.
69+ :return: async.Reader yielding tuples of (sha, bool) pairs which indicate
70+ whether the given sha exists in the database or not"""
71+ task = ChannelThreadTask (reader , str (self .has_object_async ), lambda sha : (sha , self .has_object (sha )))
72+ return pool .add_task (task )
73+
5974 def info (self , sha ):
6075 """ :return: OInfo instance
6176 :param sha: 40 bytes hexsha or 20 bytes binary sha
6277 :raise BadObject:"""
6378 raise NotImplementedError ("To be implemented in subclass" )
6479
65- def info_async (self , input_channel ):
80+ def info_async (self , reader ):
6681 """Retrieve information of a multitude of objects asynchronously
67- :param input_channel: Channel yielding the sha's of the objects of interest
68- :return: Channel yielding OInfo|InvalidOInfo, in any order"""
69- raise NotImplementedError ("To be implemented in subclass" )
82+ :param reader: Channel yielding the sha's of the objects of interest
83+ :return: async.Reader yielding OInfo|InvalidOInfo, in any order"""
84+ task = ChannelThreadTask (reader , str (self .info_async ), self .info )
85+ return pool .add_task (task )
7086
7187 def stream (self , sha ):
7288 """:return: OStream instance
7389 :param sha: 40 bytes hexsha or 20 bytes binary sha
7490 :raise BadObject:"""
7591 raise NotImplementedError ("To be implemented in subclass" )
7692
77- def stream_async (self , input_channel ):
93+ def stream_async (self , reader ):
7894 """Retrieve the OStream of multiple objects
79- :param input_channel : see ``info``
95+ :param reader : see ``info``
8096 :param max_threads: see ``ObjectDBW.store``
81- :return: Channel yielding OStream|InvalidOStream instances in any order"""
82- raise NotImplementedError ("To be implemented in subclass" )
97+ :return: async.Reader yielding OStream|InvalidOStream instances in any order
98+ :note: depending on the system configuration, it might not be possible to
99+ read all OStreams at once. Instead, read them individually using reader.read(x)
100+ where x is small enough."""
101+ # base implementation just uses the stream method repeatedly
102+ task = ChannelThreadTask (reader , str (self .stream_async ), self .stream )
103+ return pool .add_task (task )
83104
84105 #} END query interface
85106
@@ -114,21 +135,23 @@ def store(self, istream):
114135 :raise IOError: if data could not be written"""
115136 raise NotImplementedError ("To be implemented in subclass" )
116137
117- def store_async (self , input_channel ):
138+ def store_async (self , reader ):
118139 """Create multiple new objects in the database asynchronously. The method will
119140 return right away, returning an output channel which receives the results as
120141 they are computed.
121142
122143 :return: Channel yielding your IStream which served as input, in any order.
123144 The IStreams sha will be set to the sha it received during the process,
124145 or its error attribute will be set to the exception informing about the error.
125- :param input_channel: Channel yielding IStream instance .
126- As the same instances will be used in the output channel, you can create a map
127- between the id(istream) -> istream
128- :note:As some ODB implementations implement this operation as atomic, they might
146+ :param reader: async.Reader yielding IStream instances .
147+ The same instances will be used in the output channel as were received
148+ in by the Reader.
149+ :note:As some ODB implementations implement this operation atomic, they might
129150 abort the whole operation if one item could not be processed. Hence check how
130151 many items have actually been produced."""
131- raise NotImplementedError ("To be implemented in subclass" )
152+ # base implementation uses store to perform the work
153+ task = ChannelThreadTask (reader , str (self .store_async ), self .store )
154+ return pool .add_task (task )
132155
133156 #} END edit interface
134157
0 commit comments