コード例 #1
0
ファイル: git.py プロジェクト: blueshark0811/Issue-Tracking
 def get_commit_by_id(self, commit_id):
     commit = self._get_commit(commit_id)
     files = self._diff_files(commit.id, commit.parents[0])
     return Commit(
         commit.id, commit.committer,
         datetime.fromtimestamp(commit.commit_time), commit.message, files,
         generate_unified_diff(self, files, commit.parents[0], commit.id))
コード例 #2
0
    def _rev_to_commit(self, rev):
        # TODO: this doesn't yet handle the case of multiple parent revisions
        current = self._branch.repository.revision_tree(rev.revision_id)
        if len(rev.parent_ids):
            prev = self._branch.repository.revision_tree(rev.parent_ids[0])
        else:
            prev = self._branch.repository.revision_tree('null:')

        delta = current.changes_from(prev)
        files = [
            f[0] for f in delta.added + delta.removed + delta.renamed +
            delta.kind_changed + delta.modified
        ]

        diff_file = StringIO.StringIO()

        diff_tree = diff.DiffTree(prev, current, diff_file)

        self._branch.lock_read()
        diff_tree.show_diff('')
        self._branch.unlock()

        diff_out = diff_file.getvalue()
        diff_file.close()

        return Commit(self._get_commit_id(rev.revision_id), rev.committer,
                      datetime.fromtimestamp(rev.timestamp), rev.message,
                      files, diff_out)
コード例 #3
0
ファイル: hg.py プロジェクト: blueshark0811/Issue-Tracking
    def _ctx_to_commit(self, ctx):
        diff = generate_unified_diff(self, ctx.files(),
                                     ctx.parents()[0].rev(), ctx.rev())

        return Commit(ctx.rev(), ctx.user(),
                      datetime.fromtimestamp(ctx.date()[0]), ctx.description(),
                      ctx.files(), diff)
コード例 #4
0
 def get_commit_by_id(self, commit_id):
     commit = self._get_commit(commit_id)
     parent = commit.parents[0] if len(commit.parents) else 'NULL'
     files = self._diff_files(commit.id, parent)
     return Commit(
         commit.id, commit.committer,
         datetime.fromtimestamp(commit.commit_time), commit.message, files,
         lambda: generate_unified_diff(self, files, parent, commit.id))
コード例 #5
0
    def _log_to_commit(self, log):
        info = self._repo.info(self.path)
        base, url = info['repos'], info['url']
        at = url[len(base):]
        commit_files = [
            cp_dict['path'][len(at) + 1:] for cp_dict in log['changed_paths']
        ]

        def get_diff():
            # Here we go back through history, 5 commits at a time, searching
            # for the first point at which there is a change along our path.
            oldrev_log = None
            i = 1
            # the start of our search is always at the previous commit
            while oldrev_log is None:
                i += 5
                diff_rev_start = pysvn.Revision(
                    pysvn.opt_revision_kind.number,
                    log['revision'].number - (i - 5))
                diff_rev_end = pysvn.Revision(pysvn.opt_revision_kind.number,
                                              log['revision'].number - i)
                log_list = self._repo.log(self.path,
                                          revision_start=diff_rev_start,
                                          revision_end=diff_rev_end,
                                          discover_changed_paths=True)
                try:
                    oldrev_log = log_list.pop(0)
                except IndexError:
                    # If we've gone back through the entirety of history and
                    # still not found anything, bail out, this commit doesn't
                    # exist along our path (or perhaps at all)
                    if i >= log['revision'].number:
                        raise CommitDoesNotExist

            diff = self._repo.diff(
                NamedTemporaryFile().name,
                url_or_path=self.path,
                revision1=oldrev_log['revision'],
                revision2=log['revision'],
            )
            return diff

        return Commit(log['revision'].number, log['author'],
                      datetime.fromtimestamp(log['date']), log['message'],
                      commit_files, get_diff)