~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/groupcompress.py

  • Committer: Alexander Belchenko
  • Date: 2012-03-29 08:34:13 UTC
  • mto: (6015.44.14 2.4)
  • mto: This revision was merged to the branch mainline in revision 6513.
  • Revision ID: bialix@ukr.net-20120329083413-d4bqqdtfn2yrxp4f
change st_dev, st_ino, st_uid, st_gid from int members to properties.

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