~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_py.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-14 00:01:32 UTC
  • mfrom: (4957.1.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100114000132-3p3rabnonjw3gzqb
(jam) Merge bzr.stable, bringing in bug fixes #175839, #504390

Show diffs side-by-side

added added

removed removed

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