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

  • Committer: John Arbash Meinel
  • Date: 2009-04-21 23:54:16 UTC
  • mto: (4300.1.7 groupcompress_info)
  • mto: This revision was merged to the branch mainline in revision 4301.
  • Revision ID: john@arbash-meinel.com-20090421235416-f0cz6ilf5cufbugi
Fix bug #364900, properly remove the 64kB that was just encoded in the copy.
Also, stop supporting None as a copy length in 'encode_copy_instruction'.
It was only used by the test suite, and it is good to pull that sort of thing out of
production code. (Besides, setting the copy to 64kB has the same effect.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
159
159
 
160
160
 
161
161
class ReadVFile(object):
162
 
    """Adapt a readv result iterator to a file like protocol.
163
 
    
164
 
    The readv result must support the iterator protocol returning (offset,
165
 
    data_bytes) pairs.
166
 
    """
167
 
 
168
 
    # XXX: This could be a generic transport class, as other code may want to
169
 
    # gradually consume the readv result.
 
162
    """Adapt a readv result iterator to a file like protocol."""
170
163
 
171
164
    def __init__(self, readv_result):
172
 
        """Construct a new ReadVFile wrapper.
173
 
 
174
 
        :seealso: make_readv_reader
175
 
 
176
 
        :param readv_result: the most recent readv result - list or generator
177
 
        """
178
 
        # readv can return a sequence or an iterator, but we require an
179
 
        # iterator to know how much has been consumed.
180
 
        readv_result = iter(readv_result)
181
165
        self.readv_result = readv_result
 
166
        # the most recent readv result block
182
167
        self._string = None
183
168
 
184
169
    def _next(self):
185
170
        if (self._string is None or
186
171
            self._string.tell() == self._string_length):
187
 
            offset, data = self.readv_result.next()
 
172
            length, data = self.readv_result.next()
188
173
            self._string_length = len(data)
189
174
            self._string = StringIO(data)
190
175
 
192
177
        self._next()
193
178
        result = self._string.read(length)
194
179
        if len(result) < length:
195
 
            raise errors.BzrError('wanted %d bytes but next '
196
 
                'hunk only contains %d: %r...' %
197
 
                (length, len(result), result[:20]))
 
180
            raise errors.BzrError('request for too much data from a readv hunk.')
198
181
        return result
199
182
 
200
183
    def readline(self):
202
185
        self._next()
203
186
        result = self._string.readline()
204
187
        if self._string.tell() == self._string_length and result[-1] != '\n':
205
 
            raise errors.BzrError('short readline in the readvfile hunk: %r'
206
 
                % (result, ))
 
188
            raise errors.BzrError('short readline in the readvfile hunk.')
207
189
        return result
208
190
 
209
191
 
424
406
        # the buffer.
425
407
        last_buffer_length = None
426
408
        cur_buffer_length = len(self._buffer)
427
 
        last_state_handler = None
428
 
        while (cur_buffer_length != last_buffer_length
429
 
               or last_state_handler != self._state_handler):
 
409
        while cur_buffer_length != last_buffer_length:
430
410
            last_buffer_length = cur_buffer_length
431
 
            last_state_handler = self._state_handler
432
411
            self._state_handler()
433
412
            cur_buffer_length = len(self._buffer)
434
413