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__)
# 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

View File

@ -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]

View File

@ -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

View File

@ -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", "<br />")
@ -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

View File

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

View File

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

View File

@ -38,11 +38,11 @@
<h4 style="margin-bottom: 0.5rem">
{% 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 %}
<a href="{{url_for("repo.ref",
owner=repo.owner.canonical_name,
repo=repo.name,

View File

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

View File

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

View File

@ -148,14 +148,5 @@ class Repository(Base):
self._git_repo = GitRepository(self.path)
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.sshkey import SSHKey