Пример #1
0
 def mktree(self, odb, entries):
     """create a tree from the given tree entries and safe it to the database"""
     sio = StringIO()
     tree_to_stream(entries, sio.write)
     sio.seek(0)
     istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))
     return istream.binsha
Пример #2
0
def write_tree_from_cache(entries: List[IndexEntry],
                          odb: 'GitCmdObjectDB',
                          sl: slice,
                          si: int = 0) -> Tuple[bytes, List['TreeCacheTup']]:
    """Create a tree from the given sorted list of entries and put the respective
    trees into the given object database

    :param entries: **sorted** list of IndexEntries
    :param odb: object database to store the trees in
    :param si: start index at which we should start creating subtrees
    :param sl: slice indicating the range we should process on the entries list
    :return: tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of
        tree entries being a tuple of hexsha, mode, name"""
    tree_items: List['TreeCacheTup'] = []

    ci = sl.start
    end = sl.stop
    while ci < end:
        entry = entries[ci]
        if entry.stage != 0:
            raise UnmergedEntriesError(entry)
        # END abort on unmerged
        ci += 1
        rbound = entry.path.find('/', si)
        if rbound == -1:
            # its not a tree
            tree_items.append((entry.binsha, entry.mode, entry.path[si:]))
        else:
            # find common base range
            base = entry.path[si:rbound]
            xi = ci
            while xi < end:
                oentry = entries[xi]
                orbound = oentry.path.find('/', si)
                if orbound == -1 or oentry.path[si:orbound] != base:
                    break
                # END abort on base mismatch
                xi += 1
            # END find common base

            # enter recursion
            # ci - 1 as we want to count our current item as well
            sha, _tree_entry_list = write_tree_from_cache(
                entries, odb, slice(ci - 1, xi), rbound + 1)
            tree_items.append((sha, S_IFDIR, base))

            # skip ahead
            ci = xi
        # END handle bounds
    # END for each entry

    # finally create the tree
    sio = BytesIO()
    tree_to_stream(
        tree_items,
        sio.write)  # writes to stream as bytes, but doesnt change tree_items
    sio.seek(0)

    istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))
    return (istream.binsha, tree_items)
Пример #3
0
 def mktree(self, odb, entries):
     """create a tree from the given tree entries and safe it to the database"""
     sio = BytesIO()
     tree_to_stream(entries, sio.write)
     sio.seek(0)
     istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))
     return istream.binsha
Пример #4
0
def write_tree_from_cache(entries, odb, sl, si=0):
    """Create a tree from the given sorted list of entries and put the respective
    trees into the given object database

    :param entries: **sorted** list of IndexEntries
    :param odb: object database to store the trees in
    :param si: start index at which we should start creating subtrees
    :param sl: slice indicating the range we should process on the entries list
    :return: tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of
        tree entries being a tuple of hexsha, mode, name"""
    tree_items = list()
    tree_items_append = tree_items.append
    ci = sl.start
    end = sl.stop
    while ci < end:
        entry = entries[ci]
        if entry.stage != 0:
            raise UnmergedEntriesError(entry)
        # END abort on unmerged
        ci += 1
        rbound = entry.path.find('/', si)
        if rbound == -1:
            # its not a tree
            tree_items_append((entry.binsha, entry.mode, entry.path[si:]))
        else:
            # find common base range
            base = entry.path[si:rbound]
            xi = ci
            while xi < end:
                oentry = entries[xi]
                orbound = oentry.path.find('/', si)
                if orbound == -1 or oentry.path[si:orbound] != base:
                    break
                # END abort on base mismatch
                xi += 1
            # END find common base

            # enter recursion
            # ci - 1 as we want to count our current item as well
            sha, tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi),
                                                         rbound + 1)
            tree_items_append((sha, S_IFDIR, base))

            # skip ahead
            ci = xi
        # END handle bounds
    # END for each entry

    # finally create the tree
    sio = StringIO()
    tree_to_stream(tree_items, sio.write)
    sio.seek(0)

    istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))
    return (istream.binsha, tree_items)
Пример #5
0
 def _store_tree (self, repo, entities):
     """return tree's istream
         """
     assert repo
     sio = StringIO ()
     assert isinstance (entities, list)
     # we need to make sure the entities are sorted by name, which is required by git
     entities.sort (lambda a,b: cmp (a[2], b[2]))
     tree_to_stream (entities, sio.write)
     sio.seek (0)
     t_stream = IStream ("tree", len(sio.getvalue ()), sio)
     repo.odb.store (t_stream)
     sio.close ()
     return t_stream