~edwargix/git.sr.ht

d8983d3b6741708d6a021b76db233f8462296cb5 — Drew DeVault 4 years ago c349832
summary: use topological commit sort
1 files changed, 8 insertions(+), 10 deletions(-)

M gitsrht/blueprints/repo.py
M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +8 -10
@@ 62,15 62,13 @@ def render_empty_repo(owner, repo):
    return render_template("empty-repo.html", owner=owner, repo=repo,
            clone_urls=urls)

def get_last_3_commits(commit):
    commits = [commit]
    for parent in commit.parents:
        commits.append(parent)
        for grandparent in parent.parents:
            commits.append(grandparent)

    commits = sorted(commits, key=lambda c: commit_time(c), reverse=True)
    return commits[:3]
def get_last_3_commits(git_repo, commit):
    commits = list()
    for c in git_repo.walk(commit.id, pygit2.GIT_SORT_TOPOLOGICAL):
        commits.append(c)
        if len(commits) >= 3:
            break
    return commits

@repo.route("/<owner>/<repo>")
def summary(owner, repo):


@@ 82,7 80,7 @@ def summary(owner, repo):

        default_branch = git_repo.default_branch()
        tip = git_repo.get(default_branch.target)
        commits = get_last_3_commits(tip)
        commits = get_last_3_commits(git_repo, tip)
        link_prefix = url_for(
            'repo.tree', owner=repo.owner, repo=repo.name,
            ref=f"{default_branch.name}/")  # Trailing slash needed