216
220
"""Mark a single step of regeneration complete."""
217
221
self.pb.update(message, self.count, self.total)
225
class KnitReconciler(RepoReconciler):
226
"""Reconciler that reconciles a knit format repository.
228
This will detect garbage inventories and remove them.
230
Inconsistent parentage is checked for in the revision weave.
233
def _reconcile_steps(self):
234
"""Perform the steps to reconcile this repository."""
236
# knits never suffer this
237
self.inconsistent_parents = 0
240
def _load_indexes(self):
241
"""Load indexes for the reconciliation."""
242
self.transaction = self.repo.get_transaction()
243
self.pb.update('Reading indexes.', 0, 2)
244
self.inventory = self.repo.get_inventory_weave()
245
self.pb.update('Reading indexes.', 1, 2)
246
self.revisions = self.repo._revision_store.get_revision_file(self.transaction)
247
self.pb.update('Reading indexes.', 2, 2)
249
def _gc_inventory(self):
250
"""Remove inventories that are not referenced from the revision store."""
251
self.pb.update('Checking unused inventories.', 0, 1)
252
self._check_garbage_inventories()
253
self.pb.update('Checking unused inventories.', 1, 3)
254
if not self.garbage_inventories:
255
self.pb.note('Inventory ok.')
257
self.pb.update('Backing up inventory...', 0, 0)
258
self.repo.control_weaves.copy(self.inventory, 'inventory.backup', self.transaction)
259
self.pb.note('Backup Inventory created.')
260
# asking for '' should never return a non-empty weave
261
new_inventory = self.repo.control_weaves.get_empty('inventory.new',
264
# we have topological order of revisions and non ghost parents ready.
265
self._setup_steps(len(self.revisions))
266
for rev_id in TopoSorter(self.revisions.get_graph().items()).iter_topo_order():
267
parents = self.revisions.get_parents(rev_id)
268
# double check this really is in topological order.
269
unavailable = [p for p in parents if p not in new_inventory]
270
assert len(unavailable) == 0
271
# this entry has all the non ghost parents in the inventory
273
self._reweave_step('adding inventories')
274
# ugly but needed, weaves are just way tooooo slow else.
275
new_inventory.add_lines(rev_id, parents, self.inventory.get_lines(rev_id))
277
# if this worked, the set of new_inventory.names should equal
279
assert set(new_inventory.versions()) == set(self.revisions.versions())
280
self.pb.update('Writing weave')
281
self.repo.control_weaves.copy(new_inventory, 'inventory', self.transaction)
282
self.repo.control_weaves.delete('inventory.new', self.transaction)
283
self.inventory = None
284
self.pb.note('Inventory regenerated.')
286
def _reinsert_revisions(self):
287
"""Correct the revision history for revisions in the revision knit."""
288
# the total set of revisions to process
289
self.pending = set(self.revisions.versions())
291
# mapping from revision_id to parents
293
# errors that we detect
294
self.inconsistent_parents = 0
295
# we need the revision id of each revision and its available parents list
296
self._setup_steps(len(self.pending))
297
for rev_id in self.pending:
298
# put a revision into the graph.
299
self._graph_revision(rev_id)
301
if not self.inconsistent_parents:
302
self.pb.note('Revision history accurate.')
304
self._setup_steps(len(self._rev_graph))
305
for rev_id, parents in self._rev_graph.items():
306
if parents != self.revisions.get_parents(rev_id):
307
self.revisions.fix_parents(rev_id, parents)
308
self._reweave_step('Fixing parents')
309
self.pb.note('Ancestry corrected.')
311
def _graph_revision(self, rev_id):
312
"""Load a revision into the revision graph."""
313
# pick a random revision
314
# analyse revision id rev_id and put it in the stack.
315
self._reweave_step('loading revisions')
316
rev = self.repo._revision_store.get_revision(rev_id, self.transaction)
317
assert rev.revision_id == rev_id
319
for parent in rev.parent_ids:
320
if self.revisions.has_version(parent):
321
parents.append(parent)
323
mutter('found ghost %s', parent)
324
self._rev_graph[rev_id] = parents
325
if set(self.inventory.get_parents(rev_id)) != set(parents):
326
self.inconsistent_parents += 1
327
mutter('Inconsistent inventory parents: id {%s} '
328
'inventory claims %r, '
329
'available parents are %r, '
330
'unavailable parents are %r',
332
set(self.inventory.get_parents(rev_id)),
334
set(rev.parent_ids).difference(set(parents)))
336
def _check_garbage_inventories(self):
337
"""Check for garbage inventories which we cannot trust
339
We cant trust them because their pre-requisite file data may not
340
be present - all we know is that their revision was not installed.
342
inventories = set(self.inventory.versions())
343
revisions = set(self.revisions.versions())
344
garbage = inventories.difference(revisions)
345
self.garbage_inventories = len(garbage)
346
for revision_id in garbage:
347
mutter('Garbage inventory {%s} found.', revision_id)