Beispiel #1
0
 def make_file(self, file_id, name, parent_id, content='content\n',
               revision='new-test-rev'):
     ie = InventoryFile(file_id, name, parent_id)
     ie.text_sha1 = osutils.sha_string(content)
     ie.text_size = len(content)
     ie.revision = revision
     return ie
Beispiel #2
0
 def test_error_encoding(self):
     inv = self.make_inventory('tree-root')
     inv.add(InventoryFile('a-id', u'\u1234', 'tree-root'))
     try:
         inv.add(InventoryFile('b-id', u'\u1234', 'tree-root'))
     except errors.BzrError, e:
         self.assertContainsRe(str(e), u'\u1234'.encode('utf-8'))
Beispiel #3
0
 def test_add_recursive(self):
     parent = InventoryDirectory('src-id', 'src', 'tree-root')
     child = InventoryFile('hello-id', 'hello.c', 'src-id')
     parent.children[child.file_id] = child
     inv = self.make_inventory('tree-root')
     inv.add(parent)
     self.assertEqual('src/hello.c', inv.id2path('hello-id'))
Beispiel #4
0
 def test_non_directory_children(self):
     """Test path2id when a parent directory has no children"""
     inv = self.make_inventory('tree_root')
     inv.add(InventoryFile('file-id', 'file', parent_id='tree_root'))
     inv.add(InventoryLink('link-id', 'link', parent_id='tree_root'))
     self.assertIs(None, inv.path2id('file/subfile'))
     self.assertIs(None, inv.path2id('link/subfile'))
Beispiel #5
0
        def add_entry(file_id):
            path = self.id2path(file_id)
            if path is None:
                return
            if path == '':
                parent_id = None
            else:
                parent_path = dirname(path)
                parent_id = self.path2id(parent_path)

            kind = self.kind(file_id)
            revision_id = self.get_last_changed(file_id)

            name = basename(path)
            if kind == 'directory':
                ie = InventoryDirectory(file_id, name, parent_id)
            elif kind == 'file':
                ie = InventoryFile(file_id, name, parent_id)
                ie.executable = self.is_executable(file_id)
            elif kind == 'symlink':
                ie = InventoryLink(file_id, name, parent_id)
                ie.symlink_target = self.get_symlink_target(file_id, path)
            ie.revision = revision_id

            if kind == 'file':
                ie.text_size, ie.text_sha1 = self.get_size_and_sha1(file_id)
                if ie.text_size is None:
                    raise BzrError('Got a text_size of None for file_id %r' %
                                   file_id)
            inv.add(ie)
Beispiel #6
0
def read_inventory(inv_file):
    """Read inventory object from rio formatted inventory file"""
    from bzrlib.inventory import Inventory, InventoryFile
    s = read_stanza(inv_file)
    assert s['inventory_version'] == 7
    inv = Inventory()
    for s in read_stanzas(inv_file):
        kind, file_id = s.items[0]
        parent_id = None
        if 'parent_id' in s:
            parent_id = s['parent_id']
        if kind == 'file':
            ie = InventoryFile(file_id, s['name'], parent_id)
            ie.text_sha1 = s['text_sha1']
            ie.text_size = s['text_size']
        else:
            raise NotImplementedError()
        inv.add(ie)
    return inv
Beispiel #7
0
def read_inventory(inv_file):
    """Read inventory object from rio formatted inventory file"""
    from bzrlib.inventory import Inventory, InventoryFile
    s = read_stanza(inv_file)
    assert s['inventory_version'] == 7
    inv = Inventory()
    for s in read_stanzas(inv_file):
        kind, file_id = s.items[0]
        parent_id = None
        if 'parent_id' in s:
            parent_id = s['parent_id']
        if kind == 'file':
            ie = InventoryFile(file_id, s['name'], parent_id)
            ie.text_sha1 = s['text_sha1']
            ie.text_size = s['text_size']
        else:
            raise NotImplementedError()
        inv.add(ie)
    return inv
    def make_one_file_inventory(self, repo, revision, parents,
                                inv_revision=None, root_revision=None,
                                file_contents=None, make_file_version=True):
        """Make an inventory containing a version of a file with ID 'a-file'.

        The file's ID will be 'a-file', and its filename will be 'a file name',
        stored at the tree root.

        :param repo: a repository to add the new file version to.
        :param revision: the revision ID of the new inventory.
        :param parents: the parents for this revision of 'a-file'.
        :param inv_revision: if not None, the revision ID to store in the
            inventory entry.  Otherwise, this defaults to revision.
        :param root_revision: if not None, the inventory's root.revision will
            be set to this.
        :param file_contents: if not None, the contents of this file version.
            Otherwise a unique default (based on revision ID) will be
            generated.
        """
        inv = Inventory(revision_id=revision)
        if root_revision is not None:
            inv.root.revision = root_revision
        file_id = 'a-file-id'
        entry = InventoryFile(file_id, 'a file name', 'TREE_ROOT')
        if inv_revision is not None:
            entry.revision = inv_revision
        else:
            entry.revision = revision
        entry.text_size = 0
        if file_contents is None:
            file_contents = '%sline\n' % entry.revision
        entry.text_sha1 = osutils.sha_string(file_contents)
        inv.add(entry)
        if make_file_version:
            repo.texts.add_lines((file_id, revision),
                [(file_id, parent) for parent in parents], [file_contents])
        return inv
Beispiel #9
0
    def test_describe_change(self):
        # we need to test the following change combinations:
        # rename
        # reparent
        # modify
        # gone
        # added
        # renamed/reparented and modified
        # change kind (perhaps can't be done yet?)
        # also, merged in combination with all of these?
        old_a = InventoryFile('a-id', 'a_file', ROOT_ID)
        old_a.text_sha1 = '123132'
        old_a.text_size = 0
        new_a = InventoryFile('a-id', 'a_file', ROOT_ID)
        new_a.text_sha1 = '123132'
        new_a.text_size = 0

        self.assertChangeDescription('unchanged', old_a, new_a)

        new_a.text_size = 10
        new_a.text_sha1 = 'abcabc'
        self.assertChangeDescription('modified', old_a, new_a)

        self.assertChangeDescription('added', None, new_a)
        self.assertChangeDescription('removed', old_a, None)
        # perhaps a bit questionable but seems like the most reasonable thing...
        self.assertChangeDescription('unchanged', None, None)

        # in this case it's both renamed and modified; show a rename and 
        # modification:
        new_a.name = 'newfilename'
        self.assertChangeDescription('modified and renamed', old_a, new_a)

        # reparenting is 'renaming'
        new_a.name = old_a.name
        new_a.parent_id = 'somedir-id'
        self.assertChangeDescription('modified and renamed', old_a, new_a)

        # reset the content values so its not modified
        new_a.text_size = old_a.text_size
        new_a.text_sha1 = old_a.text_sha1
        new_a.name = old_a.name

        new_a.name = 'newfilename'
        self.assertChangeDescription('renamed', old_a, new_a)

        # reparenting is 'renaming'
        new_a.name = old_a.name
        new_a.parent_id = 'somedir-id'
        self.assertChangeDescription('renamed', old_a, new_a)
Beispiel #10
0
 def add_file(self, inv, rev_id, file_id, parent_id, name, sha, size):
     new_file = InventoryFile(file_id, name, parent_id)
     new_file.text_sha1 = sha
     new_file.text_size = size
     self.add_entry(inv, rev_id, new_file)
 def add_file(self, inv, rev_id, file_id, parent_id, name, sha, size):
     new_file = InventoryFile(file_id, name, parent_id)
     new_file.text_sha1 = sha
     new_file.text_size = size
     self.add_entry(inv, rev_id, new_file)