~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/reconcile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-08-17 07:52:09 UTC
  • mfrom: (1910.3.4 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20060817075209-e85a1f9e05ff8b87
(andrew) Trivial fixes to NotImplemented errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# (C) 2005, 2006 Canonical Limited.
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
"""Reconcilers are able to fix some potential data errors in a branch."""
18
18
 
19
19
 
20
 
__all__ = [
21
 
    'KnitReconciler',
22
 
    'PackReconciler',
23
 
    'reconcile',
24
 
    'Reconciler',
25
 
    'RepoReconciler',
26
 
    ]
27
 
 
28
 
 
29
 
from bzrlib import (
30
 
    errors,
31
 
    ui,
32
 
    repository,
33
 
    )
34
 
from bzrlib.trace import mutter, note
 
20
__all__ = ['reconcile', 'Reconciler', 'RepoReconciler', 'KnitReconciler']
 
21
 
 
22
 
 
23
from bzrlib import ui
 
24
from bzrlib.trace import mutter
35
25
from bzrlib.tsort import TopoSorter
36
26
 
37
27
 
81
71
        repo_reconciler = self.repo.reconcile(thorough=True)
82
72
        self.inconsistent_parents = repo_reconciler.inconsistent_parents
83
73
        self.garbage_inventories = repo_reconciler.garbage_inventories
84
 
        if repo_reconciler.aborted:
85
 
            self.pb.note(
86
 
                'Reconcile aborted: revision index has inconsistent parents.')
87
 
            self.pb.note(
88
 
                'Run "bzr check" for more details.')
89
 
        else:
90
 
            self.pb.note('Reconciliation complete.')
 
74
        self.pb.note('Reconciliation complete.')
91
75
 
92
76
 
93
77
class RepoReconciler(object):
94
78
    """Reconciler that reconciles a repository.
95
79
 
96
 
    The goal of repository reconciliation is to make any derived data
97
 
    consistent with the core data committed by a user. This can involve 
98
 
    reindexing, or removing unreferenced data if that can interfere with
99
 
    queries in a given repository.
100
 
 
101
80
    Currently this consists of an inventory reweave with revision cross-checks.
102
81
    """
103
82
 
110
89
        """
111
90
        self.garbage_inventories = 0
112
91
        self.inconsistent_parents = 0
113
 
        self.aborted = False
114
92
        self.repo = repo
115
93
        self.thorough = thorough
116
94
 
192
170
                # This is done to avoid a revision_count * time-to-write additional overhead on 
193
171
                # reconcile.
194
172
                new_inventory_vf._check_write_ok()
195
 
                Weave._add_lines(new_inventory_vf, rev_id, parents,
196
 
                    self.inventory.get_lines(rev_id), None, None, None, False, True)
 
173
                Weave._add_lines(new_inventory_vf, rev_id, parents, self.inventory.get_lines(rev_id),
 
174
                                 None)
197
175
            else:
198
176
                new_inventory_vf.add_lines(rev_id, parents, self.inventory.get_lines(rev_id))
199
177
 
289
267
class KnitReconciler(RepoReconciler):
290
268
    """Reconciler that reconciles a knit format repository.
291
269
 
292
 
    This will detect garbage inventories and remove them in thorough mode.
 
270
    This will detect garbage inventories and remove them.
 
271
 
 
272
    Inconsistent parentage is checked for in the revision weave.
293
273
    """
294
274
 
295
275
    def _reconcile_steps(self):
296
276
        """Perform the steps to reconcile this repository."""
297
277
        if self.thorough:
298
 
            try:
299
 
                self._load_indexes()
300
 
            except errors.BzrCheckError:
301
 
                self.aborted = True
302
 
                return
 
278
            self._load_indexes()
303
279
            # knits never suffer this
304
280
            self._gc_inventory()
305
 
            self._fix_text_parents()
306
281
 
307
282
    def _load_indexes(self):
308
283
        """Load indexes for the reconciliation."""
310
285
        self.pb.update('Reading indexes.', 0, 2)
311
286
        self.inventory = self.repo.get_inventory_weave()
312
287
        self.pb.update('Reading indexes.', 1, 2)
313
 
        self.repo._check_for_inconsistent_revision_parents()
314
288
        self.revisions = self.repo._revision_store.get_revision_file(self.transaction)
315
289
        self.pb.update('Reading indexes.', 2, 2)
316
290
 
363
337
        self.garbage_inventories = len(garbage)
364
338
        for revision_id in garbage:
365
339
            mutter('Garbage inventory {%s} found.', revision_id)
366
 
 
367
 
    def _fix_text_parents(self):
368
 
        """Fix bad versionedfile parent entries.
369
 
 
370
 
        It is possible for the parents entry in a versionedfile entry to be
371
 
        inconsistent with the values in the revision and inventory.
372
 
 
373
 
        This method finds entries with such inconsistencies, corrects their
374
 
        parent lists, and replaces the versionedfile with a corrected version.
375
 
        """
376
 
        transaction = self.repo.get_transaction()
377
 
        revision_versions = repository._RevisionTextVersionCache(self.repo)
378
 
        versions = self.revisions.versions()
379
 
        revision_versions.prepopulate_revs(versions)
380
 
        for num, file_id in enumerate(self.repo.weave_store):
381
 
            self.pb.update('Fixing text parents', num,
382
 
                           len(self.repo.weave_store))
383
 
            vf = self.repo.weave_store.get_weave(file_id, transaction)
384
 
            vf_checker = self.repo.get_versioned_file_checker(
385
 
                versions, revision_versions)
386
 
            versions_with_bad_parents = vf_checker.check_file_version_parents(
387
 
                vf, file_id)
388
 
            if len(versions_with_bad_parents) == 0:
389
 
                continue
390
 
            self._fix_text_parent(file_id, vf, versions_with_bad_parents)
391
 
 
392
 
    def _fix_text_parent(self, file_id, vf, versions_with_bad_parents):
393
 
        """Fix bad versionedfile entries in a single versioned file."""
394
 
        new_vf = self.repo.weave_store.get_empty('temp:%s' % file_id,
395
 
            self.transaction)
396
 
        new_parents = {}
397
 
        for version in vf.versions():
398
 
            if version in versions_with_bad_parents:
399
 
                parents = versions_with_bad_parents[version][1]
400
 
            else:
401
 
                parents = vf.get_parents(version)
402
 
            new_parents[version] = parents
403
 
        for version in TopoSorter(new_parents.items()).iter_topo_order():
404
 
            new_vf.add_lines(version, new_parents[version],
405
 
                             vf.get_lines(version))
406
 
        self.repo.weave_store.copy(new_vf, file_id, self.transaction)
407
 
        self.repo.weave_store.delete('temp:%s' % file_id, self.transaction)
408
 
 
409
 
 
410
 
class PackReconciler(RepoReconciler):
411
 
    """Reconciler that reconciles a pack based repository.
412
 
 
413
 
    Garbage inventories do not affect ancestry queries, and removal is
414
 
    considerably more expensive as there is no separate versioned file for
415
 
    them, so they are not cleaned. In short it is currently a no-op.
416
 
 
417
 
    In future this may be a good place to hook in annotation cache checking,
418
 
    index recreation etc.
419
 
    """
420
 
 
421
 
    # XXX: The index corruption that _fix_text_parents performs is needed for
422
 
    # packs, but not yet implemented. The basic approach is to:
423
 
    #  - lock the names list
424
 
    #  - perform a customised pack() that regenerates data as needed
425
 
    #  - unlock the names list
426
 
    # https://bugs.edge.launchpad.net/bzr/+bug/154173
427
 
 
428
 
    def _reconcile_steps(self):
429
 
        """Perform the steps to reconcile this repository."""