diff --git a/app.py b/app.py
index 727d544..bd06a08 100644
--- a/app.py
+++ b/app.py
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__)
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
+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
+{% block content %}
+<pre>
+ {{ diff }}
+</pre>
+{% endblock %}
\ No newline at end of file