Arsen Arsenović: 1 refs: show the accurate annotated tag time 4 files changed, 13 insertions(+), 7 deletions(-)
Copy & paste the following snippet into your terminal to import this patchset into git:
curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/25093/mbox | git am -3Learn more about email & git
After this patch, the ref and refs pages will show the time based on the tagger line of tags for annotated tags. --- I'd possibly make some changes here, notably, add a prefix such as "tagged on" and "committed on" depending on the kind of tag, to make it clear what time was specified, but it'd be a larger visual change in the UI so I'd rather ask about that first. For an example, see: https://git.sr.ht/~sircmpwn/getopt/refs/v1.0.0 gitsrht/app.py | 3 ++- gitsrht/git.py | 11 +++++++---- gitsrht/templates/ref.html | 2 +- gitsrht/templates/refs.html | 4 +++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/gitsrht/app.py b/gitsrht/app.py index 9ad916f..9efa7c5 100644 --- a/gitsrht/app.py +++ b/gitsrht/app.py @@ -3,7 +3,7 @@ import os import stat from functools import lru_cache from gitsrht import urls -from gitsrht.git import commit_time, trim_commit +from gitsrht.git import commit_time, trim_commit, signature_time from gitsrht.repos import GitRepoApi from gitsrht.service import oauth_service, webhooks_notify from gitsrht.types import Access, Redirect, Repository, User @@ -54,6 +54,7 @@ class GitApp(ScmSrhtFlask): del session["notice"] return { "commit_time": commit_time, + "signature_time": signature_time, "humanize": humanize, "notice": notice, "object_storage_enabled": object_storage_enabled, diff --git a/gitsrht/git.py b/gitsrht/git.py index e32bcfe..9caf8c5 100644 --- a/gitsrht/git.py +++ b/gitsrht/git.py @@ -19,17 +19,20 @@ def trim_commit(msg): return msg return msg[:msg.index("\n")] -def commit_time(commit): - author = commit.author if hasattr(commit, 'author') else commit.get_object().author +def signature_time(signature): # Time handling in python is so dumb try: - tzinfo = timezone(timedelta(minutes=author.offset)) - tzaware = datetime.fromtimestamp(float(author.time), tzinfo) + tzinfo = timezone(timedelta(minutes=signature.offset)) + tzaware = datetime.fromtimestamp(float(signature.time), tzinfo) diff = datetime.now(timezone.utc) - tzaware return datetime.utcnow() - diff except: return datetime.utcnow() +def commit_time(commit): + author = commit.author if hasattr(commit, 'author') else commit.get_object().author + return signature_time(author) + def _get_ref(repo, ref): return repo._get(ref) diff --git a/gitsrht/templates/ref.html b/gitsrht/templates/ref.html index 480b364..3aade25 100644 --- a/gitsrht/templates/ref.html +++ b/gitsrht/templates/ref.html @@ -8,7 +8,7 @@ <h3> {{tag.name}} <small class="pull-right text-muted"> - {{commit_time(tag) | date}} + {{signature_time(tag.tagger) | date}} </small> </h3> <div class="row"> diff --git a/gitsrht/templates/refs.html b/gitsrht/templates/refs.html index 5aef23b..6e077ba 100644 --- a/gitsrht/templates/refs.html +++ b/gitsrht/templates/refs.html @@ -37,9 +37,11 @@ <h4 style="margin-bottom: 0.5rem"> {% if isinstance(tag, pygit2.Commit) %} {% set refname = commit.id.hex %} + {% set author = commit.author %} {{ref[len("refs/tags/"):]}} {% else %} {% set refname = tag.raw_name %} + {% set author = tag.tagger %} <a href="{{url_for("repo.ref", owner=repo.owner.canonical_name, repo=repo.name, @@ -48,7 +50,7 @@ </a> {% endif %} <small class="pull-right text-muted"> - {{commit_time(tag) | date}} + {{signature_time(author) | date}} <a style="margin-left: 0.5rem" href="{{url_for("repo.archive", -- 2.32.0
builds.sr.ht <builds@sr.ht>git.sr.ht/patches: SUCCESS in 3m34s [refs: show the accurate annotated tag time][0] from [Arsen Arsenović][1] [0]: https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/25093 [1]: mailto:arsen@aarsen.me ✓ #584493 SUCCESS git.sr.ht/patches/archlinux.yml https://builds.sr.ht/~sircmpwn/job/584493 ✓ #584492 SUCCESS git.sr.ht/patches/alpine.yml https://builds.sr.ht/~sircmpwn/job/584492 ✓ #584494 SUCCESS git.sr.ht/patches/debian.yml https://builds.sr.ht/~sircmpwn/job/584494
Thanks! To git@git.sr.ht:~sircmpwn/git.sr.ht 3173bdd..7b9c23f master -> master