From 713f5cb7bef1c05ea143b8dff9e249d0f7e7c81a Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Thu, 20 Nov 2025 23:35:35 +0200 Subject: [PATCH] blame loading --- app.py | 10 ++++-- git/blame.py | 5 ++- templates/blame.html | 72 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 73 insertions(+), 14 deletions(-) diff --git a/app.py b/app.py index 2564732..46f6d63 100644 --- a/app.py +++ b/app.py @@ -122,8 +122,14 @@ def repo_blob_path(repo_name, path): def repo_blame_path(repo_name, path): ref = request.args.get('ref', 'HEAD') refs = get_refs(f"{repo_path}/{repo_name}") - blame, style = get_blame(f"{repo_path}/{repo_name}", ref, path) - return render_template("blame.html", repo_name=repo_name, ref=ref, path=path, blame=blame, refs=refs, style=style) + + # if ajax (for loading) + if request.headers.get('X-Requested-With') == 'XMLHttpRequest': + blame, style = get_blame(f"{repo_path}/{repo_name}", ref, path) + return {'blame': blame, 'style': style} + + # initial + return render_template("blame.html", repo_name=repo_name, ref=ref, path=path, refs=refs) @app.route("//diff") def repo_diff(repo_name): diff --git a/git/blame.py b/git/blame.py index 6d391de..e49463f 100644 --- a/git/blame.py +++ b/git/blame.py @@ -50,7 +50,10 @@ def get_blame(repo_path, ref="HEAD", file_path=""): # TODO: more info if needed info = { 'commit_id': str(hunk.final_commit_id), - 'author': commit.author, + 'author': { + 'name': commit.author.name, + 'time': commit.author.time, + }, } # fill premade info for lines in this hunk for i in range(start, min(end, len(blame_lines))): # prevent index overflow, with min diff --git a/templates/blame.html b/templates/blame.html index ba4b8e7..240f195 100644 --- a/templates/blame.html +++ b/templates/blame.html @@ -1,17 +1,67 @@ {% extends "base.html" %} {% block content %} - +

Blame: {{ path }}

-{% if blame %} -
-
-
-
-{% for line in blame %}{{ "%4s" % line.line_num }} {% if line.blame %}{{ line.blame.commit_id[:8] }} {{ "%-15s" % line.blame.author.name[:15] }} {{ line.blame.author.time | datetime }}{% endif %} | {{ line.highlighted | safe }}
-{% endfor %}
-{% else %} -

No blame info

-{% endif %} +
Loading blame information, this may take a while for large files...
+ + + {% endblock %} \ No newline at end of file -- 2.47.3