Exemple #1
0
    def setUp(self):
        super(TestCaseWithCorruptRepository, self).setUp()
        # a inventory with no parents and the revision has parents..
        # i.e. a ghost.
        repo = self.make_repository('inventory_with_unnecessary_ghost')
        repo.lock_write()
        repo.start_write_group()
        inv = inventory.Inventory(revision_id=b'ghost')
        inv.root.revision = b'ghost'
        if repo.supports_rich_root():
            root_id = inv.root.file_id
            repo.texts.add_lines((root_id, b'ghost'), [], [])
        sha1 = repo.add_inventory(b'ghost', inv, [])
        rev = _mod_revision.Revision(timestamp=0,
                                     timezone=None,
                                     committer="Foo Bar <*****@*****.**>",
                                     message="Message",
                                     inventory_sha1=sha1,
                                     revision_id=b'ghost')
        rev.parent_ids = [b'the_ghost']
        try:
            repo.add_revision(b'ghost', rev)
        except (errors.NoSuchRevision, errors.RevisionNotPresent):
            raise tests.TestNotApplicable(
                "Cannot test with ghosts for this format.")

        inv = inventory.Inventory(revision_id=b'the_ghost')
        inv.root.revision = b'the_ghost'
        if repo.supports_rich_root():
            root_id = inv.root.file_id
            repo.texts.add_lines((root_id, b'the_ghost'), [], [])
        sha1 = repo.add_inventory(b'the_ghost', inv, [])
        rev = _mod_revision.Revision(timestamp=0,
                                     timezone=None,
                                     committer="Foo Bar <*****@*****.**>",
                                     message="Message",
                                     inventory_sha1=sha1,
                                     revision_id=b'the_ghost')
        rev.parent_ids = []
        repo.add_revision(b'the_ghost', rev)
        # check its setup usefully
        inv_weave = repo.inventories
        possible_parents = (None, ((b'ghost', ), ))
        self.assertSubset(
            inv_weave.get_parent_map([(b'ghost', )])[(b'ghost', )],
            possible_parents)
        repo.commit_write_group()
        repo.unlock()
Exemple #2
0
 def test_add_revision_inventory_sha1(self):
     inv = inventory.Inventory(revision_id=b'A')
     inv.root.revision = b'A'
     inv.root.file_id = b'fixed-root'
     # Insert the inventory on its own to an identical repository, to get
     # its sha1.
     reference_repo = self.make_repository('reference_repo')
     reference_repo.lock_write()
     reference_repo.start_write_group()
     inv_sha1 = reference_repo.add_inventory(b'A', inv, [])
     reference_repo.abort_write_group()
     reference_repo.unlock()
     # Now insert a revision with this inventory, and it should get the same
     # sha1.
     repo = self.make_repository('repo')
     repo.lock_write()
     repo.start_write_group()
     root_id = inv.root.file_id
     repo.texts.add_lines((b'fixed-root', b'A'), [], [])
     repo.add_revision(b'A',
                       _mod_revision.Revision(b'A',
                                              committer='B',
                                              timestamp=0,
                                              timezone=0,
                                              message='C'),
                       inv=inv)
     repo.commit_write_group()
     repo.unlock()
     repo.lock_read()
     self.assertEqual(inv_sha1, repo.get_revision(b'A').inventory_sha1)
     repo.unlock()
Exemple #3
0
 def test_non_directory_children(self):
     """Test path2id when a parent directory has no children"""
     inv = inventory.Inventory(b'tree-root')
     inv.add(self.make_file(b'file-id', 'file', b'tree-root'))
     inv.add(self.make_link(b'link-id', 'link', b'tree-root'))
     self.assertIs(None, inv.path2id('file/subfile'))
     self.assertIs(None, inv.path2id('link/subfile'))
Exemple #4
0
 def test_does_something_reconcile(self):
     t = controldir.ControlDir.create_standalone_workingtree('.')
     # an empty inventory with no revision will trigger reconciliation.
     repo = t.branch.repository
     inv = inventory.Inventory(revision_id=b'missing')
     inv.root.revision = b'missing'
     repo.lock_write()
     with repo.lock_write(), WriteGroup(repo):
         repo.add_inventory(b'missing', inv, [])
     (out, err) = self.run_bzr('reconcile')
     if repo._reconcile_backsup_inventory:
         does_backup_text = (
             "Backup Inventory created.\n"
             "Inventory regenerated.\n")
     else:
         does_backup_text = ""
     expected = ("Reconciling branch %s\n"
                 "revision_history ok.\n"
                 "Reconciling repository %s\n"
                 "%s"
                 "Reconciliation complete.\n" %
                 (t.branch.base,
                  t.controldir.root_transport.base,
                  does_backup_text))
     self.assertEqualDiff(expected, out)
     self.assertEqualDiff(err, "")
Exemple #5
0
    def test_get_entry_by_path_partial(self):
        inv = inventory.Inventory(b'TREE_ROOT')
        inv.root.revision = b'revision'
        for args in [('src', 'directory', b'src-id'),
                     ('doc', 'directory', b'doc-id'),
                     ('src/hello.c', 'file'),
                     ('src/bye.c', 'file', b'bye-id'),
                     ('Makefile', 'file'),
                     ('external', 'tree-reference', b'other-root')]:
            ie = inv.add_path(*args)
            ie.revision = b'revision'
            if args[1] == 'file':
                ie.text_sha1 = osutils.sha_string(b'content\n')
                ie.text_size = len(b'content\n')
            if args[1] == 'tree-reference':
                ie.reference_revision = b'reference'
        inv = self.inv_to_test_inv(inv)

        # Standard lookups
        ie, resolved, remaining = inv.get_entry_by_path_partial('')
        self.assertEqual((ie.file_id, resolved, remaining), (b'TREE_ROOT', [], []))
        ie, resolved, remaining = inv.get_entry_by_path_partial('src')
        self.assertEqual((ie.file_id, resolved, remaining), (b'src-id', ['src'], []))
        ie, resolved, remaining = inv.get_entry_by_path_partial('src/bye.c')
        self.assertEqual((ie.file_id, resolved, remaining), (b'bye-id', ['src', 'bye.c'], []))

        # Paths in the external tree
        ie, resolved, remaining = inv.get_entry_by_path_partial('external')
        self.assertEqual((ie.file_id, resolved, remaining), (b'other-root', ['external'], []))
        ie, resolved, remaining = inv.get_entry_by_path_partial('external/blah')
        self.assertEqual((ie.file_id, resolved, remaining), (b'other-root', ['external'], ['blah']))

        # Nonexistant paths
        ie, resolved, remaining = inv.get_entry_by_path_partial('foo.c')
        self.assertEqual((ie, resolved, remaining), (None, None, None))
Exemple #6
0
    def __init__(self, loom_meta_ie, loom_stream, loom_sha1):
        """Create a Loom Meta Tree.

        :param loom_content_lines: the unicode content to be used for the loom.
        """
        self._inventory = _mod_inventory.Inventory()
        self._inventory.add(loom_meta_ie)
        self._loom_stream = loom_stream
        self._loom_sha1 = loom_sha1
Exemple #7
0
 def test_ids(self):
     """Test detection of files within selected directories."""
     inv = inventory.Inventory(b'TREE_ROOT')
     inv.root.revision = b'revision'
     for args in [('src', 'directory', b'src-id'),
                  ('doc', 'directory', b'doc-id'), ('src/hello.c', 'file'),
                  ('src/bye.c', 'file', b'bye-id'), ('Makefile', 'file')]:
         ie = inv.add_path(*args)
         ie.revision = b'revision'
         if args[1] == 'file':
             ie.text_sha1 = osutils.sha_string(b'content\n')
             ie.text_size = len(b'content\n')
     inv = self.inv_to_test_inv(inv)
     self.assertEqual(inv.path2id('src'), b'src-id')
     self.assertEqual(inv.path2id('src/bye.c'), b'bye-id')
Exemple #8
0
 def prepare_inv_with_nested_dirs(self):
     inv = inventory.Inventory(b'tree-root')
     inv.root.revision = b'revision'
     for args in [('src', 'directory', b'src-id'),
                  ('doc', 'directory', b'doc-id'),
                  ('src/hello.c', 'file', b'hello-id'),
                  ('src/bye.c', 'file', b'bye-id'),
                  ('zz', 'file', b'zz-id'),
                  ('src/sub/', 'directory', b'sub-id'),
                  ('src/zz.c', 'file', b'zzc-id'),
                  ('src/sub/a', 'file', b'a-id'),
                  ('Makefile', 'file', b'makefile-id')]:
         ie = inv.add_path(*args)
         ie.revision = b'revision'
         if args[1] == 'file':
             ie.text_sha1 = osutils.sha_string(b'content\n')
             ie.text_size = len(b'content\n')
     return self.inv_to_test_inv(inv)
Exemple #9
0
 def make_init_inventory(self):
     inv = inventory.Inventory(b'tree-root')
     inv.revision = b'initial-rev'
     inv.root.revision = b'initial-rev'
     return self.inv_to_test_inv(inv)