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(
            TreeData({
                'meta':
                self.__repo.commit(BlobData(metadata.encode('utf-8'))),
                'patches':
                self.__repo.commit(TreeData(patches)),
            }))
Ejemplo n.º 2
0
 def patch_file(self, 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_str,
     ]).encode('utf-8')
     return self._repo.commit(BlobData(metadata))
Ejemplo n.º 3
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(BlobData(metadata + diff + b'\n'))
Ejemplo n.º 4
0
    def _patch_blob(self, pn, commit):
        if self.prev is not None:
            perm, prev_patch_tree = self.prev.commit.data.tree.data['patches']
            if pn in prev_patch_tree.data and commit == self.prev.patches[pn]:
                return prev_patch_tree.data[pn]

        patch_meta = '\n'.join([
            'Bottom: %s' % commit.data.parent.data.tree.sha1,
            'Top:    %s' % commit.data.tree.sha1,
            'Author: %s' % commit.data.author.name_email,
            'Date:   %s' % commit.data.author.date,
            '',
            commit.data.message_str,
        ])
        return self._repo.commit(BlobData(patch_meta.encode('utf-8')))
Ejemplo n.º 5
0
 def _stack_json_blob(self, repo, prev_state):
     stack_json = dict(
         version=FORMAT_VERSION,
         prev=None if prev_state is None else prev_state.commit.sha1,
         head=self.head.sha1,
         applied=self.applied,
         unapplied=self.unapplied,
         hidden=self.hidden,
         patches={
             pn: dict(oid=patch.sha1)
             for pn, patch in self.patches.items()
         },
     )
     blob = json.dumps(stack_json, indent=2).encode('utf-8')
     return repo.commit(BlobData(blob))
Ejemplo n.º 6
0
 def _metadata_blob(self):
     lines = ['Version: %d' % FORMAT_VERSION]
     lines.append('Previous: %s' %
                  ('None' if self.prev is None else self.prev.commit.sha1))
     lines.append('Head: %s' % self.head.sha1)
     for patch_list, title in [
         (self.applied, 'Applied'),
         (self.unapplied, 'Unapplied'),
         (self.hidden, 'Hidden'),
     ]:
         lines.append('%s:' % title)
         for pn in patch_list:
             lines.append('  %s: %s' % (pn, self.patches[pn].sha1))
     lines.append('')
     metadata_str = '\n'.join(lines)
     return self._repo.commit(BlobData(metadata_str.encode('utf-8')))