/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/chunk_writer.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-05 14:26:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120105142658-vek3v6pzlxb751s2
Tests passing for a first rough version of a cached branch config store. The changes here are too invasive and several parallel proposals have been made. 

@only_raises is evil and gave a hard time since any exception during
save_changes() was swallowed.

Possible improvements: 

- add some needs_write_lock decorators to crucial
  methods (_set_config_location ?) but keep locking the branch at higher levels

- decorate branch.unlock to call stack.save if last_lock() it True
  outside of @only_raises scope (evil decorator)

- add @needs_write_lock to stack.set and stack.remove (will probably get
  rid of most testing issues) we probably need a specialized decorator
  that can relay to the store and from there to the branch or whatever is
  needed. This will also helps bzr config to get it right. The
  get_mutable_section trick should not be needed anymore either.

- decorate branch.unlock to call stack.save if last_lock() it True outside
  of @only_raises scope (evil decorator)

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""ChunkWriter: write compressed data out with a fixed upper bound."""
19
19
 
 
20
from __future__ import absolute_import
 
21
 
20
22
import zlib
21
23
from zlib import Z_FINISH, Z_SYNC_FLUSH
22
24
 
122
124
        bytes that did not fit in the chunk.
123
125
 
124
126
        :return: (compressed_bytes, unused_bytes, num_nulls_needed)
125
 
            compressed_bytes    a list of bytes that were output from the
126
 
                                compressor. If the compressed length was not
127
 
                                exactly chunk_size, the final string will be a
128
 
                                string of all null bytes to pad this to
129
 
                                chunk_size
130
 
            unused_bytes        None, or the last bytes that were added, which
131
 
                                we could not fit.
132
 
            num_nulls_needed    How many nulls are padded at the end
 
127
 
 
128
            * compressed_bytes: a list of bytes that were output from the
 
129
              compressor. If the compressed length was not exactly chunk_size,
 
130
              the final string will be a string of all null bytes to pad this
 
131
              to chunk_size
 
132
            * unused_bytes: None, or the last bytes that were added, which we
 
133
              could not fit.
 
134
            * num_nulls_needed: How many nulls are padded at the end
133
135
        """
134
136
        self.bytes_in = None # Free the data cached so far, we don't need it
135
137
        out = self.compressor.flush(Z_FINISH)
164
166
        :param extra_bytes: Optional, if supplied we will add it with
165
167
            Z_SYNC_FLUSH
166
168
        :return: (bytes_out, bytes_out_len, alt_compressed)
167
 
            bytes_out   is the compressed bytes returned from the compressor
168
 
            bytes_out_len the length of the compressed output
169
 
            compressor  An object with everything packed in so far, and
170
 
                        Z_SYNC_FLUSH called.
 
169
 
 
170
            * bytes_out: is the compressed bytes returned from the compressor
 
171
            * bytes_out_len: the length of the compressed output
 
172
            * compressor: An object with everything packed in so far, and
 
173
              Z_SYNC_FLUSH called.
171
174
        """
172
175
        compressor = zlib.compressobj()
173
176
        bytes_out = []