~edwargix/git.sr.ht

3173bdddcdff576a009c6d1969cf77a656945694 — Arsen Arsenović 3 years ago 7b9c23f
refs: show the accurate annotated tag time

After this patch, the ref and refs pages will show the time based on the
tagger line of tags for annotated tags.
4 files changed, 13 insertions(+), 7 deletions(-)

M gitsrht/app.py
M gitsrht/git.py
M gitsrht/templates/ref.html
M gitsrht/templates/refs.html
M gitsrht/app.py => gitsrht/app.py +2 -1
@@ 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,

M gitsrht/git.py => gitsrht/git.py +7 -4
@@ 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)


M gitsrht/templates/ref.html => gitsrht/templates/ref.html +1 -1
@@ 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">

M gitsrht/templates/refs.html => gitsrht/templates/refs.html +3 -1
@@ 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",