~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: Patch Queue Manager
  • Date: 2015-12-17 18:39:00 UTC
  • mfrom: (6606.1.2 fix-float)
  • Revision ID: pqm@pqm.ubuntu.com-20151217183900-0719du2uv1kwu3lc
(vila) Inline testtools private method to fix an issue in xenial (the
 private implementation has changed in an backward incompatible way).
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Core compression logic for compressing streams of related files."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import time
20
22
import zlib
21
 
try:
22
 
    import pylzma
23
 
except ImportError:
24
 
    pylzma = None
25
23
 
26
24
from bzrlib.lazy_import import lazy_import
27
25
lazy_import(globals(), """
57
55
# groupcompress blocks.
58
56
BATCH_SIZE = 2**16
59
57
 
60
 
_USE_LZMA = False and (pylzma is not None)
61
 
 
62
58
# osutils.sha_string('')
63
59
_null_sha1 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
64
60
 
153
149
                self._content = ''
154
150
            elif self._compressor_name == 'lzma':
155
151
                # We don't do partial lzma decomp yet
 
152
                import pylzma
156
153
                self._content = pylzma.decompress(z_content)
157
154
            elif self._compressor_name == 'zlib':
158
155
                # Start a zlib decompressor
299
296
        self._content = content
300
297
        self._z_content_chunks = None
301
298
 
302
 
    def _create_z_content_using_lzma(self):
303
 
        if self._content_chunks is not None:
304
 
            self._content = ''.join(self._content_chunks)
305
 
            self._content_chunks = None
306
 
        if self._content is None:
307
 
            raise AssertionError('Nothing to compress')
308
 
        z_content = pylzma.compress(self._content)
309
 
        self._z_content_chunks = (z_content,)
310
 
        self._z_content_length = len(z_content)
311
 
 
312
299
    def _create_z_content_from_chunks(self, chunks):
313
300
        compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION)
314
301
        # Peak in this point is 1 fulltext, 1 compressed text, + zlib overhead
322
309
    def _create_z_content(self):
323
310
        if self._z_content_chunks is not None:
324
311
            return
325
 
        if _USE_LZMA:
326
 
            self._create_z_content_using_lzma()
327
 
            return
328
312
        if self._content_chunks is not None:
329
313
            chunks = self._content_chunks
330
314
        else:
334
318
    def to_chunks(self):
335
319
        """Create the byte stream as a series of 'chunks'"""
336
320
        self._create_z_content()
337
 
        if _USE_LZMA:
338
 
            header = self.GCB_LZ_HEADER
339
 
        else:
340
 
            header = self.GCB_HEADER
 
321
        header = self.GCB_HEADER
341
322
        chunks = ['%s%d\n%d\n'
342
323
                  % (header, self._z_content_length, self._content_length),
343
324
                 ]