~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/index.py

CombinedGraphIndex.iter_entries() is now able to reload on request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1192
1192
            efficient order for the index.
1193
1193
        """
1194
1194
        keys = set(keys)
1195
 
        for index in self._indices:
1196
 
            if not keys:
 
1195
        while True:
 
1196
            try:
 
1197
                for index in self._indices:
 
1198
                    if not keys:
 
1199
                        return
 
1200
                    for node in index.iter_entries(keys):
 
1201
                        keys.remove(node[1])
 
1202
                        yield node
1197
1203
                return
1198
 
            for node in index.iter_entries(keys):
1199
 
                keys.remove(node[1])
1200
 
                yield node
 
1204
            except errors.NoSuchFile:
 
1205
                self._reload_or_raise()
1201
1206
 
1202
1207
    def iter_entries_prefix(self, keys):
1203
1208
        """Iterate over keys within the index using prefix matching.
1238
1243
        have a maximum error of the number of child indices * largest number of
1239
1244
        keys in any index.
1240
1245
        """
1241
 
        do_retry = True
1242
 
        while do_retry:
 
1246
        while True:
1243
1247
            try:
1244
1248
                return sum((index.key_count() for index in self._indices), 0)
1245
1249
            except errors.NoSuchFile:
1246
 
                if self._reload_func is None:
1247
 
                    raise
1248
 
                exc_type, exc_value, exc_traceback = sys.exc_info()
1249
 
                if not self._reload_func():
1250
 
                    raise exc_type, exc_value, exc_traceback
 
1250
                self._reload_or_raise()
 
1251
 
 
1252
    def _reload_or_raise(self):
 
1253
        """We just got a NoSuchFile exception.
 
1254
 
 
1255
        Try to reload the indices, if it fails, just raise the current
 
1256
        exception.
 
1257
        """
 
1258
        if self._reload_func is None:
 
1259
            raise
 
1260
        exc_type, exc_value, exc_traceback = sys.exc_info()
 
1261
        if not self._reload_func():
 
1262
            # We tried to reload, but nothing changed, so we fail anyway
 
1263
            raise exc_type, exc_value, exc_traceback
1251
1264
 
1252
1265
    def validate(self):
1253
1266
        """Validate that everything in the index can be accessed."""