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


Python Repository.iter_commits方法代码示例

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


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

示例1: Analyzer

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import iter_commits [as 别名]
class Analyzer(object):

    def __init__(self, repo_obj, cache='/tmp', languages=None, branch='master'):

        # local import to avoid a circular import
        from analysis.models import Branch

        self.repo_obj = repo_obj

        if languages is None:
            languages = ["python"]

        self.languages = languages
        self.branch = branch

        repo_url = self.repo_obj.url

        repo_dir = os.path.join(cache, quote(repo_url))
        try:
            self.repo = Repo(repo_dir)
            origin = self.repo.remotes.origin

            try:
                origin.fetch('all')
                origin.pull(self.branch)
            except AssertionError as e:
                # triggers when trying to pull on a repo that is up to date already
                print e
                print "FAILED TO PULL"
                pass

        except GitError:
            self.repo = Repo.clone_from(repo_url, repo_dir)

        branch_obj = Branch.objects.filter(repository=repo_obj, name=self.branch)[:1]
        if not branch_obj:
            branch_obj = Branch(repository=repo_obj, name=self.branch)
            # TODO branch last analyzed
            branch_obj.save()
        else:
            branch_obj = branch_obj[0]

        self.branch_obj = branch_obj


    def run(self, period=60*60*24*30):
        self.do_time_scan(period)

    def do_time_scan(self, period=60*60*24*30):

        # local import to avoid a circular import
        from analysis.models import Author, Commit

        max_age = int(time.time()) - period

        commits_to_analyze = []
        for commit in self.repo.iter_commits('master'):
            if commit.authored_date > max_age:
                commits_to_analyze.insert(0, commit)
            else:
                break
       
        commits_seen = Commit.objects.filter(commit_hash__in=commits_to_analyze).only('commit_hash')

        commits_seen_set = set([commit.commit_hash for commit in commits_seen])

        full = True
        parent = None
        for commit in commits_to_analyze:
            if commit.hexsha not in commits_seen_set:
                author = commit.author
                author_email = author.email
                author_obj = Author.objects.filter(email=author_email)[:1]
                if author_obj:
                  author_obj = author_obj[0]
                else:
                  # TODO Tie author to user
                  author_obj = Author(email=author_email, name=author.name)
                  author_obj.save()
                commit_obj = Commit(commit_hash=commit.hexsha, commit_hash_short=commit.hexsha[:7],
                                    branch=self.branch_obj, authored_date=commit.authored_date, author=author_obj)
                commit_obj.save()
                if parent:
                    commit_obj.files.add(*[file for file in parent.files.all()])
                self.analyze_commit(commit, commit_obj, full)
                commit_obj.save()
                parent = commit_obj
            full = False 

    def analyze_commit(self, commit, commit_obj, full=False):

        from analysis.models import FileAnalysis, PyLintAnalysis, \
            PyClassComplexityAnalysis, PyFunctionComplexityAnalysis

        self.repo.git.checkout(commit.hexsha)
        
        file_analysis_entries = {}

        lint_paths = []

#.........这里部分代码省略.........
开发者ID:brianbrunner,项目名称:bitcaliber,代码行数:103,代码来源:analyzer.py


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