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

  • Committer: John Arbash Meinel
  • Date: 2008-10-24 20:13:11 UTC
  • mto: (3860.1.1 153786-retry)
  • mto: This revision was merged to the branch mainline in revision 3865.
  • Revision ID: john@arbash-meinel.com-20081024201311-4kteabxxs3istdan
_DirectPackAccess can now raise RetryWithNewPacks when we think something has happened.

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
from itertools import izip, chain
65
65
import operator
66
66
import os
 
67
import sys
67
68
 
68
69
from bzrlib.lazy_import import lazy_import
69
70
lazy_import(globals(), """
707
708
    """
708
709
 
709
710
    def __init__(self, index, data_access, max_delta_chain=200,
710
 
        annotated=False):
 
711
                 annotated=False, reload_func=None):
711
712
        """Create a KnitVersionedFiles with index and data_access.
712
713
 
713
714
        :param index: The index for the knit data.
717
718
            insertion. Set to 0 to prohibit the use of deltas.
718
719
        :param annotated: Set to True to cause annotations to be calculated and
719
720
            stored during insertion.
 
721
        :param reload_func: An function that can be called if we think we need
 
722
            to reload the pack listing and try again. See
 
723
            'bzrlib.repofmt.pack_repo.AggregateIndex' for the signature.
720
724
        """
721
725
        self._index = index
722
726
        self._access = data_access
726
730
        else:
727
731
            self._factory = KnitPlainFactory()
728
732
        self._fallback_vfs = []
 
733
        self._reload_func = reload_func
729
734
 
730
735
    def __repr__(self):
731
736
        return "%s(%r, %r)" % (
1159
1164
        if not self._index.has_graph:
1160
1165
            # Cannot topological order when no graph has been stored.
1161
1166
            ordering = 'unordered'
 
1167
 
 
1168
        remaining_keys = keys
 
1169
        while True:
 
1170
            try:
 
1171
                keys = set(remaining_keys)
 
1172
                for content_factory in self._get_remaining_record_stream(keys,
 
1173
                                            ordering, include_delta_closure):
 
1174
                    remaining_keys.discard(content_factory.key)
 
1175
                    yield content_factory
 
1176
                return
 
1177
            except errors.RetryWithNewPacks, e:
 
1178
                # reload_func
 
1179
                raise
 
1180
 
 
1181
    def _get_remaining_record_stream(self, keys, ordering,
 
1182
                                     include_delta_closure):
1162
1183
        if include_delta_closure:
1163
1184
            positions = self._get_components_positions(keys, allow_missing=True)
1164
1185
        else:
2433
2454
        if current_index is not None:
2434
2455
            request_lists.append((current_index, current_list))
2435
2456
        for index, offsets in request_lists:
2436
 
            transport, path = self._indices[index]
2437
 
            reader = pack.make_readv_reader(transport, path, offsets)
2438
 
            for names, read_func in reader.iter_records():
2439
 
                yield read_func(None)
 
2457
            try:
 
2458
                transport, path = self._indices[index]
 
2459
            except KeyError:
 
2460
                # A KeyError here indicates that someone has triggered an index
 
2461
                # reload, and this index has gone missing, we need to start
 
2462
                # over.
 
2463
                raise errors.RetryWithNewPacks(reload_occurred=True,
 
2464
                                               exc_info=sys.exc_info())
 
2465
            try:
 
2466
                reader = pack.make_readv_reader(transport, path, offsets)
 
2467
                for names, read_func in reader.iter_records():
 
2468
                    yield read_func(None)
 
2469
            except errors.NoSuchFile:
 
2470
                # A NoSuchFile error indicates that a pack file has gone
 
2471
                # missing on disk, we need to trigger a reload, and start over.
 
2472
                raise errors.RetryWithNewPacks(reload_occurred=False,
 
2473
                                               exc_info=sys.exc_info())
2440
2474
 
2441
2475
    def set_writer(self, writer, index, transport_packname):
2442
2476
        """Set a writer to use for adding data."""