Rev 5285: Add the simplest setup I could think of to test that we can handle a ghost. in http://bazaar.launchpad.net/~jameinel/bzr/2.2-create-ghost

John Arbash Meinel john at arbash-meinel.com
Mon Jun 7 22:01:52 BST 2010


At http://bazaar.launchpad.net/~jameinel/bzr/2.2-create-ghost

------------------------------------------------------------
revno: 5285
revision-id: john at arbash-meinel.com-20100607210146-jfnxq4f4p1cfki6g
parent: pqm at pqm.ubuntu.com-20100607023804-g0tttwnphcv00q2o
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.2-create-ghost
timestamp: Mon 2010-06-07 16:01:46 -0500
message:
  Add the simplest setup I could think of to test that we can handle a ghost.
-------------- next part --------------
=== modified file 'bzrlib/tests/per_repository/test_repository.py'
--- a/bzrlib/tests/per_repository/test_repository.py	2010-05-06 23:41:35 +0000
+++ b/bzrlib/tests/per_repository/test_repository.py	2010-06-07 21:01:46 +0000
@@ -1242,6 +1242,61 @@
             repo.unlock()
 
 
+class TestCaseWithGhost(per_repository.TestCaseWithRepository):
+
+    def make_commit_with_ghost_parent(self, repo):
+        repo.start_write_group()
+        inv = inventory.Inventory(revision_id='A')
+        inv.root.revision = 'A'
+        if repo.supports_rich_root():
+            root_id = inv.root.file_id
+            repo.texts.add_lines((root_id, 'A'), [], [])
+        ie = inv.add_path('foo', kind='file', file_id='foo-id')
+        content = 'hello\n'
+        ie.text_size = len(content)
+        ie.text_sha1 = osutils.sha_string(content)
+        ie.revision = 'ghost'
+        inv_sha1 = repo.add_inventory('A', inv, ['ghost'])
+        repo.texts.add_lines(('foo-id', 'ghost'), [], [content])
+        rev = _mod_revision.Revision(timestamp=0, timezone=0,
+                                     committer='Foo Bar <foo at example.com>',
+                                     message='With ghost parent',
+                                     inventory_sha1=inv_sha1,
+                                     revision_id='A')
+        rev.parent_ids = ['ghost']
+        repo.add_revision('A', rev)
+        repo.commit_write_group()
+
+    def test_handles_ghost(self):
+        repo = self.make_repository('repository')
+        repo.lock_write()
+        self.make_commit_with_ghost_parent(repo)
+        repo.unlock()
+        b = repo.bzrdir.create_branch()
+        b.set_last_revision_info(1, 'A')
+        try:
+            tree = repo.bzrdir.create_workingtree(revision_id='A')
+        except errors.NotLocalUrl:
+            tree = b.create_checkout('checkout', revision_id='A',
+                                     lightweight=True)
+        tree.lock_write()
+        self.addCleanup(tree.unlock)
+        # All-in-one formats don't create a new tree, so we have to update the
+        # working contents.
+        tree.revert()
+        repo = tree.branch.repository
+        # Make sure 'ghost' is a revision considered to be a real ghost
+        # But that we can still get the revision tree, and disk content for all
+        # the content of 'A'.
+        self.assertEqual({'A': ('ghost',)}, repo.get_parent_map(['A', 'ghost']))
+        rt = repo.revision_tree('A')
+        self.assertEqual('ghost', rt.inventory['foo-id'].revision)
+        self.assertEqual('hello\n',
+            repo.texts.get_record_stream([('foo-id', 'ghost')], 'unordered',
+                True).next().get_bytes_as('fulltext'))
+        self.assertEqualDiff('hello\n', tree.get_file_text('foo-id'))
+
+
 class TestCaseWithCorruptRepository(per_repository.TestCaseWithRepository):
 
     def setUp(self):



More information about the bazaar-commits mailing list