/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
# Written by Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
17
17
 
18
18
"""Bzrlib specific gzip tunings. We plan to feed these to the upstream gzip."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
from cStringIO import StringIO
21
23
 
22
24
# make GzipFile faster:
27
29
import zlib
28
30
 
29
31
# we want a \n preserved, break on \n only splitlines.
30
 
import bzrlib
 
32
from bzrlib import symbol_versioning
31
33
 
32
34
__all__ = ["GzipFile", "bytes_to_gzip"]
33
35
 
118
120
    Yes, its only 1.6 seconds, but they add up.
119
121
    """
120
122
 
 
123
    def __init__(self, *args, **kwargs):
 
124
        symbol_versioning.warn(
 
125
            symbol_versioning.deprecated_in((2, 3, 0))
 
126
            % 'bzrlib.tuned_gzip.GzipFile',
 
127
            DeprecationWarning, stacklevel=2)
 
128
        gzip.GzipFile.__init__(self, *args, **kwargs)
 
129
 
121
130
    def _add_read_data(self, data):
122
131
        # 4169 calls in 183
123
132
        # temp var for len(data) and switch to +='s.
395
404
        # (4 seconds to 1 seconds for the sample upgrades I was testing).
396
405
        self.write(''.join(lines))
397
406
 
 
407
    if sys.version_info > (2, 7):
 
408
        # As of Python 2.7 the crc32 must be positive when close is called
 
409
        def close(self):
 
410
            if self.fileobj is None:
 
411
                return
 
412
            if self.mode == gzip.WRITE:
 
413
                self.crc &= 0xFFFFFFFFL
 
414
            gzip.GzipFile.close(self)
398
415