diff --git a/gitsrht/blueprints/api/porcelain.py b/gitsrht/blueprints/api/porcelain.py index 51d8db3..65f0626 100644 --- a/gitsrht/blueprints/api/porcelain.py +++ b/gitsrht/blueprints/api/porcelain.py @@ -20,19 +20,17 @@ from srht.validation import Validation porcelain = Blueprint("api_porcelain", __name__) # See also gitsrht-update-hook/types.go -def commit_to_dict(c, repo): - author = repo.author(c) - committer = repo.committer(c) +def commit_to_dict(c): return { "id": str(c.id), "short_id": c.short_id, "author": { - "email": author.email, - "name": author.name, + "email": c.author.email, + "name": c.author.name, }, "committer": { - "email": committer.email, - "name": committer.name, + "email": c.committer.email, + "name": c.committer.name, }, "timestamp": commit_time(c), "message": c.message, @@ -155,7 +153,7 @@ def repo_commits_GET(username, reponame, ref, path): next_id = str(commits[-1].id) return { "next": next_id, - "results": [commit_to_dict(c, repo) for c in commits], + "results": [commit_to_dict(c) for c in commits], # TODO: Track total commits per repo per branch "total": -1, "results_per_page": commits_per_page diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index d9426f8..bdbd866 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -503,7 +503,7 @@ def log(owner, repo, ref, path): has_more = commits and len(commits) == 21 - author_emails = set((repo.author(commit).email for commit in commits[:20])) + author_emails = set((commit.author.email for commit in commits[:20])) authors = {user.email:user for user in User.query.filter(User.email.in_(author_emails)).all()} return render_template("log.html", view="log", owner=owner, repo=repo, ref=ref, path=path.split("/"), @@ -671,7 +671,7 @@ def refs_rss(owner, repo): def _ref_sort_key(ref): target = git_repo.get(ref.target) - author = repo.author(target) + author = target.author if hasattr(target, 'author') else target.get_object().author return author.time + author.offset references = sorted(references, key=_ref_sort_key, reverse=True)[:20] diff --git a/gitsrht/git.py b/gitsrht/git.py index 00f6fbc..3c67241 100644 --- a/gitsrht/git.py +++ b/gitsrht/git.py @@ -1,6 +1,6 @@ from collections import deque from datetime import datetime, timedelta, timezone -from pygit2 import Repository as GitRepository, Mailmap, Tag +from pygit2 import Repository as GitRepository, Tag from markupsafe import Markup, escape from stat import filemode import pygit2 @@ -98,7 +98,6 @@ def get_log(git_repo, commit, path="", commits_per_page=20, until=None): class Repository(GitRepository): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._mailmap = Mailmap.from_repository(self) def __enter__(self): return self @@ -123,18 +122,6 @@ class Repository(GitRepository): else: return None - def author(self, obj): - sig = obj.author if hasattr(obj, "author") else obj.get_object().author - return self._mailmap.resolve_signature(sig) - - def committer(self, obj): - sig = obj.committer if hasattr(obj, "committer") else obj.get_object().committer - return self._mailmap.resolve_signature(sig) - - def tagger(self, obj): - sig = obj.tagger if hasattr(obj, "tagger") else obj.get_object().tagger - return self._mailmap.resolve_signature(sig) - @property def is_empty(self): return len(self.raw_listall_branches(pygit2.GIT_BRANCH_LOCAL)) == 0 diff --git a/gitsrht/rss.py b/gitsrht/rss.py index e17496d..fe46e63 100644 --- a/gitsrht/rss.py +++ b/gitsrht/rss.py @@ -45,7 +45,7 @@ def ref_to_item(repo, reference): with GitRepository(repo.path) as git_repo: target = git_repo.get(reference.target) - author = repo.author(target) + author = target.author if hasattr(target, 'author') else target.get_object().author time = aware_time(author).strftime(RFC_822_FORMAT) url = ref_url(repo, reference) description = target.message.strip().replace("\n", "
") @@ -64,8 +64,7 @@ def commit_to_item(repo, commit): time = aware_time(commit.author).strftime(RFC_822_FORMAT) url = commit_url(repo, commit) title, description = commit_title_description(commit) - author = repo.author(commit) - author = f"{author.email} ({author.name})" + author = f"{commit.author.email} ({commit.author.name})" element = ET.Element("item") ET.SubElement(element, "title").text = title diff --git a/gitsrht/templates/blame.html b/gitsrht/templates/blame.html index bd1d377..35fa71b 100644 --- a/gitsrht/templates/blame.html +++ b/gitsrht/templates/blame.html @@ -27,13 +27,12 @@ pre, body { repo=repo.name, ref=ref)}}" >{{commit.id.hex[:8]}} — - {% set author = repo.author(commit) %} - {% set author_user = lookup_user(author.email) %} + {% set author_user = lookup_user(commit.author.email) %} {% if author_user %} {{author.name}} + username=author_user.username)}}">{{commit.author.name}} {% else %} - {{author.name}} + {{commit.author.name}} {% endif %} {{trim_commit(commit.message)}} diff --git a/gitsrht/templates/blob.html b/gitsrht/templates/blob.html index c354a0d..09bb5eb 100644 --- a/gitsrht/templates/blob.html +++ b/gitsrht/templates/blob.html @@ -24,13 +24,12 @@ pre { repo=repo.name, ref=ref)}}" >{{commit.id.hex[:8]}} — - {% set author = repo.author(commit) %} - {% set author_user = lookup_user(author.email) %} + {% set author_user = lookup_user(commit.author.email) %} {% if author_user %} {{author.name}} + username=author_user.username)}}">{{commit.author.name}} {% else %} - {{author.name}} + {{commit.author.name}} {% endif %} {{trim_commit(commit.message)}} diff --git a/gitsrht/templates/refs.html b/gitsrht/templates/refs.html index 1fc61b4..2deae85 100644 --- a/gitsrht/templates/refs.html +++ b/gitsrht/templates/refs.html @@ -38,11 +38,11 @@

{% if isinstance(tag, pygit2.Commit) %} {% set refname = commit.id.hex %} - {% set author = repo.author(commit) %} + {% set author = commit.author %} {{ref[len("refs/tags/"):]}} {% else %} {% set refname = tag.raw_name %} - {% set author = repo.tagger(tag) %} + {% set author = tag.tagger %} {{commit.id.hex[:8]}} — - {% set author = repo.author(commit) %} - {% set author_user = lookup_user(author.email) %} + {% set author_user = lookup_user(commit.author.email) %} {% if author_user %} {{author.name}} + username=author_user.username)}}">{{commit.author.name}} {% else %} - {{author.name}} + {{commit.author.name}} {% endif %} {{trim_commit(commit.message)}} diff --git a/gitsrht/templates/utils.html b/gitsrht/templates/utils.html index 174f7a3..9a9637d 100644 --- a/gitsrht/templates/utils.html +++ b/gitsrht/templates/utils.html @@ -93,13 +93,12 @@ endif %}{% endfor %} >{{c.id.hex[:8]}} {% endif %} — - {% set author = repo.author(c) %} - {% set author_user = lookup(author.email) %} + {% set author_user = lookup(c.author.email) %} {% if author_user %} {{author.name}} + username=author_user.username)}}">{{c.author.name}} {% else %} - {{author.name}} + {{c.author.name}} {% endif %}