~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/check.py

  • Committer: Andrew Bennetts
  • Date: 2008-12-12 03:53:56 UTC
  • mto: This revision was merged to the branch mainline in revision 3900.
  • Revision ID: andrew.bennetts@canonical.com-20081212035356-uqcu89gy4nqf017x
Fix compilation error in _dirstate_helpers_c on SunOS/Solaris. (Jari Aalto)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
# TODO: Check ancestries are correct for every revision: includes
18
18
# every committed so far, and in a reasonable order.
21
21
 
22
22
# TODO: Check for extra files in the control directory.
23
23
 
24
 
# TODO: Check revision, inventory and entry objects have all
 
24
# TODO: Check revision, inventory and entry objects have all 
25
25
# required fields.
26
26
 
27
27
# TODO: Get every revision in the revision-store even if they're not
63
63
        self.checked_weaves = set()
64
64
        self.unreferenced_versions = set()
65
65
        self.inconsistent_parents = []
66
 
        self.rich_roots = repository.supports_rich_root()
67
 
        self.text_key_references = {}
68
66
 
69
67
    def check(self):
70
68
        self.repository.lock_read()
168
166
        rev_id - the one to check
169
167
        """
170
168
        rev = self.repository.get_revision(rev_id)
171
 
 
 
169
                
172
170
        if rev.revision_id != rev_id:
173
171
            raise BzrCheckError('wrong internal revision id in revision {%s}'
174
172
                                % rev_id)
175
173
 
176
174
        for parent in rev.parent_ids:
177
175
            if not parent in self.planned_revisions:
178
 
                # rev has a parent we didn't know about.
179
176
                missing_links = self.missing_parent_links.get(parent, [])
180
177
                missing_links.append(rev_id)
181
178
                self.missing_parent_links[parent] = missing_links
184
181
                if self.repository.has_revision(parent):
185
182
                    missing_ancestry = self.repository.get_ancestry(parent)
186
183
                    for missing in missing_ancestry:
187
 
                        if (missing is not None
 
184
                        if (missing is not None 
188
185
                            and missing not in self.planned_revisions):
189
186
                            self.planned_revisions.append(missing)
190
187
                else:
191
188
                    self.ghosts.append(rev_id)
192
189
 
193
190
        if rev.inventory_sha1:
194
 
            # Loopback - this is currently circular logic as the
195
 
            # knit get_inventory_sha1 call returns rev.inventory_sha1.
196
 
            # Repository.py's get_inventory_sha1 should instead return
197
 
            # inventories.get_record_stream([(revid,)]).next().sha1 or
198
 
            # similar.
199
191
            inv_sha1 = self.repository.get_inventory_sha1(rev_id)
200
192
            if inv_sha1 != rev.inventory_sha1:
201
193
                raise BzrCheckError('Inventory sha1 hash doesn\'t match'
211
203
        self.inventory_weave.check(progress_bar=self.progress)
212
204
        self.progress.update('checking text storage', 1, 2)
213
205
        self.repository.texts.check(progress_bar=self.progress)
214
 
        weave_checker = self.repository._get_versioned_file_checker(
215
 
            text_key_references=self.text_key_references)
 
206
        weave_checker = self.repository._get_versioned_file_checker()
216
207
        result = weave_checker.check_file_version_parents(
217
208
            self.repository.texts, progress_bar=self.progress)
218
209
        self.checked_weaves = weave_checker.file_ids
231
222
    def _check_revision_tree(self, rev_id):
232
223
        tree = self.repository.revision_tree(rev_id)
233
224
        inv = tree.inventory
234
 
        seen_ids = set()
235
 
        seen_names = set()
236
 
        for path, ie in inv.iter_entries():
237
 
            self._add_entry_to_text_key_references(inv, ie)
238
 
            file_id = ie.file_id
 
225
        seen_ids = {}
 
226
        for file_id in inv:
239
227
            if file_id in seen_ids:
240
228
                raise BzrCheckError('duplicated file_id {%s} '
241
229
                                    'in inventory for revision {%s}'
242
230
                                    % (file_id, rev_id))
243
 
            seen_ids.add(file_id)
 
231
            seen_ids[file_id] = True
 
232
        for file_id in inv:
 
233
            ie = inv[file_id]
244
234
            ie.check(self, rev_id, inv, tree)
 
235
        seen_names = {}
 
236
        for path, ie in inv.iter_entries():
245
237
            if path in seen_names:
246
238
                raise BzrCheckError('duplicated path %s '
247
239
                                    'in inventory for revision {%s}'
248
240
                                    % (path, rev_id))
249
 
            seen_names.add(path)
250
 
 
251
 
    def _add_entry_to_text_key_references(self, inv, entry):
252
 
        if not self.rich_roots and entry == inv.root:
253
 
            return
254
 
        key = (entry.file_id, entry.revision)
255
 
        self.text_key_references.setdefault(key, False)
256
 
        if entry.revision == inv.revision_id:
257
 
            self.text_key_references[key] = True
 
241
            seen_names[path] = True
258
242
 
259
243
 
260
244
@deprecated_function(deprecated_in((1,6,0)))
261
245
def check(branch, verbose):
262
246
    """Run consistency checks on a branch.
263
 
 
 
247
    
264
248
    Results are reported through logging.
265
 
 
 
249
    
266
250
    Deprecated in 1.6.  Please use check_branch instead.
267
251
 
268
252
    :raise BzrCheckError: if there's a consistency error.
294
278
 
295
279
    if do_tree:
296
280
        if tree is not None:
297
 
            note("Checking working tree at '%s'."
 
281
            note("Checking working tree at '%s'." 
298
282
                 % (tree.bzrdir.root_transport.base,))
299
283
            tree._check()
300
284
        else: