|
41 | 41 |
|
42 | 42 | __all__ = ('is_loose_object', 'loose_object_header_info', 'msb_size', 'pack_object_header_info', |
43 | 43 | 'write_object', 'loose_object_header', 'stream_copy', 'apply_delta_data', |
44 | | - 'is_equal_canonical_sha' ) |
| 44 | + 'is_equal_canonical_sha', 'apply_delta_chunks', 'reverse_merge_deltas', |
| 45 | + 'merge_deltas') |
| 46 | + |
| 47 | + |
| 48 | +#{ Structures |
| 49 | + |
| 50 | +class DeltaChunk(object): |
| 51 | + """Represents a piece of a delta, it can either add new data, or copy existing |
| 52 | + one from a source buffer""" |
| 53 | + __slots__ = ( |
| 54 | + 'to', # start offset in the target buffer in bytes |
| 55 | + 'ts', # size of this chunk in the target buffer in bytes |
| 56 | + 'so', # start offset in the source buffer in bytes or None |
| 57 | + 'data' # chunk of bytes to be added to the target buffer or None |
| 58 | + ) |
| 59 | + |
| 60 | + def __init__(self, to, ts, so, data): |
| 61 | + self.to = to |
| 62 | + self.ts = ts |
| 63 | + self.so = so |
| 64 | + self.data = data |
| 65 | + |
| 66 | + #{ Interface |
| 67 | + |
| 68 | + def abssize(self): |
| 69 | + return self.to + self.ts |
| 70 | + |
| 71 | + def apply(self, source, target): |
| 72 | + """Apply own data to the target buffer |
| 73 | + :param source: buffer providing source bytes for copy operations |
| 74 | + :param target: target buffer large enough to contain all the changes to be applied""" |
| 75 | + if self.data is not None: |
| 76 | + # APPEND DATA |
| 77 | + pass |
| 78 | + else: |
| 79 | + # COPY DATA FROM SOURCE |
| 80 | + pass |
| 81 | + # END handle chunk mode |
| 82 | + |
| 83 | + #} END interface |
| 84 | + |
| 85 | +#} END structures |
45 | 86 |
|
46 | 87 | #{ Routines |
47 | 88 |
|
@@ -164,10 +205,46 @@ def stream_copy(read, write, size, chunk_size): |
164 | 205 | return dbw |
165 | 206 |
|
166 | 207 |
|
| 208 | +def reverse_merge_deltas(dcl, dstreams): |
| 209 | + """Read the condensed delta chunk information from dstream and merge its information |
| 210 | + into a list of existing delta chunks |
| 211 | + :param dcl: list of DeltaChunk objects, may be empty initially, and will be changed |
| 212 | + during the merge process |
| 213 | + :param dstreams: iterable of delta stream objects. They must be ordered latest first, |
| 214 | + hence the delta to be applied last comes first, then its ancestors |
| 215 | + :return: None""" |
| 216 | + raise NotImplementedError("This is left out up until we actually iterate the dstreams - they are prefetched right now") |
| 217 | + |
| 218 | +def merge_deltas(dcl, dstreams): |
| 219 | + """Read the condensed delta chunk information from dstream and merge its information |
| 220 | + into a list of existing delta chunks |
| 221 | + :param dcl: list of DeltaChunk objects, may be empty initially, and will be changed |
| 222 | + during the merge process |
| 223 | + :param dstreams: iterable of delta stream objects. They must be ordered latest last, |
| 224 | + hence the delta to be applied last comes last, its oldest ancestor first |
| 225 | + :return: None""" |
| 226 | + for ds in dstreams: |
| 227 | + buf = ds.read() |
| 228 | + i, src_size = msb_size(buf) |
| 229 | + i, target_size = msb_size(buf, i) |
| 230 | + |
| 231 | + # parse the commands |
| 232 | + |
| 233 | + # END for each delta stream |
| 234 | + |
| 235 | +def apply_delta_chunks(src_buf, src_buf_size, dcl, target): |
| 236 | + """ |
| 237 | + Apply data from a delta chunk list and a source buffer to the target stream |
| 238 | + |
| 239 | + :param src_buf: random access data from which the delta was created |
| 240 | + :param src_buf_size: size of the source buffer in bytes |
| 241 | + :param delta_buf_size: size fo the delta buffer in bytes |
| 242 | + :param target: ostream with a write method""" |
| 243 | + |
| 244 | + |
167 | 245 | def apply_delta_data(src_buf, src_buf_size, delta_buf, delta_buf_size, target_file): |
168 | 246 | """ |
169 | | - Apply data from a delta buffer using a source buffer to the target file, |
170 | | - which will be written to |
| 247 | + Apply data from a delta buffer using a source buffer to the target file |
171 | 248 | |
172 | 249 | :param src_buf: random access data from which the delta was created |
173 | 250 | :param src_buf_size: size of the source buffer in bytes |
|
0 commit comments