248
250
' got out of sync with the line counter.')
249
251
self.endpoint = endpoint
253
def _flush_insert(self, start_linenum, end_linenum,
254
new_lines, out_lines, index_lines):
255
"""Add an 'insert' request to the data stream."""
256
bytes_to_insert = ''.join(new_lines[start_linenum:end_linenum])
257
insert_length = len(bytes_to_insert)
258
# Each insert instruction is at most 127 bytes long
259
for start_byte in xrange(0, insert_length, 127):
260
insert_count = min(insert_length - start_byte, 127)
261
out_lines.append(chr(insert_count))
262
# Don't index the 'insert' instruction
263
index_lines.append(False)
264
insert = bytes_to_insert[start_byte:start_byte+insert_count]
265
as_lines = osutils.split_lines(insert)
266
out_lines.extend(as_lines)
267
index_lines.extend([True]*len(as_lines))
269
def _flush_copy(self, old_start_linenum, num_lines,
270
out_lines, index_lines):
271
if old_start_linenum == 0:
274
first_byte = self.line_offsets[old_start_linenum - 1]
275
stop_byte = self.line_offsets[old_start_linenum + num_lines - 1]
276
num_bytes = stop_byte - first_byte
277
# The data stream allows >64kB in a copy, but to match the compiled
278
# code, we will also limit it to a 64kB copy
279
for start_byte in xrange(first_byte, stop_byte, 64*1024):
280
num_bytes = min(64*1024, stop_byte - start_byte)
281
copy_bytes = encode_copy_instruction(start_byte, num_bytes)
282
out_lines.append(copy_bytes)
283
index_lines.append(False)
251
285
def make_delta(self, new_lines, bytes_length=None, soft=False):
252
286
"""Compute the delta for this content versus the original content."""
253
287
if bytes_length is None: