From 19fd8f19f2406e3ddb141728dd5dc83ca9639ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Thu, 30 Jul 2020 18:00:10 +0200 Subject: [PATCH] Use the default branch for links --- gitsrht/blueprints/artifacts.py | 5 +++-- gitsrht/blueprints/repo.py | 12 +++++++----- gitsrht/blueprints/stats.py | 3 ++- gitsrht/templates/refs.html | 2 +- gitsrht/templates/repo.html | 12 ++++++++---- 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/gitsrht/blueprints/artifacts.py b/gitsrht/blueprints/artifacts.py index e02d68b..cece6af 100644 --- a/gitsrht/blueprints/artifacts.py +++ b/gitsrht/blueprints/artifacts.py @@ -41,15 +41,16 @@ def ref_upload(owner, repo, ref): valid = Validation(request) f = request.files.get("file") valid.expect(f, "File is required", field="file") + default_branch = git_repo.default_branch() if not valid.ok: return render_template("ref.html", view="refs", owner=owner, repo=repo, git_repo=git_repo, tag=tag, - **valid.kwargs) + default_branch=default_branch, **valid.kwargs) artifact = upload_artifact(valid, repo, target, f, f.filename) if not valid.ok: return render_template("ref.html", view="refs", owner=owner, repo=repo, git_repo=git_repo, tag=tag, - **valid.kwargs) + default_branch=default_branch, **valid.kwargs) db.session.commit() return redirect(url_for("repo.ref", owner=owner.canonical_name, diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index 737e258..248e1a1 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -417,7 +417,8 @@ def commit(owner, repo, ref): return render_template("commit.html", view="log", owner=owner, repo=repo, ref=ref, refs=refs, commit=commit, parent=parent, - diff=diff, diffstat=diffstat, pygit2=pygit2) + diff=diff, diffstat=diffstat, pygit2=pygit2, + default_branch=git_repo.default_branch()) @repo.route("///commit/.patch") def patch(owner, repo, ref): @@ -469,9 +470,9 @@ def refs(owner, repo): git_repo.branches[branch], git_repo.get(git_repo.branches[branch].target) ) for branch in git_repo.branches.local] - default_branch = git_repo.default_branch().name + default_branch = git_repo.default_branch() branches = sorted(branches, - key=lambda b: (b[1].name == default_branch, b[2].commit_time), + key=lambda b: (b[1].name == default_branch.name, b[2].commit_time), reverse=True) results_per_page = 10 @@ -493,7 +494,8 @@ def refs(owner, repo): return render_template("refs.html", view="refs", owner=owner, repo=repo, tags=tags, branches=branches, git_repo=git_repo, isinstance=isinstance, pygit2=pygit2, - page=page + 1, total_pages=total_pages) + page=page + 1, total_pages=total_pages, + default_branch=default_branch) @repo.route("///refs/rss.xml") @@ -540,4 +542,4 @@ def ref(owner, repo, ref): .filter(Artifact.commit == tag.target.hex)).all() return render_template("ref.html", view="refs", owner=owner, repo=repo, git_repo=git_repo, tag=tag, - artifacts=artifacts) + artifacts=artifacts, default_branch=git_repo.default_branch()) diff --git a/gitsrht/blueprints/stats.py b/gitsrht/blueprints/stats.py index 90bef8f..e883048 100644 --- a/gitsrht/blueprints/stats.py +++ b/gitsrht/blueprints/stats.py @@ -38,4 +38,5 @@ def contributors(owner, repo): chart_data = get_contrib_chart_data(contributions) return render_template("contributors.html", view="contributors", - owner=owner, repo=repo, chart_data=chart_data) + owner=owner, repo=repo, chart_data=chart_data, + default_branch=default_branch) diff --git a/gitsrht/templates/refs.html b/gitsrht/templates/refs.html index 8c80d95..dccdea3 100644 --- a/gitsrht/templates/refs.html +++ b/gitsrht/templates/refs.html @@ -95,7 +95,7 @@ owner=repo.owner.canonical_name, repo=repo.name, ref=name)}}" class="btn btn-block {{ "btn-primary" - if branch.name == git_repo.default_branch().name + if branch.name == default_branch.name else "btn-default" }}" >browse {{icon("caret-right")}} diff --git a/gitsrht/templates/repo.html b/gitsrht/templates/repo.html index 7f662b7..c99ee11 100644 --- a/gitsrht/templates/repo.html +++ b/gitsrht/templates/repo.html @@ -6,10 +6,14 @@ {# Man, this is lame #} - +{% if default_branch %} + +{% endif %} {% endblock %} {% block body %}
-- 2.38.4