diff --git a/README.md b/README.md
index 8b4e76e..1395b59 100644
--- a/README.md
+++ b/README.md
-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
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__)
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
}
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
+{% block content %}
+ <h1>Commit {{ commit.id }}</h1>
+ <p>Message: {{ commit.message }}</p>
+ <p>Author: {{ commit.author.name }} <{{ commit.author.email }}></p>
+ <p>Committer: {{ commit.committer.name }} <{{ commit.committer.email }}></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
<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
<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