From 48072f205905566bd62b7787a25641cfa61cd851 Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Wed, 19 Nov 2025 19:52:18 +0200 Subject: [PATCH] see what are compared in diff --- app.py | 4 ++-- git/diff.py | 16 ++++++++++++---- templates/diff.html | 2 ++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 0c5d650..2d7420a 100644 --- a/app.py +++ b/app.py @@ -85,8 +85,8 @@ def repo_blame_path(repo_name, path): @app.route("//diff") def repo_diff(repo_name): - id1 = request.args.get('id1', 'HEAD') - id2 = request.args.get('id2', 'HEAD') + id1 = request.args.get('id1') + id2 = request.args.get('id2') diff = get_diff(f"{repo_path}/{repo_name}", id1=id1, id2=id2) return render_template("diff.html", diff=diff) diff --git a/git/diff.py b/git/diff.py index 5e5b75c..ea1998c 100644 --- a/git/diff.py +++ b/git/diff.py @@ -1,10 +1,14 @@ import pygit2 as git # compares two refs and return diff stats per file and full patch -def get_diff(path, id1="HEAD", id2="HEAD"): +def get_diff(path, id1, id2): repo = git.Repository(path) - ref_one = repo.revparse_single(id1) - ref_two = repo.revparse_single(id2) + if not id1: + id1 = 'HEAD~1' + if not id2: + id2 = 'HEAD' + ref_one = repo.revparse_single(id1) # older + ref_two = repo.revparse_single(id2) # newer diff = repo.diff(ref_one, ref_two) # TODO: context_lines, interhunk_lines, etc as options @@ -48,7 +52,11 @@ def get_diff(path, id1="HEAD", id2="HEAD"): return { 'patch': diff.patch, - 'files': changed_files + 'files': changed_files, + 'ref1_id': str(ref_one.id), + 'ref2_id': str(ref_two.id), + 'ref1': id1, + 'ref2': id2 } diff --git a/templates/diff.html b/templates/diff.html index a1da9de..88388b5 100644 --- a/templates/diff.html +++ b/templates/diff.html @@ -1,4 +1,6 @@ {% block content %} +

Diff between {{ diff.ref1 }} ({{ diff.ref1_id[:7] }}) and {{ diff.ref2 }} ({{ diff.ref2_id[:7] }})

+

Changed Files