~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_py.py

  • Committer: Patch Queue Manager
  • Date: 2014-02-12 18:22:22 UTC
  • mfrom: (6589.2.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20140212182222-beouo25gaf1cny76
(vila) The XDG Base Directory Specification uses the XDG_CACHE_HOME,
 not XDG_CACHE_DIR. (Andrew Starr-Bochicchio)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
useless stuff.
21
21
"""
22
22
 
 
23
from __future__ import absolute_import
 
24
 
23
25
from bzrlib import osutils
24
26
 
25
27
 
248
250
                ' got out of sync with the line counter.')
249
251
        self.endpoint = endpoint
250
252
 
 
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))
 
268
 
 
269
    def _flush_copy(self, old_start_linenum, num_lines,
 
270
                    out_lines, index_lines):
 
271
        if old_start_linenum == 0:
 
272
            first_byte = 0
 
273
        else:
 
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)
 
284
 
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: