~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

 * bzr add now lists how many files were ignored per glob.  add --verbose
   lists the specific files.  (Aaron Bentley)

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
    def __init__(self, branch):
43
43
        self.branch = branch
44
 
        self.repository = branch.repository
45
44
        self.checked_text_cnt = 0
46
45
        self.checked_rev_cnt = 0
47
46
        self.ghosts = []
51
50
        self.missing_revision_cnt = 0
52
51
        # maps (file-id, version) -> sha1
53
52
        self.checked_texts = {}
54
 
        self.checked_weaves = {}
55
53
 
56
54
    def check(self):
57
55
        self.branch.lock_read()
60
58
            self.progress.update('retrieving inventory', 0, 0)
61
59
            # do not put in init, as it should be done with progess,
62
60
            # and inside the lock.
63
 
            self.inventory_weave = self.branch.repository.get_inventory_weave()
 
61
            self.inventory_weave = self.branch._get_inventory_weave()
64
62
            self.history = self.branch.revision_history()
65
63
            if not len(self.history):
66
64
                # nothing to see here
67
65
                return
68
66
            self.plan_revisions()
69
67
            revno = 0
70
 
            self.check_weaves()
71
68
            while revno < len(self.planned_revisions):
72
69
                rev_id = self.planned_revisions[revno]
73
70
                self.progress.update('checking revision', revno,
79
76
            self.branch.unlock()
80
77
 
81
78
    def plan_revisions(self):
82
 
        repository = self.branch.repository
83
 
        if not repository.revision_store.listable():
84
 
            self.planned_revisions = repository.get_ancestry(self.history[-1])
 
79
        if not self.branch.revision_store.listable():
 
80
            self.planned_revisions = self.branch.get_ancestry(self.history[-1])
85
81
            self.planned_revisions.remove(None)
86
82
            # FIXME progress bars should support this more nicely.
87
83
            self.progress.clear()
89
85
                   " for a complete check use a local branch.")
90
86
            return
91
87
        
92
 
        self.planned_revisions = set(repository.revision_store)
 
88
        self.planned_revisions = set(self.branch.revision_store)
93
89
        inventoried = set(self.inventory_weave.names())
94
90
        awol = self.planned_revisions - inventoried
95
91
        if len(awol) > 0:
98
94
        self.planned_revisions = list(self.planned_revisions)
99
95
 
100
96
    def report_results(self, verbose):
101
 
        note('checked branch %s format %s',
 
97
        note('checked branch %s format %d',
102
98
             self.branch.base, 
103
 
             self.branch._format)
 
99
             self.branch._branch_format)
104
100
 
105
101
        note('%6d revisions', self.checked_rev_cnt)
106
102
        note('%6d unique file texts', self.checked_text_cnt)
107
103
        note('%6d repeated file texts', self.repeated_text_cnt)
108
 
        note('%6d weaves', len(self.checked_weaves))
109
104
        if self.missing_inventory_sha_cnt:
110
105
            note('%6d revisions are missing inventory_sha1',
111
106
                 self.missing_inventory_sha_cnt)
142
137
            rev_history_position = None
143
138
        last_rev_id = None
144
139
        if rev_history_position:
145
 
            rev = branch.repository.get_revision(rev_id)
 
140
            rev = branch.get_revision(rev_id)
146
141
            if rev_history_position > 0:
147
142
                last_rev_id = self.history[rev_history_position - 1]
148
143
        else:
149
 
            rev = branch.repository.get_revision(rev_id)
 
144
            rev = branch.get_revision(rev_id)
150
145
                
151
146
        if rev.revision_id != rev_id:
152
147
            raise BzrCheckError('wrong internal revision id in revision {%s}'
170
165
                    # list based so somewhat slow,
171
166
                    # TODO have a planned_revisions list and set.
172
167
                    if self.branch.has_revision(parent):
173
 
                        missing_ancestry = self.repository.get_ancestry(parent)
 
168
                        missing_ancestry = self.branch.get_ancestry(parent)
174
169
                        for missing in missing_ancestry:
175
170
                            if (missing is not None 
176
171
                                and missing not in self.planned_revisions):
183
178
                                % (rev_id, last_rev_id))
184
179
 
185
180
        if rev.inventory_sha1:
186
 
            inv_sha1 = branch.repository.get_inventory_sha1(rev_id)
 
181
            inv_sha1 = branch.get_inventory_sha1(rev_id)
187
182
            if inv_sha1 != rev.inventory_sha1:
188
183
                raise BzrCheckError('Inventory sha1 hash doesn\'t match'
189
184
                    ' value in revision {%s}' % rev_id)
193
188
        self._check_revision_tree(rev_id)
194
189
        self.checked_rev_cnt += 1
195
190
 
196
 
    def check_weaves(self):
197
 
        """Check all the weaves we can get our hands on.
198
 
        """
199
 
        n_weaves = 1
200
 
        weave_ids = []
201
 
        if self.branch.repository.weave_store.listable():
202
 
            weave_ids = list(self.branch.repository.weave_store)
203
 
            n_weaves = len(weave_ids)
204
 
        self.progress.update('checking weave', 0, n_weaves)
205
 
        self.inventory_weave.check(progress_bar=self.progress)
206
 
        for i, weave_id in enumerate(weave_ids):
207
 
            self.progress.update('checking weave', i, n_weaves)
208
 
            w = self.branch.repository.weave_store.get_weave(weave_id,
209
 
                    self.branch.repository.get_transaction())
210
 
            # No progress here, because it looks ugly.
211
 
            w.check()
212
 
            self.checked_weaves[weave_id] = True
213
 
 
214
191
    def _check_revision_tree(self, rev_id):
215
 
        tree = self.branch.repository.revision_tree(rev_id)
 
192
        tree = self.branch.revision_tree(rev_id)
216
193
        inv = tree.inventory
217
194
        seen_ids = {}
218
195
        for file_id in inv: