From 93b959111dcc90223b3785b22f3089b670f59489 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Mon, 1 Oct 2018 15:33:54 -0400 Subject: [PATCH] Wire up browse and patch buttons --- gitsrht/blueprints/repo.py | 24 ++++++++++++++++++++++++ gitsrht/templates/commit.html | 20 ++++++++++++++------ 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("///commit/.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 @@
-- 2.38.4