~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: Robert Collins
  • Date: 2006-05-03 09:25:40 UTC
  • mto: (1692.4.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1694.
  • Revision ID: robertc@robertcollins.net-20060503092540-9f4487ad389bc285
Finish the reconcile tweak: filled in ghosts are a data loss issue and need to be checked during fast reconciles.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
 
117
117
    def _reconcile_steps(self):
118
118
        """Perform the steps to reconcile this repository."""
119
 
        if self.thorough:
120
 
            self._reweave_inventory()
 
119
        self._reweave_inventory()
121
120
 
122
121
    def _reweave_inventory(self):
123
 
        """Regenerate the inventory weave for the repository from scratch."""
124
 
        # local because its really a wart we want to hide
 
122
        """Regenerate the inventory weave for the repository from scratch.
 
123
        
 
124
        This is a smart function: it will only do the reweave if doing it 
 
125
        will correct data issues. The self.thorough flag controls whether
 
126
        only data-loss causing issues (!self.thorough) or all issues
 
127
        (self.thorough) are treated as requiring the reweave.
 
128
        """
 
129
        # local because needing to know about WeaveFile is a wart we want to hide
125
130
        from bzrlib.weave import WeaveFile, Weave
126
131
        transaction = self.repo.get_transaction()
127
132
        self.pb.update('Reading inventory data.')
139
144
            # put a revision into the graph.
140
145
            self._graph_revision(rev_id)
141
146
        self._check_garbage_inventories()
142
 
        if not self.inconsistent_parents and not self.garbage_inventories:
 
147
        # if there are no inconsistent_parents and 
 
148
        # (no garbage inventories or we are not doing a thorough check)
 
149
        if (not self.inconsistent_parents and 
 
150
            (not self.garbage_inventories or not self.thorough)):
143
151
            self.pb.note('Inventory ok.')
144
152
            return
145
153
        self.pb.update('Backing up inventory...', 0, 0)
200
208
            else:
201
209
                mutter('found ghost %s', parent)
202
210
        self._rev_graph[rev_id] = parents   
203
 
        if (set(self.inventory.get_parents(rev_id)) != set(parents) or
204
 
            (len(self.inventory.get_parents(rev_id)) and len(parents) and
205
 
             parents[0] != self.inventory.get_parents(rev_id)[0])):
 
211
        if self._parents_are_inconsistent(rev_id, parents):
206
212
            self.inconsistent_parents += 1
207
213
            mutter('Inconsistent inventory parents: id {%s} '
208
214
                   'inventory claims %r, '
213
219
                   set(parents),
214
220
                   set(rev.parent_ids).difference(set(parents)))
215
221
 
 
222
    def _parents_are_inconsistent(self, rev_id, parents):
 
223
        """Return True if the parents list of rev_id does not match the weave.
 
224
 
 
225
        This detect inconsistences based on the self.thorough value:
 
226
        if thorough is on, the first parent value is checked as well as ghost
 
227
        differences.
 
228
        Otherwise only the ghost differences are evaluated.
 
229
        """
 
230
        weave_parents = self.inventory.get_parents(rev_id)
 
231
        weave_missing_old_ghosts = set(weave_parents) != set(parents)
 
232
        first_parent_is_wrong = (
 
233
            len(weave_parents) and len(parents) and
 
234
            parents[0] != weave_parents[0])
 
235
        if self.thorough:
 
236
            return weave_missing_old_ghosts or first_parent_is_wrong
 
237
        else:
 
238
            return weave_missing_old_ghosts
 
239
 
216
240
    def _check_garbage_inventories(self):
217
241
        """Check for garbage inventories which we cannot trust
218
242
 
219
243
        We cant trust them because their pre-requisite file data may not
220
244
        be present - all we know is that their revision was not installed.
221
245
        """
 
246
        if not self.thorough:
 
247
            return
222
248
        inventories = set(self.inventory.versions())
223
249
        revisions = set(self._rev_graph.keys())
224
250
        garbage = inventories.difference(revisions)