5555
5656def pack_object_at (data , offset , as_stream ):
5757 """
58- :return: PackInfo|PackStream
58+ :return: Tuple(abs_data_offset, PackInfo|PackStream)
5959 an object of the correct type according to the type_id of the object.
6060 If as_stream is True, the object will contain a stream, allowing the
6161 data to be read decompressed.
@@ -97,14 +97,14 @@ def pack_object_at(data, offset, as_stream):
9797 if as_stream :
9898 stream = DecompressMemMapReader (buffer (data , total_rela_offset ), False , uncomp_size )
9999 if delta_info is None :
100- return OPackStream (offset , abs_data_offset , type_id , uncomp_size , stream )
100+ return abs_data_offset , OPackStream (offset , type_id , uncomp_size , stream )
101101 else :
102- return ODeltaPackStream (offset , abs_data_offset , type_id , uncomp_size , delta_info , stream )
102+ return abs_data_offset , ODeltaPackStream (offset , type_id , uncomp_size , delta_info , stream )
103103 else :
104104 if delta_info is None :
105- return OPackInfo (offset , abs_data_offset , type_id , uncomp_size )
105+ return abs_data_offset , OPackInfo (offset , type_id , uncomp_size )
106106 else :
107- return ODeltaPackInfo (offset , abs_data_offset , type_id , uncomp_size , delta_info )
107+ return abs_data_offset , ODeltaPackInfo (offset , type_id , uncomp_size , delta_info )
108108 # END handle info
109109 # END handle stream
110110
@@ -278,6 +278,7 @@ def sha_to_index(self, sha):
278278 if the sha was not found in this pack index
279279 :param sha: 20 byte sha to lookup"""
280280 first_byte = ord (sha [0 ])
281+ get_sha = self .sha
281282 lo = 0 # lower index, the left bound of the bisection
282283 if first_byte != 0 :
283284 lo = self ._fanout_table [first_byte - 1 ]
@@ -286,7 +287,7 @@ def sha_to_index(self, sha):
286287 # bisect until we have the sha
287288 while lo < hi :
288289 mid = (lo + hi ) / 2
289- c = cmp (sha , self . sha (mid ))
290+ c = cmp (sha , get_sha (mid ))
290291 if c < 0 :
291292 hi = mid
292293 elif not c :
@@ -346,12 +347,12 @@ def _iter_objects(self, start_offset, as_stream=True):
346347
347348 null = NullStream ()
348349 while cur_offset < content_size :
349- ostream = pack_object_at (data , cur_offset , True )
350+ data_offset , ostream = pack_object_at (data , cur_offset , True )
350351 # scrub the stream to the end - this decompresses the object, but yields
351352 # the amount of compressed bytes we need to get to the next offset
352353
353354 stream_copy (ostream .read , null .write , ostream .size , chunk_size )
354- cur_offset += (ostream . data_offset - ostream .pack_offset ) + ostream .stream .compressed_bytes_read ()
355+ cur_offset += (data_offset - ostream .pack_offset ) + ostream .stream .compressed_bytes_read ()
355356
356357
357358 # if a stream is requested, reset it beforehand
@@ -399,7 +400,7 @@ def collect_streams(self, offset):
399400 :param offset: specifies the first byte of the object within this pack"""
400401 out = list ()
401402 while True :
402- ostream = pack_object_at (self ._data , offset , True )
403+ ostream = pack_object_at (self ._data , offset , True )[ 1 ]
403404 out .append (ostream )
404405 if ostream .type_id == OFS_DELTA :
405406 offset = ostream .pack_offset - ostream .delta_info
@@ -420,13 +421,13 @@ def info(self, offset):
420421 """Retrieve information about the object at the given file-absolute offset
421422 :param offset: byte offset
422423 :return: OPackInfo instance, the actual type differs depending on the type_id attribute"""
423- return pack_object_at (self ._data , offset or self .first_object_offset , False )
424+ return pack_object_at (self ._data , offset or self .first_object_offset , False )[ 1 ]
424425
425426 def stream (self , offset ):
426427 """Retrieve an object at the given file-relative offset as stream along with its information
427428 :param offset: byte offset
428429 :return: OPackStream instance, the actual type differs depending on the type_id attribute"""
429- return pack_object_at (self ._data , offset or self .first_object_offset , True )
430+ return pack_object_at (self ._data , offset or self .first_object_offset , True )[ 1 ]
430431
431432 def stream_iter (self , start_offset = 0 ):
432433 """:return: iterator yielding OPackStream compatible instances, allowing
0 commit comments