Revert "Resolve name and email from mailmap"

This patch has an oversight, sent backtrace to Seb for review.

This reverts commit 2369d4aa22.
This commit is contained in:
Drew DeVault 2022-11-07 13:16:50 +01:00
parent d9d750669d
commit cd790c9bed
10 changed files with 25 additions and 54 deletions

View File

@ -20,19 +20,17 @@ from srht.validation import Validation
porcelain = Blueprint("api_porcelain", __name__) porcelain = Blueprint("api_porcelain", __name__)
# See also gitsrht-update-hook/types.go # See also gitsrht-update-hook/types.go
def commit_to_dict(c, repo): def commit_to_dict(c):
author = repo.author(c)
committer = repo.committer(c)
return { return {
"id": str(c.id), "id": str(c.id),
"short_id": c.short_id, "short_id": c.short_id,
"author": { "author": {
"email": author.email, "email": c.author.email,
"name": author.name, "name": c.author.name,
}, },
"committer": { "committer": {
"email": committer.email, "email": c.committer.email,
"name": committer.name, "name": c.committer.name,
}, },
"timestamp": commit_time(c), "timestamp": commit_time(c),
"message": c.message, "message": c.message,
@ -155,7 +153,7 @@ def repo_commits_GET(username, reponame, ref, path):
next_id = str(commits[-1].id) next_id = str(commits[-1].id)
return { return {
"next": next_id, "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 # TODO: Track total commits per repo per branch
"total": -1, "total": -1,
"results_per_page": commits_per_page "results_per_page": commits_per_page

View File

@ -503,7 +503,7 @@ def log(owner, repo, ref, path):
has_more = commits and len(commits) == 21 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()} authors = {user.email:user for user in User.query.filter(User.email.in_(author_emails)).all()}
return render_template("log.html", view="log", return render_template("log.html", view="log",
owner=owner, repo=repo, ref=ref, path=path.split("/"), owner=owner, repo=repo, ref=ref, path=path.split("/"),
@ -671,7 +671,7 @@ def refs_rss(owner, repo):
def _ref_sort_key(ref): def _ref_sort_key(ref):
target = git_repo.get(ref.target) 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 return author.time + author.offset
references = sorted(references, key=_ref_sort_key, reverse=True)[:20] references = sorted(references, key=_ref_sort_key, reverse=True)[:20]

View File

@ -1,6 +1,6 @@
from collections import deque from collections import deque
from datetime import datetime, timedelta, timezone 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 markupsafe import Markup, escape
from stat import filemode from stat import filemode
import pygit2 import pygit2
@ -98,7 +98,6 @@ def get_log(git_repo, commit, path="", commits_per_page=20, until=None):
class Repository(GitRepository): class Repository(GitRepository):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._mailmap = Mailmap.from_repository(self)
def __enter__(self): def __enter__(self):
return self return self
@ -123,18 +122,6 @@ class Repository(GitRepository):
else: else:
return None 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 @property
def is_empty(self): def is_empty(self):
return len(self.raw_listall_branches(pygit2.GIT_BRANCH_LOCAL)) == 0 return len(self.raw_listall_branches(pygit2.GIT_BRANCH_LOCAL)) == 0

View File

@ -45,7 +45,7 @@ def ref_to_item(repo, reference):
with GitRepository(repo.path) as git_repo: with GitRepository(repo.path) as git_repo:
target = git_repo.get(reference.target) 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) time = aware_time(author).strftime(RFC_822_FORMAT)
url = ref_url(repo, reference) url = ref_url(repo, reference)
description = target.message.strip().replace("\n", "<br />") description = target.message.strip().replace("\n", "<br />")
@ -64,8 +64,7 @@ def commit_to_item(repo, commit):
time = aware_time(commit.author).strftime(RFC_822_FORMAT) time = aware_time(commit.author).strftime(RFC_822_FORMAT)
url = commit_url(repo, commit) url = commit_url(repo, commit)
title, description = commit_title_description(commit) title, description = commit_title_description(commit)
author = repo.author(commit) author = f"{commit.author.email} ({commit.author.name})"
author = f"{author.email} ({author.name})"
element = ET.Element("item") element = ET.Element("item")
ET.SubElement(element, "title").text = title ET.SubElement(element, "title").text = title

View File

@ -27,13 +27,12 @@ pre, body {
repo=repo.name, repo=repo.name,
ref=ref)}}" ref=ref)}}"
>{{commit.id.hex[:8]}}</a> &mdash; >{{commit.id.hex[:8]}}</a> &mdash;
{% set author = repo.author(commit) %} {% set author_user = lookup_user(commit.author.email) %}
{% set author_user = lookup_user(author.email) %}
{% if author_user %} {% if author_user %}
<a href="{{url_for("public.user_index", <a href="{{url_for("public.user_index",
username=author_user.username)}}">{{author.name}}</a> username=author_user.username)}}">{{commit.author.name}}</a>
{% else %} {% else %}
{{author.name}} {{commit.author.name}}
{% endif %} {% endif %}
{{trim_commit(commit.message)}} {{trim_commit(commit.message)}}
<span class="text-muted"> <span class="text-muted">

View File

@ -24,13 +24,12 @@ pre {
repo=repo.name, repo=repo.name,
ref=ref)}}" ref=ref)}}"
>{{commit.id.hex[:8]}}</a> &mdash; >{{commit.id.hex[:8]}}</a> &mdash;
{% set author = repo.author(commit) %} {% set author_user = lookup_user(commit.author.email) %}
{% set author_user = lookup_user(author.email) %}
{% if author_user %} {% if author_user %}
<a href="{{url_for("public.user_index", <a href="{{url_for("public.user_index",
username=author_user.username)}}">{{author.name}}</a> username=author_user.username)}}">{{commit.author.name}}</a>
{% else %} {% else %}
{{author.name}} {{commit.author.name}}
{% endif %} {% endif %}
{{trim_commit(commit.message)}} {{trim_commit(commit.message)}}
<span class="text-muted"> <span class="text-muted">

View File

@ -38,11 +38,11 @@
<h4 style="margin-bottom: 0.5rem"> <h4 style="margin-bottom: 0.5rem">
{% if isinstance(tag, pygit2.Commit) %} {% if isinstance(tag, pygit2.Commit) %}
{% set refname = commit.id.hex %} {% set refname = commit.id.hex %}
{% set author = repo.author(commit) %} {% set author = commit.author %}
{{ref[len("refs/tags/"):]}} {{ref[len("refs/tags/"):]}}
{% else %} {% else %}
{% set refname = tag.raw_name %} {% set refname = tag.raw_name %}
{% set author = repo.tagger(tag) %} {% set author = tag.tagger %}
<a href="{{url_for("repo.ref", <a href="{{url_for("repo.ref",
owner=repo.owner.canonical_name, owner=repo.owner.canonical_name,
repo=repo.name, repo=repo.name,

View File

@ -16,13 +16,12 @@
repo=repo.name, repo=repo.name,
ref=ref)}}" ref=ref)}}"
>{{commit.id.hex[:8]}}</a> &mdash; >{{commit.id.hex[:8]}}</a> &mdash;
{% set author = repo.author(commit) %} {% set author_user = lookup_user(commit.author.email) %}
{% set author_user = lookup_user(author.email) %}
{% if author_user %} {% if author_user %}
<a href="{{url_for("public.user_index", <a href="{{url_for("public.user_index",
username=author_user.username)}}">{{author.name}}</a> username=author_user.username)}}">{{commit.author.name}}</a>
{% else %} {% else %}
{{author.name}} {{commit.author.name}}
{% endif %} {% endif %}
{{trim_commit(commit.message)}} {{trim_commit(commit.message)}}
<span class="text-muted"> <span class="text-muted">

View File

@ -93,13 +93,12 @@ endif %}{% endfor %}
>{{c.id.hex[:8]}}</a> >{{c.id.hex[:8]}}</a>
{% endif %} {% endif %}
&mdash; &mdash;
{% set author = repo.author(c) %} {% set author_user = lookup(c.author.email) %}
{% set author_user = lookup(author.email) %}
{% if author_user %} {% if author_user %}
<a href="{{url_for("public.user_index", <a href="{{url_for("public.user_index",
username=author_user.username)}}">{{author.name}}</a> username=author_user.username)}}">{{c.author.name}}</a>
{% else %} {% else %}
{{author.name}} {{c.author.name}}
{% endif %} {% endif %}
<small class="pull-right"> <small class="pull-right">
<a <a

View File

@ -148,14 +148,5 @@ class Repository(Base):
self._git_repo = GitRepository(self.path) self._git_repo = GitRepository(self.path)
return self._git_repo return self._git_repo
def author(self, obj):
return self.git_repo.author(obj)
def committer(self, obj):
return self.git_repo.committer(obj)
def tagger(self, obj):
return self.git_repo.tagger(obj)
from gitsrht.types.artifact import Artifact from gitsrht.types.artifact import Artifact
from gitsrht.types.sshkey import SSHKey from gitsrht.types.sshkey import SSHKey