当前位置: 首页>>代码示例>>Python>>正文


Python Commit.diff方法代码示例

本文整理汇总了Python中reviewboard.scmtools.core.Commit.diff方法的典型用法代码示例。如果您正苦于以下问题:Python Commit.diff方法的具体用法?Python Commit.diff怎么用?Python Commit.diff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reviewboard.scmtools.core.Commit的用法示例。


在下文中一共展示了Commit.diff方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_change

# 需要导入模块: from reviewboard.scmtools.core import Commit [as 别名]
# 或者: from reviewboard.scmtools.core.Commit import diff [as 别名]
    def get_change(self, revision, cache_key):
        """Get an individual change.

        This returns a tuple with the commit message and the diff contents.
        """
        revision = int(revision)

        commit = cache.get(cache_key)
        if commit:
            message = commit.message
            author_name = commit.author_name
            date = commit.date
            base_revision = commit.parent
        else:
            commits = list(self.ra.iter_log(None, revision, 0, limit=2))
            rev, props = commits[0][1:3]
            message = props[SVN_LOG]
            author_name = props[SVN_AUTHOR]
            date = props[SVN_DATE]

            if len(commits) > 1:
                base_revision = commits[1][1]
            else:
                base_revision = 0

        out, err = self.client.diff(base_revision, revision, self.repopath,
                                    self.repopath, diffopts=DIFF_UNIFIED)

        commit = Commit(author_name, six.text_type(revision), date,
                        message, six.text_type(base_revision))
        commit.diff = out.read()
        return commit
开发者ID:aaronmartin0303,项目名称:reviewboard,代码行数:34,代码来源:subvertpy.py

示例2: get_change

# 需要导入模块: from reviewboard.scmtools.core import Commit [as 别名]
# 或者: from reviewboard.scmtools.core.Commit import diff [as 别名]
    def get_change(self, revision):
        """Get an individual change.

        This returns a Commit object containing the details of the commit.
        """
        revision = int(revision)

        commits = self.client.get_log('/', start=revision, limit=2)

        commit = commits[0]
        message = commit.get('message', b'').decode('utf-8', 'replace')
        author_name = commit.get('author', b'').decode('utf-8', 'replace')
        date = commit['date'].isoformat()

        if len(commits) > 1:
            base_revision = commits[1]['revision']
        else:
            base_revision = 0

        try:
            enc, diff = convert_to_unicode(
                self.client.diff(base_revision, revision),
                self.repository.get_encoding_list())
        except Exception as e:
            raise self.normalize_error(e)

        commit = Commit(author_name, six.text_type(revision), date,
                        message, six.text_type(base_revision))
        commit.diff = diff

        return commit
开发者ID:Anastasiya2307,项目名称:reviewboard,代码行数:33,代码来源:__init__.py

示例3: get_change

# 需要导入模块: from reviewboard.scmtools.core import Commit [as 别名]
# 或者: from reviewboard.scmtools.core.Commit import diff [as 别名]
        def get_change(repository, commit_to_get):
            commit = Commit(
                message='* This is a summary\n\n* This is a description.')
            diff_filename = os.path.join(self.testdata_dir, 'git_readme.diff')

            with open(diff_filename, 'r') as f:
                commit.diff = f.read()

            return commit
开发者ID:davidt,项目名称:reviewboard,代码行数:11,代码来源:test_review_request_draft.py

示例4: get_change

# 需要导入模块: from reviewboard.scmtools.core import Commit [as 别名]
# 或者: from reviewboard.scmtools.core.Commit import diff [as 别名]
    def get_change(self, revision):
        """Get an individual change.

        This returns a tuple with the commit message and the diff contents.
        """
        cache_key = self.repository.get_commit_cache_key(revision)

        revision = int(revision)
        head_revision = Revision(opt_revision_kind.number, revision)

        commit = cache.get(cache_key)
        if commit:
            message = commit.message
            author_name = commit.author_name
            date = commit.date
            base_revision = Revision(opt_revision_kind.number, commit.parent)
        else:
            commits = self.client.log(
                self.repopath,
                revision_start=head_revision,
                limit=2)
            commit = commits[0]
            message = commit['message']
            author_name = commit['author']
            date = datetime.datetime.utcfromtimestamp(commit['date']).\
                isoformat()

            try:
                commit = commits[1]
                base_revision = commit['revision']
            except IndexError:
                base_revision = Revision(opt_revision_kind.number, 0)

        tmpdir = mkdtemp(prefix='reviewboard-svn.')

        diff = self.client.diff(
            tmpdir,
            self.repopath,
            revision1=base_revision,
            revision2=head_revision,
            diff_options=['-u'])

        rmtree(tmpdir)

        commit = Commit(author_name, six.text_type(head_revision.number), date,
                        message, six.text_type(base_revision.number))
        commit.diff = diff
        return commit
开发者ID:EricSchles,项目名称:reviewboard,代码行数:50,代码来源:svn.py

示例5: get_change

# 需要导入模块: from reviewboard.scmtools.core import Commit [as 别名]
# 或者: from reviewboard.scmtools.core.Commit import diff [as 别名]
    def get_change(self, repository, revision):
        repo_api_url = self._get_repo_api_url(repository)

        # Step 1: fetch the commit itself that we want to review, to get
        # the parent SHA and the commit message. Hopefully this information
        # is still in cache so we don't have to fetch it again.
        commit = cache.get(repository.get_commit_cache_key(revision))
        if commit:
            author_name = commit.author_name
            date = commit.date
            parent_revision = commit.parent
            message = commit.message
        else:
            url = self._build_api_url(repo_api_url, "commits")
            url += "&sha=%s" % revision

            commit = self._api_get(url)[0]

            author_name = commit["commit"]["author"]["name"]
            date = (commit["commit"]["committer"]["date"],)
            parent_revision = commit["parents"][0]["sha"]
            message = commit["commit"]["message"]

        # Step 2: fetch the "compare two commits" API to get the diff.
        url = self._build_api_url(repo_api_url, "compare/%s...%s" % (parent_revision, revision))
        comparison = self._api_get(url)

        tree_sha = comparison["base_commit"]["commit"]["tree"]["sha"]
        files = comparison["files"]

        # Step 3: fetch the tree for the original commit, so that we can get
        # full blob SHAs for each of the files in the diff.
        url = self._build_api_url(repo_api_url, "git/trees/%s" % tree_sha)
        url += "&recursive=1"
        tree = self._api_get(url)

        file_shas = {}
        for file in tree["tree"]:
            file_shas[file["path"]] = file["sha"]

        diff = []

        for file in files:
            filename = file["filename"]
            status = file["status"]
            patch = file["patch"]

            diff.append("diff --git a/%s b/%s" % (filename, filename))

            if status == "modified":
                old_sha = file_shas[filename]
                new_sha = file["sha"]
                diff.append("index %s..%s 100644" % (old_sha, new_sha))
                diff.append("--- a/%s" % filename)
                diff.append("+++ b/%s" % filename)
            elif status == "added":
                new_sha = file["sha"]

                diff.append("new file mode 100644")
                diff.append("index %s..%s" % ("0" * 40, new_sha))
                diff.append("--- /dev/null")
                diff.append("+++ b/%s" % filename)
            elif status == "removed":
                old_sha = file_shas[filename]

                diff.append("deleted file mode 100644")
                diff.append("index %s..%s" % (old_sha, "0" * 40))
                diff.append("--- a/%s" % filename)
                diff.append("+++ /dev/null")

            diff.append(patch)

        diff = "\n".join(diff)

        # Make sure there's a trailing newline
        if not diff.endswith("\n"):
            diff += "\n"

        commit = Commit(author_name, revision, date, message, parent_revision)
        commit.diff = diff
        return commit
开发者ID:prodigeni,项目名称:reviewboard,代码行数:83,代码来源:github.py

示例6: get_change

# 需要导入模块: from reviewboard.scmtools.core import Commit [as 别名]
# 或者: from reviewboard.scmtools.core.Commit import diff [as 别名]
    def get_change(self, repository, revision):
        # Step 1: fetch the commit itself that we want to review, to get
        # the parent SHA and the commit message. Hopefully this information
        # is still in cache so we don't have to fetch it again.
        commit = cache.get(repository.get_commit_cache_key(revision))
        if commit:
            author_name = commit.author_name
            date = commit.date
            parent_revision = commit.parent
            message = commit.message
        else:
            url = self._build_api_url(repository, 'commits')
            url += '&sha=%s' % revision

            commit = self._api_get(url)[0]

            author_name = commit['commit']['author']['name']
            date = commit['commit']['committer']['date'],
            parent_revision = commit['parents'][0]['sha']
            message = commit['commit']['message']

        # Step 2: fetch the "compare two commits" API to get the diff.
        url = self._build_api_url(
            repository, 'compare/%s...%s' % (parent_revision, revision))
        comparison = self._api_get(url)

        tree_sha = comparison['base_commit']['commit']['tree']['sha']
        files = comparison['files']

        # Step 3: fetch the tree for the original commit, so that we can get
        # full blob SHAs for each of the files in the diff.
        url = self._build_api_url(repository, 'git/trees/%s' % tree_sha)
        url += '&recursive=1'
        tree = self._api_get(url)

        file_shas = {}
        for file in tree['tree']:
            file_shas[file['path']] = file['sha']

        diff = []

        for file in files:
            filename = file['filename']
            status = file['status']
            patch = file['patch']

            diff.append('diff --git a/%s b/%s' % (filename, filename))

            if status == 'modified':
                old_sha = file_shas[filename]
                new_sha = file['sha']
                diff.append('index %s..%s 100644' % (old_sha, new_sha))
                diff.append('--- a/%s' % filename)
                diff.append('+++ b/%s' % filename)
            elif status == 'added':
                new_sha = file['sha']

                diff.append('new file mode 100644')
                diff.append('index %s..%s' % ('0' * 40, new_sha))
                diff.append('--- /dev/null')
                diff.append('+++ b/%s' % filename)
            elif status == 'removed':
                old_sha = file_shas[filename]

                diff.append('deleted file mode 100644')
                diff.append('index %s..%s' % (old_sha, '0' * 40))
                diff.append('--- a/%s' % filename)
                diff.append('+++ /dev/null')

            diff.append(patch)

        diff = '\n'.join(diff)

        # Make sure there's a trailing newline
        if not diff.endswith('\n'):
            diff += '\n'

        commit = Commit(author_name, revision, date, message, parent_revision)
        commit.diff = diff
        return commit
开发者ID:is00hcw,项目名称:reviewboard,代码行数:82,代码来源:github.py


注:本文中的reviewboard.scmtools.core.Commit.diff方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。