~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/pack_repo.py

  • Committer: Andrew Bennetts
  • Date: 2010-02-05 07:58:03 UTC
  • mto: (4797.2.13 2.1)
  • mto: This revision was merged to the branch mainline in revision 5033.
  • Revision ID: andrew.bennetts@canonical.com-20100205075803-35lnry4nifbnjoea
Suppress KeyError from remove_index during _abort_write_group.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from bzrlib import (
26
26
    chk_map,
 
27
    cleanup,
27
28
    debug,
28
29
    graph,
29
30
    osutils,
646
647
        del self.combined_index._indices[:]
647
648
        self.add_callback = None
648
649
 
649
 
    def remove_index(self, index, pack):
 
650
    def remove_index(self, index):
650
651
        """Remove index from the indices used to answer queries.
651
652
 
652
653
        :param index: An index from the pack parameter.
653
 
        :param pack: A Pack instance.
654
654
        """
655
655
        del self.index_to_pack[index]
656
656
        self.combined_index._indices.remove(index)
1840
1840
        self._remove_pack_indices(pack)
1841
1841
        self.packs.remove(pack)
1842
1842
 
1843
 
    def _remove_pack_indices(self, pack):
1844
 
        """Remove the indices for pack from the aggregated indices."""
1845
 
        self.revision_index.remove_index(pack.revision_index, pack)
1846
 
        self.inventory_index.remove_index(pack.inventory_index, pack)
1847
 
        self.text_index.remove_index(pack.text_index, pack)
1848
 
        self.signature_index.remove_index(pack.signature_index, pack)
1849
 
        if self.chk_index is not None:
1850
 
            self.chk_index.remove_index(pack.chk_index, pack)
 
1843
    def _remove_pack_indices(self, pack, ignore_missing=False):
 
1844
        """Remove the indices for pack from the aggregated indices.
 
1845
        
 
1846
        :param ignore_missing: Suppress KeyErrors from calling remove_index.
 
1847
        """
 
1848
        for index_type in Pack.index_definitions.keys():
 
1849
            attr_name = index_type + '_index'
 
1850
            aggregate_index = getattr(self, attr_name)
 
1851
            if aggregate_index is not None:
 
1852
                pack_index = getattr(pack, attr_name)
 
1853
                try:
 
1854
                    aggregate_index.remove_index(pack_index)
 
1855
                except KeyError:
 
1856
                    if ignore_missing:
 
1857
                        continue
 
1858
                    raise
1851
1859
 
1852
1860
    def reset(self):
1853
1861
        """Clear all cached data."""
2091
2099
        # FIXME: just drop the transient index.
2092
2100
        # forget what names there are
2093
2101
        if self._new_pack is not None:
2094
 
            try:
2095
 
                self._new_pack.abort()
2096
 
            finally:
2097
 
                # XXX: If we aborted while in the middle of finishing the write
2098
 
                # group, _remove_pack_indices can fail because the indexes are
2099
 
                # already gone.  If they're not there we shouldn't fail in this
2100
 
                # case.  -- mbp 20081113
2101
 
                self._remove_pack_indices(self._new_pack)
2102
 
                self._new_pack = None
 
2102
            operation = cleanup.OperationWithCleanups(self._new_pack.abort)
 
2103
            operation.add_cleanup(setattr, self, '_new_pack', None)
 
2104
            # If we aborted while in the middle of finishing the write
 
2105
            # group, _remove_pack_indices could fail because the indexes are
 
2106
            # already gone.  But they're not there we shouldn't fail in this
 
2107
            # case, so we pass ignore_missing=True.
 
2108
            operation.add_cleanup(self._remove_pack_indices, self._new_pack,
 
2109
                ignore_missing=True)
 
2110
            operation.run_simple()
2103
2111
        for resumed_pack in self._resumed_packs:
2104
 
            try:
2105
 
                resumed_pack.abort()
2106
 
            finally:
2107
 
                # See comment in previous finally block.
2108
 
                try:
2109
 
                    self._remove_pack_indices(resumed_pack)
2110
 
                except KeyError:
2111
 
                    pass
 
2112
            operation = cleanup.OperationWithCleanups(resumed_pack.abort)
 
2113
            # See comment in previous finally block.
 
2114
            operation.add_cleanup(self._remove_pack_indices, resumed_pack,
 
2115
                ignore_missing=True)
 
2116
            operation.run_simple()
2112
2117
        del self._resumed_packs[:]
2113
2118
 
2114
2119
    def _remove_resumed_pack_indices(self):