From cd677fa07eab4e19e5d131f89fdf2e8685c415dd Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Wed, 19 Nov 2025 13:44:33 +0200 Subject: [PATCH] simple diff view --- app.py | 8 ++++++++ git/diff.py | 13 +++++++++++++ templates/diff.html | 5 +++++ 3 files changed, 26 insertions(+) create mode 100644 git/diff.py create mode 100644 templates/diff.html diff --git a/app.py b/app.py index 727d544..bd06a08 100644 --- a/app.py +++ b/app.py @@ -6,6 +6,7 @@ from git.ref import get_refs from git.tree import get_tree_items from git.blob import get_blob from git.misc import get_version +from git.diff import get_diff app = Flask(__name__) @@ -52,5 +53,12 @@ def repo_blob_path(repo_name, path): blob = get_blob(f"{repo_path}/{repo_name}", ref, path) return render_template("blob.html", repo_name=repo_name, ref=ref, path=path, blob=blob) +@app.route("//diff") +def repo_diff(repo_name): + id1 = request.args.get('id1', 'HEAD') + id2 = request.args.get('id2', 'HEAD') + diff = get_diff(f"{repo_path}/{repo_name}", id1=id1, id2=id2) + return render_template("diff.html", diff=diff) + if __name__ == "__main__": app.run(debug=True) \ No newline at end of file diff --git a/git/diff.py b/git/diff.py new file mode 100644 index 0000000..27b97c6 --- /dev/null +++ b/git/diff.py @@ -0,0 +1,13 @@ +import pygit2 as git + +# compares two refs and return diff +# TODO: per file, now just full hunk, per file stats, and no changes to compare. +def get_diff(path, id1="HEAD", id2="HEAD"): + repo = git.Repository(path) + ref_one = repo.revparse_single(id1) + ref_two = repo.revparse_single(id2) + diff = repo.diff(ref_one, ref_two) + + return diff.patch + + diff --git a/templates/diff.html b/templates/diff.html new file mode 100644 index 0000000..c70022f --- /dev/null +++ b/templates/diff.html @@ -0,0 +1,5 @@ +{% block content %} +
+    {{ diff }}
+
+{% endblock %} \ No newline at end of file -- 2.47.3