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


Python Repository.walk方法代码示例

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


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

示例1: extract_commits

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def extract_commits(repos_root, output_path):
    # Uncomment code to generate a separate file for each commit.

    try:
        os.makedirs(output_path)
    except FileExistsError as ex:
        pass

    exec_dir = os.getcwd()

    for git_repo in get_immediate_subdirectories(repos_root):
        os.chdir(git_repo)
        repo = Repository(os.path.join(git_repo, git_folder))
        root = etree.Element("commits")

        repo_name = os.path.basename(os.path.normpath(git_repo))

        print("\n> project: " + repo_name + " extraction started")

        for commit in repo.walk(repo.head.target):
            stats = get_commit_stats(commit.id)
            commit_xml = commit_to_xml(commit, stats)
            root.append(commit_xml)

            # print(".", end=" ")
            print("> project: " + repo_name + ", commit " + str(commit.id) + " processed")

        output_xml = xml_to_string(root)

        os.chdir(exec_dir)

        with open(os.path.join(output_path, repo_name + "_" + output_commit_file), "w") as file:
            file.write(output_xml)

        print("\n> project: " + repo_name + " extraction finished")
开发者ID:megakevin,项目名称:research-assistantship-rit,代码行数:37,代码来源:get_commits.py

示例2: RepositoryProcessor

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

    def __init__(self, repository_path):
        self.repo = GitRepository(repository_path + '/.git')
        self.users = {}

    def get_bages_processors_for_user(self, email):
        if email in self.users:
            return self.users[email]
        self.users[email] = []
        for badge_class in initialize_badge_classes():
            logging.info(u'Initializing badge class [%s] for user [%s]' % (str(badge_class), email))
            self.users[email].append(badge_class(email))
        return self.users[email]

    def process(self):
        # returns the json of the collaborators
        for commit in [c for c in self.repo.walk(self.repo.head.oid, GIT_SORT_TIME)][::-1]:
            for badge in self.get_bages_processors_for_user(commit.author.email):
                badge.process_commit(commit, datetime.fromtimestamp(commit.commit_time))
        result = []
        for user_email, badges in self.users.items():
            user = {"email": user_email, "badges": []}
            result.append(user)
            for badge in badges:
                if isinstance(badge, Badge):
                    if badge.award_this():
                        user['badges'].append({"badge_slug": badge.slug})
                else:
                    user.update(badge.update_data())
            user.update(count_modifications_by_user(user_email, self.repo.path))
            print user
        return result
开发者ID:timehome,项目名称:djangodash2012,代码行数:35,代码来源:processor.py

示例3: git_is_clean

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def git_is_clean(srcdir, project):
    repo = Repository(os.path.join(srcdir, project.workspace_path, ".git"))
    for _, b in iteritems(repo.status()):
        if b != GIT_STATUS_IGNORED and b != GIT_STATUS_CURRENT:
            return False, "has uncommitted changes"
    if repo.head_is_detached:
        return False, "has detached HEAD"
    origin = get_origin(repo, project)
    if not origin:
        return False, "has no upstream remote"
    remote_refs = []
    local_refs = {}
    for refname in repo.listall_references():
        if refname.startswith("refs/remotes/%s/" % origin.name):
            ref = repo.lookup_reference(refname)
            if ref.type == GIT_REF_OID:
                remote_refs.append(ref.target)
        elif not refname.startswith("refs/remotes/"):
            ref = repo.lookup_reference(refname)
            if ref.type == GIT_REF_OID:
                local_refs[ref.peel().id] = refname
    if not remote_refs:
        return False, "has no upstream remote branches"
    if not local_refs:
        return False, "has no local branches"
    if not repo.lookup_branch("%s/%s" % (origin.name, project.master_branch), GIT_BRANCH_REMOTE):
        return False, "has no upstream master branch"
    for remote_ref in remote_refs:
        for commit in repo.walk(remote_ref):
            if commit.id in local_refs:
                del local_refs[commit.id]
    if local_refs:
        return False, "has local commits: %s" % ", ".join(["'%s'" % name for _, name in iteritems(local_refs)])
    return True, ""
开发者ID:fkie,项目名称:rosrepo,代码行数:36,代码来源:cmd_include_exclude.py

示例4: get_commit_activity

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
    def get_commit_activity(self, project):
        from datetime import date, timedelta
        from pygit2 import Repository
        from pygit2 import GIT_SORT_TIME
        repo = Repository(project.gitrepo)

        weeks = self.get_weeks()
        for commit in repo.walk(repo.head.oid, GIT_SORT_TIME):
            commit_time = date.fromtimestamp(commit.commit_time)
            commit_week = commit_time - timedelta(days=commit_time.weekday())

            if commit_week not in weeks:
                continue

            weeks[commit_week]['mine'] += 1

        counts = []
        max = 0
        for k in sorted(weeks.iterkeys()):
            counts.append({
                "week":     k.isoformat(),
                "mine":     weeks[k]['mine'],
                "others":   weeks[k]['others'],
            })
        return counts
开发者ID:alexwright,项目名称:cms-projectinfo,代码行数:27,代码来源:cms_plugins.py

示例5: get_bug_commit_ratio_per_file

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def get_bug_commit_ratio_per_file(git_folder = ".git/", output_file):
    result = []
    exec_dir = os.getcwd()
    repo = Repository(os.path.join(git_repo, git_folder))

    os.chdir(git_repo)

    for commit in repo.walk(repo.head.target):
        touched_files = get_touched_files(commit)

        for file in touched_files:
            file_data = [f for f in result if f['file_name'] == file]

            if file_data:
                file_data = file_data[0]
                file_data['commit_num'] += 1
                if bug_related:
                    file_data['bug_commit_num'] += 1
            else:
                result.append({'file_name': file,
                               'commit_num': 1,
                               'bug_commit_num': 1 if bug_related else 0})

    os.chdir(exec_dir)

    for entry in result:
        entry['bug_commit_ratio'] = entry['bug_commit_num'] / entry['commit_num']

    with open(output_file, "w", newline='') as output:
        writer = csv.DictWriter(output, csv_header)
        writer.writeheader()
        writer.writerows(result)
开发者ID:an1ket,项目名称:technical-debt-capstone,代码行数:34,代码来源:get_blame_test.py

示例6: getHist

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def getHist(repo):
	base = Repository(repo)
	base.checkout('HEAD')
	history = []
	for commit in base.walk(base.head.target, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE):
		history.append(commit)
	
	return history
开发者ID:dtg3,项目名称:sevo-git-research,代码行数:10,代码来源:gitreap.py

示例7: get_and_update_repo_cache

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def get_and_update_repo_cache(repo_path):
    cache_filename = '%s-stats.cache' % repo_path
    if os.path.exists(cache_filename):
        with open(cache_filename) as f:
            data = load(f)
    else:
        data = {
            'author_to_month_to_additions': defaultdict(defaultdict_int),
            'author_to_month_to_deletions': defaultdict(defaultdict_int),
            'author_to_month_to_commits': defaultdict(defaultdict_int),
            'day_to_count': defaultdict(defaultdict_int),
            'latest_sha': None,
        }

    repo = Repository(repo_path)

    count = 0
    for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
        count += 1
        if commit.type == GIT_OBJ_COMMIT:
            if data['latest_sha'] == commit.hex:
                break
        
            if not commit.message.lower().startswith('merge'):
                try:
                    d = repo.diff('%s^' % commit.hex, commit)
                except KeyError:
                    # First commit!
                    break
                patches = list(d)
                additions = sum([p.additions for p in patches])
                deletions = sum([p.deletions for p in patches])

                author = author_aliases.get(commit.author.email, commit.author.email)

                day = date.fromtimestamp(commit.commit_time)
                data['day_to_count']['Lines'][day] += additions
                data['day_to_count']['Lines'][day] -= deletions

                if additions > 1000 and deletions < 5 and commit.hex not in whitelist_commits:
                    if commit.hex not in blacklist_commits:
                        print 'WARNING: ignored %s looks like an embedding of a lib (message: %s)' % (commit.hex, commit.message)
                    continue
                if (additions > 3000 or deletions > 3000) and commit.hex not in whitelist_commits:
                    if commit.hex not in blacklist_commits and additions != deletions:  # Guess that if additions == deletions it's a big rename of files
                        print 'WARNING: ignored %s because it is bigger than 3k lines. Put this commit in the whitelist or the blacklist (message: %s)' % (commit.hex, commit.message)
                    continue
                month = date(day.year, day.month, 1)
                data['author_to_month_to_additions'][author][month] += additions
                data['author_to_month_to_deletions'][author][month] += deletions
                data['author_to_month_to_commits'][author][month] += 1
                if data['latest_sha'] is None:
                    data['latest_sha'] = commit.hex

    with open(cache_filename, 'w') as f:
        dump(data, f)

    return data
开发者ID:ismaproco,项目名称:git-stats2,代码行数:60,代码来源:git_stats2.py

示例8: gets

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
    def gets(cls, path, max_count=100, order=GIT_SORT_TIME):
        """gets commits from a git repository.

        :param path: The normalized path to the git repository.
        :param max_count: max count of commits.
        :param order: order commits list."""
        repo = Repository(path)
        return [cls(c.hex, [p.hex for p in c.parents])
                for c in islice(repo.walk(repo.head.target, order),
                                max_count)]
开发者ID:HiWong,项目名称:commits-graph,代码行数:12,代码来源:commit.py

示例9: get_churn_per_commit

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def get_churn_per_commit(git_repo, output_file):
    touched_files = []
    exec_dir = os.getcwd()
    repo = Repository(os.path.join(git_repo, git_folder))
    os.chdir(git_repo)

    for commit in repo.walk(repo.head.target):
        touched_files = get_touched_files(commit)

    with open(output_file, "w", newline='') as output:
        writer = csv.DictWriter(output, csv_header)
        writer.writeheader()
        writer.writerows(touched_files)
开发者ID:an1ket,项目名称:technical-debt-capstone,代码行数:15,代码来源:get_blame_test.py

示例10: shift

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def shift(amount, repo_path):
    repo = Repository(repo_path)
    head = repo.lookup_reference('HEAD').resolve()
    adder = partial(add, amount=amount)
    changelog = dict()
    reference = REF_FMT.format(time=time(), pid=getpid())
    for commit in repo.walk(head.oid, GIT_SORT_REVERSE | GIT_SORT_TOPOLOGICAL):
        newmsg, nsubs = ISSUE_RE.subn(adder, commit.message)
        if nsubs != 0 or any(pnt.oid in changelog for pnt in commit.parents):
            parents = [changelog.get(c.oid, c.oid) for c in commit.parents]
            new_oid = repo.create_commit(reference, commit.author,
                    commit.committer, newmsg, commit.tree.oid, parents)
            changelog[commit.oid] = new_oid
    return changelog, reference
开发者ID:dnet,项目名称:registr,代码行数:16,代码来源:shifter.py

示例11: get_commit_churn

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def get_commit_churn(repo_path):
    exec_dir = os.getcwd()
    repo = Repository(os.path.join(repo_path, git_folder))
    os.chdir(repo_path)

    debt_commits = get_debt_commits(repo_path) #commit, commit_ts, fiel_path
    file_churn = []

    for commit in repo.walk(repo.head.target):
        print (commit.id)
        curr_commit_ts = int(str(get_unix_timestamp(str(commit.id))).replace("\n", ""))
        debt_commit_flag = [f for f in debt_commits if f['commit'] == str(commit.id)]
        #print (str(debt_commit_flag))
        is_debt_commit = 0
        if debt_commit_flag:
            is_debt_commit = 1

        touched_files = get_touched_files(commit)
        for strFileChurn in touched_files:
            added_lines, deleted_lines, file_name = strFileChurn.split("\t")

            file_commit_flag = [f for f in debt_commits if f['file_path'] == file_name]
            is_file_debt = 0
            if file_commit_flag:
                file_commit_flag = file_commit_flag[0]
                debt_commit_commit_ts = int(file_commit_flag['commit_ts'])
                
                if curr_commit_ts >= debt_commit_commit_ts:
                    is_file_debt = 1

            try:
                file_churn.append({
                    'commit':str(commit.id),
                    'commit_ts':curr_commit_ts,
                    'file_name':file_name,
                    'added_lines':added_lines,
                    'deleted_lines':deleted_lines,
                    'commit_debt':is_debt_commit,
                    'file_debt':is_file_debt,
                    })
            except (AttributeError):
                continue;

    os.chdir(exec_dir)
    with open(output_file, "w", newline='') as output:
        writer = csv.DictWriter(output, csv_header)
        writer.writeheader()
        writer.writerows(file_churn)
开发者ID:an1ket,项目名称:technical-debt-capstone,代码行数:50,代码来源:get_commit_churn.py

示例12: main

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def main():
    contrib_data_dir = sys.argv[1]
    git_repo = sys.argv[2]
    output_file = sys.argv[3]

    result = []
    exec_dir = os.getcwd()

    for contrib_file in os.listdir(contrib_data_dir):

        release = contrib_file[len(contrib_file_prefix):][:-len(contrib_file_extension)]
        contrib_file = os.path.join(contrib_data_dir, contrib_file)

        top_devs = {}

        with open(contrib_file, newline="") as csv_file:
            for row in csv.DictReader(csv_file):
                top_dev = row['top_single_dev_contribution_knowledge'].split(":")[0]

                if top_dev in top_devs:
                    top_devs[top_dev] += 1
                else:
                    top_devs[top_dev] = 1

        os.chdir(git_repo)
        call(["git", "checkout", "tags/" + release])
        os.chdir(exec_dir)

        for top_dev in top_devs:
            author_commit_count = 0
            commit_count = 0

            repo = Repository(os.path.join(git_repo, git_folder))
            for commit in repo.walk(repo.head.target):
                commit_count += 1
                if commit.author.name == top_dev:
                    author_commit_count += 1

            result.append({'release': release,
                           'release_commits': commit_count,
                           'top_dev': top_dev,
                           'files_owned': top_devs[top_dev],
                           'dev_commits': author_commit_count})

    with open(output_file, 'w', newline='') as output:
        writer = csv.DictWriter(output, csv_header)
        writer.writeheader()
        writer.writerows(result)
开发者ID:megakevin,项目名称:single-authored-code-evolution-analysis,代码行数:50,代码来源:get_top_devs.py

示例13: cross_reference_commits_with_bug_reports

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def cross_reference_commits_with_bug_reports():
    repos_root = sys.argv[1]#"/home/kevin/Desktop/eclipse-platform"#
    bug_reports_file = sys.argv[2]#"/home/kevin/Downloads/eclipse-bugs.csv"#

    with open(bug_reports_file, newline="") as csv_file:
        bug_reports = [{"id": bug["id"],
                        "creation_time": datetime.strptime(bug["creation_time"], bug_date_format),
                        "closed_time": datetime.strptime(bug["closed_time"], bug_date_format)}
                       for bug in csv.DictReader(csv_file)]

    os.makedirs(output_root_path)

    for git_repo in get_immediate_subdirectories(repos_root):
        repo_name = os.path.basename(os.path.normpath(git_repo))
        repo = Repository(os.path.join(git_repo, git_folder))
        bug_related_commits = [commit for commit in repo.walk(repo.head.target) if is_bug_related(commit)]

        root = etree.Element("commits")
        count = 0

        for bug_report in bug_reports:

            # This may actually hurt the detection
            bug_related_commits_within_bug_life = \
                [c for c in bug_related_commits
                 if bug_report['creation_time'] <= datetime.fromtimestamp(c.commit_time) <= bug_report['closed_time']]

            # for commit in bug_related_commits:
            for commit in bug_related_commits_within_bug_life:
                if are_related(commit, bug_report):
                    commit_xml = commit_to_xml(commit)
                    commit_xml.set("related_bug", bug_report["id"])
                    root.append(commit_xml)
                    count += 1

            print("repo: " + repo_name + ", bug: " + bug_report["id"] + " processed")

            # if count > 10:
            #     break

        root.set("count", str(count))
        output_xml = xml_to_string(root)

        with open(os.path.join(output_root_path, repo_name + "_" + output_commit_file), "w") as file:
            file.write(output_xml)
开发者ID:megakevin,项目名称:research-assistantship-rit,代码行数:47,代码来源:cross_ref_commits_bugs.py

示例14: _pygit2_commits

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def _pygit2_commits(commit, repository):
    from pygit2 import Repository, GIT_SORT_TOPOLOGICAL
    g = Repository(repository)

    if '..' in commit:
        tail, head = commit.split('..', 2)
        head = head or 'HEAD'
    else:
        head = commit
        tail = commit + '^'

    walker = g.walk(g.revparse_single(head).oid, GIT_SORT_TOPOLOGICAL)

    try:
        walker.hide(g.revparse_single(tail).oid)
    except KeyError:
        pass

    return walker
开发者ID:inveniosoftware,项目名称:kwalitee,代码行数:21,代码来源:check.py

示例15: main

# 需要导入模块: from pygit2 import Repository [as 别名]
# 或者: from pygit2.Repository import walk [as 别名]
def main():
    package = sys.argv[1]

    repo = Repository('.git')

    stripv = re.compile("v(\d+\.\d+\.\d+.*)")

    checktag = True

    log = """{package} ({version}) unstable; urgency=low

  * {message}

 -- {author_name} <{author_email}>  {time}
"""
    for commit in repo.walk(repo.head.target, GIT_SORT_TOPOLOGICAL):
        if checktag:
            try:
                version = git("describe", "--tags", commit.id).strip()
            except sh.ErrorReturnCode_128:
                version = '0.0.0-0-g%s' % str(commit.id)[0:7]
                checktag = False
        else:
            version = '0.0.0-0-g%s' % str(commit.id)[0:7]

        stripr = stripv.search(version)
        if stripr is not None:
            version = stripr.group(1)
        message = commit.message.encode("ascii", errors="replace").strip()
        messages = ["  %s" % line for line in message.split("\n")]
        messages[0] = messages[0].strip()
        message = "\n".join(messages)
        print log.format(**dict(
            package=package,
            version=version,
            message=message,
            author_name=commit.author.name.encode("ascii", errors="replace"),
            author_email=commit.author.email.encode("ascii", errors="replace"),
            time=datetime.datetime.fromtimestamp(commit.commit_time).strftime("%a, %d %b %Y %H:%M:%S -0000")
        ))
开发者ID:AdamJacobMuller,项目名称:gitlog-to-deblog,代码行数:42,代码来源:gitlog_to_deblog.py


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