~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Martin Pool
  • Date: 2007-10-24 02:46:12 UTC
  • mto: This revision was merged to the branch mainline in revision 2933.
  • Revision ID: mbp@sourcefrog.net-20071024024612-qp7h7ibrt7sgk1gj
Review cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
244
244
            mutter('%s: create_pack: pack stream open: %s%s t+%6.3fs',
245
245
                time.ctime(), self.upload_transport.base, self.random_name,
246
246
                time.time() - self.start_time)
 
247
        # A list of byte sequences to be written to the new pack, and the 
 
248
        # aggregate size of them.  Stored as a list rather than separate 
 
249
        # variables so that the _write_data closure below can update them.
247
250
        self._buffer = [[], 0]
248
 
        # create a callable for adding data
 
251
        # create a callable for adding data 
 
252
        #
 
253
        # robertc says- this is a closure rather than a method on the object
 
254
        # so that the variables are locals, and faster than accessing object
 
255
        # members.
249
256
        def _write_data(bytes, flush=False, _buffer=self._buffer,
250
257
            _write=self.write_stream.write, _update=self._hash.update):
251
258
            _buffer[0].append(bytes)
281
288
 
282
289
    def data_inserted(self):
283
290
        """True if data has been added to this pack."""
284
 
        return 0 != sum((self.get_revision_count(),
285
 
            self.inventory_index.key_count(),
286
 
            self.text_index.key_count(),
287
 
            self.signature_index.key_count(),
288
 
            ))
 
291
        return bool(self.get_revision_count() or
 
292
            self.inventory_index.key_count() or
 
293
            self.text_index.key_count() or
 
294
            self.signature_index.key_count())
289
295
 
290
296
    def finish(self):
291
297
        """Finish the new pack.
303
309
            self._write_data('', flush=True)
304
310
        self.name = self._hash.hexdigest()
305
311
        # write indices
306
 
        # XXX: should rename each index too rather than just uploading blind
307
 
        # under the chosen name.
 
312
        # XXX: It'd be better to write them all to temporary names, then
 
313
        # rename them all into place, so that the window when only some are
 
314
        # visible is smaller.  On the other hand none will be seen until
 
315
        # they're in the names list.
308
316
        self.index_sizes = [None, None, None, None]
309
317
        self._write_index('revision', self.revision_index, 'revision')
310
318
        self._write_index('inventory', self.inventory_index, 'inventory')
333
341
                self.pack_transport, self.name,
334
342
                time.time() - self.start_time)
335
343
 
336
 
    def make_index(self, index_type):
337
 
        """Construct a GraphIndex object for this pack index 'index_type'."""
338
 
        setattr(self, index_type + '_index',
339
 
            GraphIndex(self.index_transport,
340
 
                self.index_name(index_type, self.name),
341
 
                self.index_sizes[self.index_offset(index_type)]))
342
 
 
343
344
    def index_name(self, index_type, name):
344
345
        """Get the disk name of an index type for pack name 'name'."""
345
346
        return name + NewPack.index_definitions[index_type][0]
348
349
        """Get the position in a index_size array for a given index type."""
349
350
        return NewPack.index_definitions[index_type][1]
350
351
 
 
352
    def _replace_index_with_readonly(self, index_type):
 
353
        setattr(self, index_type + '_index',
 
354
            GraphIndex(self.index_transport,
 
355
                self.index_name(index_type, self.name),
 
356
                self.index_sizes[self.index_offset(index_type)]))
 
357
 
351
358
    def set_write_cache_size(self, size):
352
359
        self._cache_limit = size
353
360
 
366
373
            mutter('%s: create_pack: wrote %s index: %s%s t+%6.3fs',
367
374
                time.ctime(), label, self.upload_transport.base,
368
375
                self.random_name, time.time() - self.start_time)
369
 
        # As we have no current protection against erroneous additional
370
 
        # insertions, load the index from disk on further use. We should alter
371
 
        # the index layer to make it's finish() error if add_node is
 
376
        # Replace the writable index on this object with a readonly, 
 
377
        # presently unloaded index. We should alter
 
378
        # the index layer to make its finish() error if add_node is
372
379
        # subsequently used. RBC
373
 
        self.make_index(index_type)
 
380
        self._replace_index_with_readonly(index_type)
374
381
 
375
382
 
376
383
class AggregateIndex(object):