summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-10-01 15:33:54 -0400
committerDrew DeVault <sir@cmpwn.com>2018-10-01 15:33:54 -0400
commit93b959111dcc90223b3785b22f3089b670f59489 (patch)
treecfb488caa5377750fa840e74b758bea5310f3690
parentfed60c0086354cc844a4f9fcc688cd1fa006eea8 (diff)
Wire up browse and patch buttons
-rw-r--r--gitsrht/blueprints/repo.py24
-rw-r--r--gitsrht/templates/commit.html20
2 files changed, 38 insertions, 6 deletions
diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py
index 0e0fe08..3a27320 100644
--- a/gitsrht/blueprints/repo.py
+++ b/gitsrht/blueprints/repo.py
@@ -5,6 +5,7 @@ import subprocess
from datetime import datetime, timedelta
from jinja2 import Markup
from flask import Blueprint, render_template, abort, send_file, request
+from flask import Response
from flask_login import current_user
from gitsrht.access import get_repo, has_access, UserAccess
from gitsrht.editorconfig import EditorConfig
@@ -303,3 +304,26 @@ def commit(owner, repo, ref):
owner=owner, repo=repo, ref=ref, refs=refs,
commit=commit, parent=parent,
diff=diff, diffstat=diffstat, pygit2=pygit2)
+
+@repo.route("/<owner>/<repo>/commit/<ref>.patch")
+def patch(owner, repo, ref):
+ owner, repo = get_repo(owner, repo)
+ if not repo:
+ abort(404)
+ if not has_access(repo, UserAccess.read):
+ abort(401)
+ git_repo = CachedRepository(repo.path)
+ commit = git_repo.revparse_single(ref)
+ if isinstance(commit, pygit2.Tag):
+ ref = git_repo.get(commit.target)
+ subp = subprocess.run([
+ "git",
+ "--git-dir", repo.path,
+ "format-patch",
+ "--stdout", "-1",
+ ref
+ ], timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ if subp.returncode != 0:
+ print(subp.stdout, subp.stderr)
+ return "Error preparing patch", 500
+ return Response(subp.stdout, mimetype='text/plain')
diff --git a/gitsrht/templates/commit.html b/gitsrht/templates/commit.html
index 1fc0208..37db30c 100644
--- a/gitsrht/templates/commit.html
+++ b/gitsrht/templates/commit.html
@@ -13,12 +13,20 @@
</div>
</div>
<div class="col-md-2">
- <a href="#" class="btn btn-primary btn-block">
- browse {{icon("caret-right")}}
- </a>
- <a href="#" class="btn btn-default btn-block">
- patch {{icon("caret-right")}}
- </a>
+ <a
+ href="{{url_for("repo.tree",
+ owner=repo.owner.canonical_name,
+ repo=repo.name,
+ ref=commit.id.hex)}}"
+ class="btn btn-primary btn-block"
+ >browse {{icon("caret-right")}}</a>
+ <a
+ href="{{url_for("repo.patch",
+ owner=repo.owner.canonical_name,
+ repo=repo.name,
+ ref=commit.id.hex)}}"
+ class="btn btn-default btn-block"
+ >patch {{icon("caret-right")}}</a>
</div>
</div>
<div class="row">