~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-20 12:19:29 UTC
  • mfrom: (6437.23.11 2.5)
  • mto: (6581.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 6582.
  • Revision ID: jelmer@samba.org-20120220121929-7ni2psvjoatm1yp4
Merge bzr/2.5.

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(), """
39
37
    )
40
38
 
41
39
from bzrlib.repofmt import pack_repo
 
40
from bzrlib.i18n import gettext
42
41
""")
43
42
 
44
43
from bzrlib.btree_index import BTreeBuilder
56
55
# groupcompress blocks.
57
56
BATCH_SIZE = 2**16
58
57
 
59
 
_USE_LZMA = False and (pylzma is not None)
60
 
 
61
58
# osutils.sha_string('')
62
59
_null_sha1 = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
63
60
 
152
149
                self._content = ''
153
150
            elif self._compressor_name == 'lzma':
154
151
                # We don't do partial lzma decomp yet
 
152
                import pylzma
155
153
                self._content = pylzma.decompress(z_content)
156
154
            elif self._compressor_name == 'zlib':
157
155
                # Start a zlib decompressor
298
296
        self._content = content
299
297
        self._z_content_chunks = None
300
298
 
301
 
    def _create_z_content_using_lzma(self):
302
 
        if self._content_chunks is not None:
303
 
            self._content = ''.join(self._content_chunks)
304
 
            self._content_chunks = None
305
 
        if self._content is None:
306
 
            raise AssertionError('Nothing to compress')
307
 
        z_content = pylzma.compress(self._content)
308
 
        self._z_content_chunks = (z_content,)
309
 
        self._z_content_length = len(z_content)
310
 
 
311
299
    def _create_z_content_from_chunks(self, chunks):
312
300
        compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION)
313
301
        # Peak in this point is 1 fulltext, 1 compressed text, + zlib overhead
321
309
    def _create_z_content(self):
322
310
        if self._z_content_chunks is not None:
323
311
            return
324
 
        if _USE_LZMA:
325
 
            self._create_z_content_using_lzma()
326
 
            return
327
312
        if self._content_chunks is not None:
328
313
            chunks = self._content_chunks
329
314
        else:
333
318
    def to_chunks(self):
334
319
        """Create the byte stream as a series of 'chunks'"""
335
320
        self._create_z_content()
336
 
        if _USE_LZMA:
337
 
            header = self.GCB_LZ_HEADER
338
 
        else:
339
 
            header = self.GCB_HEADER
 
321
        header = self.GCB_HEADER
340
322
        chunks = ['%s%d\n%d\n'
341
323
                  % (header, self._z_content_length, self._content_length),
342
324
                 ]
1754
1736
                raise errors.RevisionNotPresent(record.key, self)
1755
1737
            if random_id:
1756
1738
                if record.key in inserted_keys:
1757
 
                    trace.note('Insert claimed random_id=True,'
1758
 
                               ' but then inserted %r two times', record.key)
 
1739
                    trace.note(gettext('Insert claimed random_id=True,'
 
1740
                               ' but then inserted %r two times'), record.key)
1759
1741
                    continue
1760
1742
                inserted_keys.add(record.key)
1761
1743
            if reuse_blocks: