Diff between 8b9c6ecd6e6d81f3832a11542aa460d46e1b68ef and 97f4325e0f1f40a6918ceadd420c839b222edd20

Changed Files

File Additions Deletions Status
README.md +1 -1 modified
app.py +6 -1 modified
git/commit.py +33 -1 modified
templates/commit.html +15 -0 added
templates/commits.html +1 -1 modified
templates/index.html +1 -1 modified

Full Patch

diff --git a/README.md b/README.md
index 8b4e76e..1395b59 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
-Fast webview using pygit2 (lib2git) bindings.
+Fast webview using pygit2 (lib2git) bindings. For my personal use, for now
 
 <img width="1280" height="960" alt="image" src="https://github.com/user-attachments/assets/1ce40e5f-1eed-4085-a1b4-698aac9c557f" />
diff --git a/app.py b/app.py
index da8d209..c7210b0 100644
--- a/app.py
+++ b/app.py
@@ -1,7 +1,7 @@
 from flask import Flask, render_template, request
 
 from git.repo import get_bare_repos
-from git.commit import get_commits
+from git.commit import get_commits, get_commit
 
 app = Flask(__name__)
 
@@ -18,5 +18,10 @@ def repo_commits(repo_name):
     commits = get_commits(f"{repo_path}/{repo_name}", ref=ref, max_count=50)
     return render_template("commits.html", repo_name=repo_name, commits=commits)
 
+@app.route("/<repo_name>/commits/<commit_hash>")
+def commit_detail(repo_name, commit_hash):
+    commit = get_commit(f"{repo_path}/{repo_name}", commit_hash)
+    return render_template("commit.html", repo_name=repo_name, commit=commit)
+
 if __name__ == "__main__":
     app.run(debug=True)
\ No newline at end of file
diff --git a/git/commit.py b/git/commit.py
index acb0101..96b8cdd 100644
--- a/git/commit.py
+++ b/git/commit.py
@@ -37,4 +37,36 @@ def get_commits(path, ref="HEAD", max_count=None):
         }
         commits.append(commit_info)
         n += 1
-    return commits
\ No newline at end of file
+    return commits
+
+# retrieves a single commit by its hash
+def get_commit(path, commit_hash):
+    repo = git.Repository(path)
+    commit = repo.revparse_single(commit_hash)
+
+    if len(commit.parents) > 0:
+        diff = repo.diff(commit.parents[0], commit)
+        stats = diff.stats
+        diff_stats = {
+            'insertions': stats.insertions,
+            'deletions': stats.deletions,
+            'files_changed': stats.files_changed
+        }
+    else:
+        diff_stats = {
+            'insertions': 0,
+            'deletions': 0,
+            'files_changed': 0
+        }
+        diff = None
+
+    commit_info = {
+        'id': str(commit.id),
+        'message': commit.message.strip(),
+        'author': commit.author,
+        'committer': commit.committer,
+        'date': commit.commit_time,
+        'diff_stats': diff_stats,
+        'diff': diff.patch if diff else None
+    }
+    return commit_info
\ No newline at end of file
diff --git a/templates/commit.html b/templates/commit.html
new file mode 100644
index 0000000..ed8eeeb
--- /dev/null
+++ b/templates/commit.html
@@ -0,0 +1,15 @@
+{% block content %}
+    <h1>Commit {{ commit.id }}</h1>
+    <p>Message: {{ commit.message }}</p>
+    <p>Author: {{ commit.author.name }} &lt;{{ commit.author.email }}&gt;</p>
+    <p>Committer: {{ commit.committer.name }} &lt;{{ commit.committer.email }}&gt;</p>
+    <p>Date: {{ commit.date }}</p>
+    <h2>Diff Stats</h2>
+    <ul>
+        <li>Files Changed: {{ commit.diff_stats.files_changed }}</li>
+        <li>Insertions: {{ commit.diff_stats.insertions }}</li>
+        <li>Deletions: {{ commit.diff_stats.deletions }}</li>
+    </ul>
+    <h2>Diff</h2>
+    <pre>{{ commit.diff }}</pre>
+{% endblock %}
\ No newline at end of file
diff --git a/templates/commits.html b/templates/commits.html
index 18e7498..bb9ecdf 100644
--- a/templates/commits.html
+++ b/templates/commits.html
@@ -3,7 +3,7 @@
     <ul>
         {% for commit in commits %}
             <li>
-            {{ commit.id }} - {{ commit.message }} - {{ commit.author.name }} - {{ commit.date }} {{ commit.diff_stats.files_changed }} files changed, {{ commit.diff_stats.insertions }} insertions, {{ commit.diff_stats.deletions }} deletions
+            <a href="{{ url_for('commit_detail', repo_name=repo_name, commit_hash=commit.id) }}">{{ commit.id }}</a> - {{ commit.message }} - {{ commit.author.name }} - {{ commit.date }} {{ commit.diff_stats.files_changed }} files changed, {{ commit.diff_stats.insertions }} insertions, {{ commit.diff_stats.deletions }} deletions
             </li>
         {% endfor %}
     </ul>
diff --git a/templates/index.html b/templates/index.html
index 8c77402..c70ffad 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -2,7 +2,7 @@
     <h1>Repositories</h1>
     <ul>
         {% for repo in repos %}
-            <li><a href="{{ repo.name }}/commits">{{ repo.name }}</a></li>
+            <li><a href="{{ url_for('repo_commits', repo_name=repo.name) }}">{{ repo.name }}</a></li>
         {% endfor %}
     </ul>
 {% endblock %}
\ No newline at end of file