Diff between 5ade245c6e519517645c82910f3599893e96fcca and cd677fa07eab4e19e5d131f89fdf2e8685c415dd

Changed Files

File Additions Deletions Status
app.py +8 -0 modified
git/diff.py +13 -0 added
templates/diff.html +5 -0 added

Full Patch

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("/<repo_name>/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 %}
+<pre>
+    {{ diff }}
+</pre>
+{% endblock %}
\ No newline at end of file