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

  • Committer: Andrew Bennetts
  • Date: 2010-03-18 05:24:02 UTC
  • mto: This revision was merged to the branch mainline in revision 5141.
  • Revision ID: andrew.bennetts@canonical.com-20100318052402-vsdd48oxucivcgve
Test that pack collection uses set_sibling_indices.

Show diffs side-by-side

added added

removed removed

Lines of Context:
382
382
    suitable for production use. :XXX
383
383
    """
384
384
 
385
 
    def __init__(self, transport, name, size, unlimited_cache=False, offset=0):
 
385
    def __init__(self, transport, name, size, unlimited_cache=False):
386
386
        """Open an index called name on transport.
387
387
 
388
388
        :param transport: A bzrlib.transport.Transport.
394
394
            avoided by having it supplied. If size is None, then bisection
395
395
            support will be disabled and accessing the index will just stream
396
396
            all the data.
397
 
        :param offset: Instead of starting the index data at offset 0, start it
398
 
            at an arbitrary offset.
399
397
        """
400
398
        self._transport = transport
401
399
        self._name = name
418
416
        self._size = size
419
417
        # The number of bytes we've read so far in trying to process this file
420
418
        self._bytes_read = 0
421
 
        self._base_offset = offset
422
419
 
423
420
    def __eq__(self, other):
424
421
        """Equal when self and other were created with the same parameters."""
447
444
            mutter('Reading entire index %s', self._transport.abspath(self._name))
448
445
        if stream is None:
449
446
            stream = self._transport.get(self._name)
450
 
            if self._base_offset != 0:
451
 
                # This is wasteful, but it is better than dealing with
452
 
                # adjusting all the offsets, etc.
453
 
                stream = StringIO(stream.read()[self._base_offset:])
454
447
        self._read_prefix(stream)
455
448
        self._expected_elements = 3 + self._key_length
456
449
        line_count = 0
1197
1190
            self._buffer_all()
1198
1191
            return
1199
1192
 
1200
 
        base_offset = self._base_offset
1201
 
        if base_offset != 0:
1202
 
            # Rewrite the ranges for the offset
1203
 
            readv_ranges = [(start+base_offset, size)
1204
 
                            for start, size in readv_ranges]
1205
1193
        readv_data = self._transport.readv(self._name, readv_ranges, True,
1206
 
            self._size + self._base_offset)
 
1194
            self._size)
1207
1195
        # parse
1208
1196
        for offset, data in readv_data:
1209
 
            offset -= base_offset
1210
1197
            self._bytes_read += len(data)
1211
 
            if offset < 0:
1212
 
                # transport.readv() expanded to extra data which isn't part of
1213
 
                # this index
1214
 
                data = data[-offset:]
1215
 
                offset = 0
1216
1198
            if offset == 0 and len(data) == self._size:
1217
1199
                # We read the whole range, most likely because the
1218
1200
                # Transport upcast our readv ranges into one long request
1418
1400
        _move_to_front propagates to all objects in self._sibling_indices by
1419
1401
        calling _move_to_front_by_name.
1420
1402
        """
1421
 
        if self._indices[:len(hit_indices)] == hit_indices:
1422
 
            # The 'hit_indices' are already at the front (and in the same
1423
 
            # order), no need to re-order
1424
 
            return
1425
1403
        hit_names = self._move_to_front_by_index(hit_indices)
1426
1404
        for sibling_idx in self._sibling_indices:
1427
1405
            sibling_idx._move_to_front_by_name(hit_names)
1435
1413
        if 'index' in debug.debug_flags:
1436
1414
            mutter('CombinedGraphIndex reordering: currently %r, promoting %r',
1437
1415
                   indices_info, hit_indices)
 
1416
        hit_indices_info = []
1438
1417
        hit_names = []
1439
 
        unhit_names = []
1440
 
        new_hit_indices = []
1441
 
        unhit_indices = []
1442
 
 
1443
 
        for offset, (name, idx) in enumerate(indices_info):
 
1418
        unhit_indices_info = []
 
1419
        for name, idx in indices_info:
1444
1420
            if idx in hit_indices:
 
1421
                info = hit_indices_info
1445
1422
                hit_names.append(name)
1446
 
                new_hit_indices.append(idx)
1447
 
                if len(new_hit_indices) == len(hit_indices):
1448
 
                    # We've found all of the hit entries, everything else is
1449
 
                    # unhit
1450
 
                    unhit_names.extend(self._index_names[offset+1:])
1451
 
                    unhit_indices.extend(self._indices[offset+1:])
1452
 
                    break
1453
1423
            else:
1454
 
                unhit_names.append(name)
1455
 
                unhit_indices.append(idx)
1456
 
 
1457
 
        self._indices = new_hit_indices + unhit_indices
1458
 
        self._index_names = hit_names + unhit_names
 
1424
                info = unhit_indices_info
 
1425
            info.append((name, idx))
 
1426
        final_info = hit_indices_info + unhit_indices_info
 
1427
        self._indices = [idx for (name, idx) in final_info]
 
1428
        self._index_names = [name for (name, idx) in final_info]
1459
1429
        if 'index' in debug.debug_flags:
1460
1430
            mutter('CombinedGraphIndex reordered: %r', self._indices)
1461
1431
        return hit_names