Comment 24 for bug 239499

Revision history for this message
Robert Collins (lifeless) wrote : Re: [Bug 239499] Re: corrupt knit index on an old arch-imported bzr repo

Previous script was borked...

import bzrlib.repository
from bzrlib import errors
from bzrlib.tsort import topo_sort
from bzrlib.versionedfile import FulltextContentFactory
r = bzrlib.repository.Repository.open('.')
r.lock_write()
r._backup_inventory()
new_inv = r._temp_inventories()
order = topo_sort(r.inventories.get_parent_map(r.inventories.keys()))
for key in order:
  try:
    record = r.inventories.get_record_stream([key], 'unordered',
True).next()
  except errors.SHA1KnitCorrupt, e:
    print "recovering %r" % key
    assert e.key == key
    parents = r.inventories.get_parent_map([key])[key]
    record = FulltextContentFactory(key, parents, None,
      ''.join(e.content))
  new_inv.insert_record_stream([record])
r._activate_new_inventory()

After this, check works for me - though it still reports inconsistent
parents; there is an existing script to repair that, and I'm about to
dig that up and run it over a repaired repo.

-Rob