Diff between df53a41e6e9a457aeffadce89bd5e61a6a77dfde and 48072f205905566bd62b7787a25641cfa61cd851

Changed Files

File Additions Deletions Status
app.py +2 -2 modified
git/diff.py +12 -4 modified
templates/diff.html +2 -0 modified

Full Patch

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("/<repo_name>/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 %}
+<h1>Diff between {{ diff.ref1 }} ({{ diff.ref1_id[:7] }}) and {{ diff.ref2 }} ({{ diff.ref2_id[:7] }})</h1>
+
 <h2>Changed Files</h2>
 <ul>
     {% for file in diff.files %}