~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: abentley
  • Date: 2005-10-14 03:50:50 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@lappy-20051014035050-d779472ccb599a51
semi-broke merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
# TODO: Check revision, inventory and entry objects have all 
26
26
# required fields.
27
27
 
28
 
# TODO: Get every revision in the revision-store even if they're not
29
 
# referenced by history and make sure they're all valid.
30
28
 
31
29
import bzrlib.ui
32
30
from bzrlib.trace import note, warning
34
32
from bzrlib.trace import mutter
35
33
from bzrlib.errors import BzrCheckError, NoSuchRevision
36
34
from bzrlib.inventory import ROOT_ID
 
35
from bzrlib.branch import gen_root_id
37
36
 
38
37
 
39
38
class Check(object):
41
40
 
42
41
    def __init__(self, branch):
43
42
        self.branch = branch
44
 
        self.inventory_weave = branch._get_inventory_weave()
45
43
        self.checked_text_cnt = 0
46
44
        self.checked_rev_cnt = 0
47
45
        self.ghosts = []
54
52
 
55
53
    def check(self):
56
54
        self.branch.lock_read()
57
 
        self.progress = bzrlib.ui.ui_factory.progress_bar()
58
55
        try:
59
56
            self.history = self.branch.revision_history()
60
57
            if not len(self.history):
61
58
                # nothing to see here
62
59
                return
63
 
            if not self.branch.revision_store.listable():
64
 
                raise BzrCheckError("Branch must be local")
65
 
            self.planned_revisions = set(self.branch.revision_store)
66
 
            inventoried = set(self.inventory_weave.names())
67
 
            awol = self.planned_revisions - inventoried
68
 
            if len(awol) > 0:
69
 
                raise BzrCheckError('Stored revisions missing from inventory'
70
 
                    '{%s}' % ','.join([f for f in awol]))
 
60
            self.planned_revisions = self.branch.get_ancestry(self.history[-1])
 
61
            self.planned_revisions.remove(None)
 
62
            revno = 0
71
63
    
72
 
            for revno, rev_id in enumerate(self.planned_revisions):
73
 
                self.progress.update('checking revision', revno+1,
 
64
            self.progress = bzrlib.ui.ui_factory.progress_bar()
 
65
            while revno < len(self.planned_revisions):
 
66
                rev_id = self.planned_revisions[revno]
 
67
                self.progress.update('checking revision', revno,
74
68
                                     len(self.planned_revisions))
 
69
                revno += 1
75
70
                self.check_one_rev(rev_id)
 
71
            self.progress.clear()
76
72
        finally:
77
 
            self.progress.clear()
78
73
            self.branch.unlock()
79
74
 
80
75
    def report_results(self, verbose):
113
108
        last_rev_id - the previous one on the mainline, if any.
114
109
        """
115
110
 
116
 
        # mutter('    revision {%s}', rev_id)
 
111
        # mutter('    revision {%s}' % rev_id)
117
112
        branch = self.branch
118
113
        try:
119
114
            rev_history_position = self.history.index(rev_id)
133
128
 
134
129
        # check the previous history entry is a parent of this entry
135
130
        if rev.parent_ids:
 
131
            if last_rev_id is None and rev_history_position is not None:
 
132
                # what if the start is a ghost ? i.e. conceptually the 
 
133
                # baz imports
 
134
                raise BzrCheckError("revision {%s} has %d parents, but is the "
 
135
                                    "start of the branch"
 
136
                                    % (rev_id, len(rev.parent_ids)))
136
137
            if last_rev_id is not None:
137
138
                for parent_id in rev.parent_ids:
138
139
                    if parent_id == last_rev_id:
167
168
                    ' value in revision {%s}' % rev_id)
168
169
        else:
169
170
            missing_inventory_sha_cnt += 1
170
 
            mutter("no inventory_sha1 on revision {%s}", rev_id)
 
171
            mutter("no inventory_sha1 on revision {%s}" % rev_id)
171
172
        self._check_revision_tree(rev_id)
172
173
        self.checked_rev_cnt += 1
173
174