diff --git a/app.py b/app.py
index c6504f0..6b0b144 100644
--- a/app.py
+++ b/app.py
import os
+import subprocess
from flask import Flask, render_template, request, abort
from datetime import datetime
from dotenv import load_dotenv
commit = get_commit(f"{repo_path}/{repo_name}", commit_id)
return render_template("commit.html", repo_name=repo_name, commit=commit)
+@app.route("/<repo_name>/patch/<commit_id>")
+def commit_patch(repo_name, commit_id):
+ if not validate_repo_name(repo_name):
+ abort(404)
+ if not validate_ref_as_commit(f"{repo_path}/{repo_name}", commit_id):
+ abort(400, "Invalid commit id")
+ # Use git format-patch to generate the patch
+ result = subprocess.run(['git', '--git-dir', f"{repo_path}/{repo_name}", 'format-patch', '-1', '--stdout', commit_id],
+ capture_output=True, text=True, encoding='utf-8')
+ # git leaves encoded headers like =?UTF-8?Q?...?=, but that should be fine for patch view for now, TODO
+ if result.returncode != 0:
+ abort(500, f"Failed to generate patch: {result.stderr}")
+ return result.stdout, 200, {'Content-Type': 'text/plain; charset=utf-8'}
+
@app.route("/<repo_name>/refs")
def repo_refs(repo_name):
if not validate_repo_name(repo_name):
diff --git a/templates/commit.html b/templates/commit.html
index 48627bf..2dd5001 100644
--- a/templates/commit.html
+++ b/templates/commit.html
<tbody>
{% for file in commit.changed_files %}
<tr>
- <td>{{ file.file }}</td>
+ <td><a href="{{ url_for('repo_blob_path', repo_name=repo_name, path=file.file) }}?ref={{ commit.id }}">{{ file.file }}</a></td>
<td style="color: green;">+{{ file.additions }}</td>
<td style="color: red;">-{{ file.deletions }}</td>
<td>{{ file.status }}</td>
</tbody>
</table>
{% if commit.parent_id %}
- <p><a href="{{ url_for('repo_diff', repo_name=repo_name) }}?id1={{ commit.parent_id }}&id2={{ commit.id }}">View Full Diff</a></p>
+ <p><a href="{{ url_for('repo_diff', repo_name=repo_name) }}?id1={{ commit.parent_id }}&id2={{ commit.id }}">View Full Diff</a> | <a href="{{ url_for('commit_patch', repo_name=repo_name, commit_id=commit.id) }}">Patch</a></p>
{% endif %}
{% else %}
<p>No changes compared to parent</p>