[MERGE] Implement KnitRepository._find_inconsistent_revision_parents

Andrew Bennetts andrew at canonical.com
Fri Sep 14 05:20:47 BST 2007


This adds a method to KnitRepository that can detect if the knit index graph
disagrees with the revision texts about what the parents of a revision are.
It's not used by anything yet, aside from the test, but I'm about to hook it
into check.

-Andrew.

-------------- next part --------------
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: andrew.bennetts at canonical.com-20070914041757-\
#   bdwh2flaqzg3i2dc
# target_branch: http://bazaar-vcs.org/bzr/bzr.dev
# testament_sha1: 1beef3e5f653275735f1d251809adf360acd4fa5
# timestamp: 2007-09-14 14:18:10 +1000
# source_branch: http://people.ubuntu.com/~andrew/bzr/find-\
#   inconsistent-parents
# base_revision_id: pqm at pqm.ubuntu.com-20070914004213-xraql0v7q1p63j81
# 
# Begin patch
=== added file 'bzrlib/tests/repository_implementations/test_check.py'
--- bzrlib/tests/repository_implementations/test_check.py	1970-01-01 00:00:00 +0000
+++ bzrlib/tests/repository_implementations/test_check.py	2007-09-14 04:17:57 +0000
@@ -0,0 +1,61 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+"""Test operations that check the repository for corruption"""
+
+
+from bzrlib import (
+    inventory,
+    revision as _mod_revision,
+    )
+from bzrlib.repofmt.knitrepo import RepositoryFormatKnit
+from bzrlib.tests.repository_implementations import TestCaseWithRepository
+from bzrlib.tests import TestNotApplicable
+
+
+class TestFindInconsistentRevisionParents(TestCaseWithRepository):
+
+    def test_extra_ghost_in_index(self):
+        if not isinstance(self.repository_format, RepositoryFormatKnit):
+            # XXX: This could happen to weaves too, but they're pretty
+            # deprecated.
+            raise TestNotApplicable(
+                "%s isn't a knit format" % self.repository_format)
+        # Make a repo with one revision.
+        repo = self.make_repository('broken')
+        inv = inventory.Inventory(revision_id='revision-id')
+        inv.root.revision = 'revision-id'
+        repo.add_inventory('revision-id', inv, [])
+        revision = _mod_revision.Revision('revision-id',
+            committer='jrandom at example.com', timestamp=0,
+            inventory_sha1='', timezone=0, message='message', parent_ids=[])
+        repo.add_revision('revision-id',revision, inv)
+
+        # Change the knit index's record of the parents for 'revision-id' to
+        # claim it has a parent that doesn't exist in this knit at all.
+        repo.lock_read()
+        rev_knit = repo._get_revision_vf()
+        index_cache = rev_knit._index._cache
+        cached_index_entry = list(index_cache['revision-id'])
+        cached_index_entry[4] = ['incorrect-parent']
+        index_cache['revision-id'] = tuple(cached_index_entry)
+
+        self.assertEqual(
+            [('revision-id', ['incorrect-parent'], [])],
+            list(repo._find_inconsistent_revision_parents()))
+        repo.unlock()
+

=== modified file 'bzrlib/repofmt/knitrepo.py'
--- bzrlib/repofmt/knitrepo.py	2007-09-12 04:21:51 +0000
+++ bzrlib/repofmt/knitrepo.py	2007-09-14 04:17:57 +0000
@@ -224,6 +224,22 @@
     def _make_parents_provider(self):
         return _KnitParentsProvider(self._get_revision_vf())
 
+    def _find_inconsistent_revision_parents(self):
+        """Find revisions with different parent lists in the revision object
+        and in the index graph.
+        """
+        vf = self._get_revision_vf()
+        index_versions = vf.versions()
+        for index_version in index_versions:
+            parents_according_to_index = vf._index.get_parents_with_ghosts(
+                index_version)
+            revision = self._revision_store.get_revision(index_version,
+                self.get_transaction())
+            parents_according_to_revision = revision.parent_ids
+            if parents_according_to_index != parents_according_to_revision:
+                yield (index_version, parents_according_to_index,
+                    parents_according_to_revision)
+
 
 class KnitRepository3(KnitRepository):
 

=== modified file 'bzrlib/tests/repository_implementations/__init__.py'
--- bzrlib/tests/repository_implementations/__init__.py	2007-08-17 05:16:14 +0000
+++ bzrlib/tests/repository_implementations/__init__.py	2007-09-14 04:17:57 +0000
@@ -99,6 +99,7 @@
     result = TestSuite()
     test_repository_implementations = [
         'bzrlib.tests.repository_implementations.test_break_lock',
+        'bzrlib.tests.repository_implementations.test_check',
         'bzrlib.tests.repository_implementations.test_commit_builder',
         'bzrlib.tests.repository_implementations.test_fetch',
         'bzrlib.tests.repository_implementations.test_fileid_involved',

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWSGVOKsABKj/gGRUQAB77///
f+//+r////BgC219Y55nu9hQD0u6Wdkave949K9nQcaZo5OASSFU/aEm1NDT0aZTFH6ICaeo9Q0D
QBtRoaZAZAamUyaMjQFNogNBoaaNDQGjIAaAANAGgJompk01J4oaYho9J6g0AZAaaAZADNRoEiKZ
JhApP00ZRhJtTeo1PU9T0n6mkaHqaaZNANAADmjRoaYQDTAmmgDIaGIA0YjQwRkAEkgQ0mCZAmk9
Gp6qf6aVP0p4apvVH6pso3pT2ppqepvVNADZIo2RMCDPsHNd7by5VY5zjPhaDDdPw5lEha6aW3tW
Px2tKs+S9hI/cZT2kQyphLmtt5TDRM3DMc34j5cdw+fVJJbpvT4qlMDJ7aHcOxw92TuHS0UBDjHR
u162PWdJjYlmgdDedJICIkjDXP6bt2jbeXc3PbSFxsGZhmX/MP8o0frWjMww1MjS4YFFk7zdydua
TLcuZm7Ml6eFrbsbLNXy/tGXGZOJLiB8ZZoybRS1NHAehPkL4gqTs4y60g3olzjaLRH3dRpoWvRd
MlsSDs0bDtjlWnYA5pPPk6NrV1LHCYYl20X+Hus+3jc4me9ogPjMJEjufAZrdYSnNcjNg983pUWO
YzjEoZbdSyFlg3nRIU6M3PRAETlpSRAloC4nkcrKlh/7gCGvqFNC0RoSdd6VZzsmIr8KopYE97Ak
TyPrOWxESs1wO9udbrHHJ3k/MdNOhaN++e/mOLtPjk9HEBbdyTQaQVC1g2ehqIg108MZi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