3939# used when dealing with larger streams
4040chunk_size = 1000 * mmap .PAGESIZE
4141
42- __all__ = ('is_loose_object' , 'loose_object_header_info' , 'object_header_info ' ,
43- 'write_object' )
42+ __all__ = ('is_loose_object' , 'loose_object_header_info' , 'msb_size' , 'pack_object_header_info ' ,
43+ 'write_object' , 'loose_object_header' , 'stream_copy' , 'apply_delta_data' )
4444
4545#{ Routines
4646
4747def is_loose_object (m ):
48- """:return: True the file contained in memory map m appears to be a loose object.
49- Only the first two bytes are needed"""
48+ """
49+ :return: True the file contained in memory map m appears to be a loose object.
50+ Only the first two bytes are needed"""
5051 b0 , b1 = map (ord , m [:2 ])
5152 word = (b0 << 8 ) + b1
5253 return b0 == 0x78 and (word % 31 ) == 0
5354
5455def loose_object_header_info (m ):
55- """:return: tuple(type_string, uncompressed_size_in_bytes) the type string of the
56+ """
57+ :return: tuple(type_string, uncompressed_size_in_bytes) the type string of the
5658 object as well as its uncompressed size in bytes.
5759 :param m: memory map from which to read the compressed object data"""
5860 decompress_size = 8192 # is used in cgit as well
@@ -61,9 +63,10 @@ def loose_object_header_info(m):
6163 return type_name , int (size )
6264
6365def pack_object_header_info (data ):
64- """:return: tuple(type_id, uncompressed_size_in_bytes, byte_offset)
65- The type_id should be interpreted according to the ``type_id_to_type_map`` map
66- The byte-offset specifies the start of the actual zlib compressed datastream
66+ """
67+ :return: tuple(type_id, uncompressed_size_in_bytes, byte_offset)
68+ The type_id should be interpreted according to the ``type_id_to_type_map`` map
69+ The byte-offset specifies the start of the actual zlib compressed datastream
6770 :param m: random-access memory, like a string or memory map"""
6871 c = ord (data [0 ]) # first byte
6972 i = 1 # next char to read
@@ -87,8 +90,9 @@ def pack_object_header_info(data):
8790 # END handle exceptions
8891
8992def msb_size (data , offset = 0 ):
90- """:return: tuple(read_bytes, size) read the msb size from the given random
91- access data starting at the given byte offset"""
93+ """
94+ :return: tuple(read_bytes, size) read the msb size from the given random
95+ access data starting at the given byte offset"""
9296 size = 0
9397 i = 0
9498 l = len (data )
@@ -107,12 +111,14 @@ def msb_size(data, offset=0):
107111 return i + offset , size
108112
109113def loose_object_header (type , size ):
110- """:return: string representing the loose object header, which is immediately
114+ """
115+ :return: string representing the loose object header, which is immediately
111116 followed by the content stream of size 'size'"""
112117 return "%s %i\0 " % (type , size )
113118
114119def write_object (type , size , read , write , chunk_size = chunk_size ):
115- """Write the object as identified by type, size and source_stream into the
120+ """
121+ Write the object as identified by type, size and source_stream into the
116122 target_stream
117123
118124 :param type: type string of the object
@@ -131,8 +137,10 @@ def write_object(type, size, read, write, chunk_size=chunk_size):
131137 return tbw
132138
133139def stream_copy (read , write , size , chunk_size ):
134- """Copy a stream up to size bytes using the provided read and write methods,
140+ """
141+ Copy a stream up to size bytes using the provided read and write methods,
135142 in chunks of chunk_size
143+
136144 :note: its much like stream_copy utility, but operates just using methods"""
137145 dbw = 0 # num data bytes written
138146
@@ -156,8 +164,10 @@ def stream_copy(read, write, size, chunk_size):
156164
157165
158166def apply_delta_data (src_buf , src_buf_size , delta_buf , delta_buf_size , target_file ):
159- """Apply data from a delta buffer using a source buffer to the target file,
167+ """
168+ Apply data from a delta buffer using a source buffer to the target file,
160169 which will be written to
170+
161171 :param src_buf: random access data from which the delta was created
162172 :param src_buf_size: size of the source buffer in bytes
163173 :param delta_buf_size: size fo the delta buffer in bytes
0 commit comments