コード例 #1
0
 def test_to_inventory_root_id_not_versioned(self):
     delta = [(None, '', 'an-id',
               inventory.make_entry('directory', '', None, 'an-id'))]
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=True)
     self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
                       'old-version', 'new-version', delta)
コード例 #2
0
 def test_to_inventory_root_id_versioned_not_permitted(self):
     root_entry = inventory.make_entry('directory', '', None, 'TREE_ROOT')
     root_entry.revision = 'some-version'
     delta = [(None, '', 'TREE_ROOT', root_entry)]
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=False, tree_references=True)
     self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
                       'old-version', 'new-version', delta)
コード例 #3
0
 def test_empty_delta_to_lines(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=True)
     self.assertEqual(
         StringIO(empty_lines).readlines(),
         serializer.delta_to_lines(NULL_REVISION, NULL_REVISION, delta))
コード例 #4
0
 def test_richroot_unversioned_root_errors(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     root = new_inv.make_entry('directory', '', None, 'TREE_ROOT')
     new_inv.add(root)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=True)
     err = self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
                             NULL_REVISION, 'entry-version', delta)
     self.assertEqual(str(err), 'no version for fileid TREE_ROOT')
コード例 #5
0
 def test_nonrichroot_versioned_root_errors(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     root = new_inv.make_entry('directory', '', None, 'TREE_ROOT')
     root.revision = 'a@e\xc3\xa5ample.com--2004'
     new_inv.add(root)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=False, tree_references=True)
     err = self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
                             NULL_REVISION, 'entry-version', delta)
     self.assertStartsWith(str(err), 'Version present for / in TREE_ROOT')
コード例 #6
0
 def test_root_only_to_lines(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     root = new_inv.make_entry('directory', '', None, 'an-id')
     root.revision = 'a@e\xc3\xa5ample.com--2004'
     new_inv.add(root)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=True)
     self.assertEqual(
         StringIO(root_only_lines).readlines(),
         serializer.delta_to_lines(NULL_REVISION, 'entry-version', delta))
コード例 #7
0
 def test_to_inventory_has_tree_not_meant_to(self):
     make_entry = inventory.make_entry
     tree_ref = make_entry('tree-reference', 'foo', 'changed-in', 'ref-id')
     tree_ref.reference_revision = 'ref-revision'
     delta = [(None, '', 'an-id',
               make_entry('directory', '', 'changed-in', 'an-id')),
              (None, 'foo', 'ref-id', tree_ref)
              # a file that followed the root move
              ]
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=True)
     self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
                       'old-version', 'new-version', delta)
コード例 #8
0
 def test_unversioned_non_root_errors(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     root = new_inv.make_entry('directory', '', None, 'TREE_ROOT')
     root.revision = 'a@e\xc3\xa5ample.com--2004'
     new_inv.add(root)
     non_root = new_inv.make_entry('directory', 'foo', root.file_id, 'id')
     new_inv.add(non_root)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=True)
     err = self.assertRaises(InventoryDeltaError, serializer.delta_to_lines,
                             NULL_REVISION, 'entry-version', delta)
     self.assertEqual(str(err), 'no version for fileid id')
コード例 #9
0
 def test_tree_reference_enabled(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     root = new_inv.make_entry('directory', '', None, 'TREE_ROOT')
     root.revision = 'a@e\xc3\xa5ample.com--2004'
     new_inv.add(root)
     non_root = new_inv.make_entry('tree-reference', 'foo', root.file_id,
                                   'id')
     non_root.revision = 'changed'
     non_root.reference_revision = 'subtree-version'
     new_inv.add(non_root)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=True)
     self.assertEqual(
         StringIO(reference_lines).readlines(),
         serializer.delta_to_lines(NULL_REVISION, 'entry-version', delta))
コード例 #10
0
 def _inventory_delta_stream(self, repository, ordering, revids):
     prev_inv = _mod_inventory.Inventory(root_id=None,
         revision_id=_mod_revision.NULL_REVISION)
     serializer = inventory_delta.InventoryDeltaSerializer(
         repository.supports_rich_root(),
         repository._format.supports_tree_reference)
     repository.lock_read()
     try:
         for inv, revid in repository._iter_inventories(revids, ordering):
             if inv is None:
                 continue
             inv_delta = inv._make_delta(prev_inv)
             lines = serializer.delta_to_lines(
                 prev_inv.revision_id, inv.revision_id, inv_delta)
             yield ChunkedContentFactory(inv.revision_id, None, None, lines)
             prev_inv = inv
     finally:
         repository.unlock()
コード例 #11
0
 def test_unversioned_root(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     root = new_inv.make_entry('directory', '', None, 'TREE_ROOT')
     # Implicit roots are considered modified in every revision.
     root.revision = 'entry-version'
     new_inv.add(root)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=False, tree_references=False)
     serialized_lines = serializer.delta_to_lines(NULL_REVISION,
                                                  'entry-version', delta)
     self.assertEqual(
         StringIO(root_only_unversioned).readlines(), serialized_lines)
     deserializer = inventory_delta.InventoryDeltaDeserializer()
     self.assertEqual(
         (NULL_REVISION, 'entry-version', False, False, delta),
         deserializer.parse_text_bytes(''.join(serialized_lines)))
コード例 #12
0
 def test_tree_reference_disabled(self):
     old_inv = Inventory(None)
     new_inv = Inventory(None)
     root = new_inv.make_entry('directory', '', None, 'TREE_ROOT')
     root.revision = 'a@e\xc3\xa5ample.com--2004'
     new_inv.add(root)
     non_root = new_inv.make_entry('tree-reference', 'foo', root.file_id,
                                   'id')
     non_root.revision = 'changed'
     non_root.reference_revision = 'subtree-version'
     new_inv.add(non_root)
     delta = new_inv._make_delta(old_inv)
     serializer = inventory_delta.InventoryDeltaSerializer(
         versioned_root=True, tree_references=False)
     # we expect keyerror because there is little value wrapping this.
     # This test aims to prove that it errors more than how it errors.
     err = self.assertRaises(KeyError, serializer.delta_to_lines,
                             NULL_REVISION, 'entry-version', delta)
     self.assertEqual(('tree-reference', ), err.args)
コード例 #13
0
    def test_unknown_kind_errors(self):
        old_inv = Inventory(None)
        new_inv = Inventory(None)
        root = new_inv.make_entry('directory', '', None, 'my-rich-root-id')
        root.revision = 'changed'
        new_inv.add(root)

        class StrangeInventoryEntry(inventory.InventoryEntry):
            kind = 'strange'

        non_root = StrangeInventoryEntry('id', 'foo', root.file_id)
        non_root.revision = 'changed'
        new_inv.add(non_root)
        delta = new_inv._make_delta(old_inv)
        serializer = inventory_delta.InventoryDeltaSerializer(
            versioned_root=True, tree_references=True)
        # we expect keyerror because there is little value wrapping this.
        # This test aims to prove that it errors more than how it errors.
        err = self.assertRaises(KeyError, serializer.delta_to_lines,
                                NULL_REVISION, 'entry-version', delta)
        self.assertEqual(('strange', ), err.args)
コード例 #14
0
    def test_to_inventory_torture(self):
        def make_entry(kind, name, parent_id, file_id, **attrs):
            entry = inventory.make_entry(kind, name, parent_id, file_id)
            for name, value in attrs.items():
                setattr(entry, name, value)
            return entry

        # this delta is crafted to have all the following:
        # - deletes
        # - renamed roots
        # - deep dirs
        # - files moved after parent dir was renamed
        # - files with and without exec bit
        delta = [
            # new root:
            (None, '', 'new-root-id',
             make_entry('directory',
                        '',
                        None,
                        'new-root-id',
                        revision='changed-in')),
            # an old root:
            ('', 'old-root', 'TREE_ROOT',
             make_entry('directory',
                        'subdir-now',
                        'new-root-id',
                        'TREE_ROOT',
                        revision='moved-root')),
            # a file that followed the root move
            ('under-old-root', 'old-root/under-old-root', 'moved-id',
             make_entry('file',
                        'under-old-root',
                        'TREE_ROOT',
                        'moved-id',
                        revision='old-rev',
                        executable=False,
                        text_size=30,
                        text_sha1='some-sha')),
            # a deleted path
            ('old-file', None, 'deleted-id', None),
            # a tree reference moved to the new root
            ('ref', 'ref', 'ref-id',
             make_entry('tree-reference',
                        'ref',
                        'new-root-id',
                        'ref-id',
                        reference_revision='tree-reference-id',
                        revision='new-rev')),
            # a symlink now in a deep dir
            ('dir/link', 'old-root/dir/link', 'link-id',
             make_entry('symlink',
                        'link',
                        'deep-id',
                        'link-id',
                        symlink_target='target',
                        revision='new-rev')),
            # a deep dir
            ('dir', 'old-root/dir', 'deep-id',
             make_entry('directory',
                        'dir',
                        'TREE_ROOT',
                        'deep-id',
                        revision='new-rev')),
            # a file with an exec bit set
            (None, 'configure', 'exec-id',
             make_entry('file',
                        'configure',
                        'new-root-id',
                        'exec-id',
                        executable=True,
                        text_size=30,
                        text_sha1='some-sha',
                        revision='old-rev')),
        ]
        serializer = inventory_delta.InventoryDeltaSerializer(
            versioned_root=True, tree_references=True)
        lines = serializer.delta_to_lines(NULL_REVISION, 'something', delta)
        expected = """format: bzr inventory delta v1 (bzr 1.14)
parent: null:
version: something
versioned_root: true
tree_references: true
/\x00/old-root\x00TREE_ROOT\x00new-root-id\x00moved-root\x00dir
/dir\x00/old-root/dir\x00deep-id\x00TREE_ROOT\x00new-rev\x00dir
/dir/link\x00/old-root/dir/link\x00link-id\x00deep-id\x00new-rev\x00link\x00target
/old-file\x00None\x00deleted-id\x00\x00null:\x00deleted\x00\x00
/ref\x00/ref\x00ref-id\x00new-root-id\x00new-rev\x00tree\x00tree-reference-id
/under-old-root\x00/old-root/under-old-root\x00moved-id\x00TREE_ROOT\x00old-rev\x00file\x0030\x00\x00some-sha
None\x00/\x00new-root-id\x00\x00changed-in\x00dir
None\x00/configure\x00exec-id\x00new-root-id\x00old-rev\x00file\x0030\x00Y\x00some-sha
"""
        serialized = ''.join(lines)
        self.assertIsInstance(serialized, str)
        self.assertEqual(expected, serialized)