Ejemplo n.º 1
0
    def __tree(self, metadata):
        if self.prev is None:

            def pf(c):
                return patch_file(self.__repo, c.data)
        else:
            prev_top_tree = self.prev.commit.data.tree
            perm, prev_patch_tree = prev_top_tree.data.entries['patches']
            # Map from Commit object to patch_file() results taken
            # from the previous log entry.
            c2b = dict((self.prev.patches[pn], pf)
                       for pn, pf in prev_patch_tree.data.entries.items())

            def pf(c):
                r = c2b.get(c, None)
                if not r:
                    r = patch_file(self.__repo, c.data)
                return r

        patches = dict((pn, pf(c)) for pn, c in self.patches.items())
        return self.__repo.commit(
            git.TreeData({
                'meta':
                self.__repo.commit(git.BlobData(metadata.encode('utf-8'))),
                'patches':
                self.__repo.commit(git.TreeData(patches))
            }))
Ejemplo n.º 2
0
def patch_file(repo, cd):
    metadata = '\n'.join([
        'Bottom: %s' % cd.parent.data.tree.sha1,
        'Top:    %s' % cd.tree.sha1,
        'Author: %s' % cd.author.name_email,
        'Date:   %s' % cd.author.date,
        '',
        cd.message,
        '',
        '---',
        '',
    ]).encode('utf-8')
    diff = repo.diff_tree(cd.parent.data.tree, cd.tree, ['-M']).strip()
    return repo.commit(git.BlobData(metadata + diff + b'\n'))