Rev 3039: Fix bug #165290 by having the fetch code check that all external references are satisfied before it allows the data to be committed. in http://bzr.arbash-meinel.com/branches/bzr/0.93-dev/fetch_check_parents_165290

John Arbash Meinel john at arbash-meinel.com
Fri Nov 30 20:12:52 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.93-dev/fetch_check_parents_165290

------------------------------------------------------------
revno: 3039
revision-id:john at arbash-meinel.com-20071130201158-s0ex85foh34nv429
parent: john at arbash-meinel.com-20071130050802-aqswmc0a7sv7hal9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: fetch_check_parents_165290
timestamp: Fri 2007-11-30 14:11:58 -0600
message:
  Fix bug #165290 by having the fetch code check that all external references are satisfied before it allows the data to be committed.
modified:
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/tests/interrepository_implementations/test_interrepository.py test_interrepository.py-20060220061411-1ec13fa99e5e3eee
-------------- next part --------------
=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2007-11-29 05:23:52 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2007-11-30 20:11:58 +0000
@@ -173,6 +173,14 @@
         """The text index is the name + .tix."""
         return self.index_name('text', name)
 
+    def _external_compression_parents_of_new_texts(self):
+        keys = set()
+        refs = set()
+        for node in self.text_index.iter_all_entries():
+            keys.add(node[1])
+            refs.update(node[3][1])
+        return refs - keys
+
 
 class ExistingPack(Pack):
     """An in memory proxy for an existing .pack and its disk indices."""
@@ -834,14 +842,6 @@
                 pb.update("Copied record", record_index)
                 record_index += 1
 
-    def _external_compression_parents_of_new_texts(self):
-        keys = set()
-        refs = set()
-        for node in self.new_pack.text_index.iter_all_entries():
-            keys.add(node[1])
-            refs.update(node[3][1])
-        return refs - keys
-
     def _get_text_nodes(self):
         text_index_map = self._pack_collection._packs_list_to_pack_map_and_index_list(
             self.packs, 'text_index')[0]
@@ -988,7 +988,7 @@
             output_knit.add_lines_with_ghosts(
                 key[1], parents, text_lines, random_id=True, check_content=False)
         # 4) check that nothing inserted has a reference outside the keyspace.
-        missing_text_keys = self._external_compression_parents_of_new_texts()
+        missing_text_keys = self.new_pack._external_compression_parents_of_new_texts()
         if missing_text_keys:
             raise errors.BzrError('Reference to missing compression parents %r'
                 % (refs - keys,))

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-11-29 04:14:06 +0000
+++ b/bzrlib/repository.py	2007-11-30 20:11:58 +0000
@@ -2558,6 +2558,16 @@
         pack = Packer(self.target._pack_collection, packs, '.fetch',
             revision_ids).pack()
         if pack is not None:
+            external_refs = pack._external_compression_parents_of_new_texts()
+            if external_refs:
+                index = self.target._pack_collection.text_index.combined_index
+                found_items = list(index.iter_entries(external_refs))
+                if len(found_items) != len(external_refs):
+                    found_keys = set(k for idx, k, refs, value in found_items)
+                    missing_items = external_refs - found_keys
+                    missing_file_id, missing_revision_id = missing_items.pop()
+                    raise errors.MissingText(self.target, missing_revision_id,
+                                             missing_file_id)
             self.target._pack_collection._save_pack_names()
             # Trigger an autopack. This may duplicate effort as we've just done
             # a pack creation, but for now it is simpler to think about as

=== modified file 'bzrlib/tests/interrepository_implementations/test_interrepository.py'
--- a/bzrlib/tests/interrepository_implementations/test_interrepository.py	2007-11-29 22:41:30 +0000
+++ b/bzrlib/tests/interrepository_implementations/test_interrepository.py	2007-11-30 20:11:58 +0000
@@ -186,7 +186,7 @@
         # exception
         try:
             to_repo.fetch(tree.branch.repository, 'rev-two')
-        except Exception:
+        except (errors.MissingText, errors.RevisionNotPresent), e:
             # If an exception is raised, the revision should not be in the
             # target.
             self.assertRaises((errors.NoSuchRevision, errors.RevisionNotPresent),



More information about the bazaar-commits mailing list