From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by dcvr.yhbt.net (Postfix) with ESMTP id 34C591F5AE for ; Thu, 30 Jul 2020 16:20:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728437AbgG3QUs (ORCPT ); Thu, 30 Jul 2020 12:20:48 -0400 Received: from pb-smtp2.pobox.com ([64.147.108.71]:50028 "EHLO pb-smtp2.pobox.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728368AbgG3QUs (ORCPT ); Thu, 30 Jul 2020 12:20:48 -0400 Received: from pb-smtp2.pobox.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id BA29C6B74A; Thu, 30 Jul 2020 12:20:41 -0400 (EDT) (envelope-from junio@pobox.com) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=vANukSLmHyYrzyHXyfmO5Trr0ps=; b=YCNOxU jPrH8K5dWWx3t8AIo1SxJjOMlhvRX7udrELsgx5Gn1nsh2TDVfYMpt4Ays7cI4GJ aYt4UBsujWEPHx++u52M/wdk6hF/dUreEYCr4pkH+Wp1ABKREVRmwvrGmFNAFVMk CIpG8tQaSPCwHbX2hwQhJauBKu+QQx0oAOj10= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=UhYsATidFWoET8I3LgNAxk3Mw7mSAIhQ jfDQujkvNwvRZhlJCf4MMNC8IGWUPDgEhxyAcP0XeYUicNkwtUvtobz/zIYvpiSL hokmNm9vG24uZT45qJyXJsOQbsrAgcd2qQSiWkI8Lxr0nbsKy8ndnj8vt+iArmeg ngzpobBrN3o= Received: from pb-smtp2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-smtp2.pobox.com (Postfix) with ESMTP id B1D4F6B749; Thu, 30 Jul 2020 12:20:41 -0400 (EDT) (envelope-from junio@pobox.com) Received: from pobox.com (unknown [35.196.173.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pb-smtp2.pobox.com (Postfix) with ESMTPSA id 469266B748; Thu, 30 Jul 2020 12:20:41 -0400 (EDT) (envelope-from junio@pobox.com) From: Junio C Hamano To: Jakub =?utf-8?Q?Nar=C4=99bski?= Cc: git@vger.kernel.org, Emma Brooks Subject: Re: [RFC PATCH] gitweb: Map names/emails with mailmap References: <20200730041217.6893-1-me@pluvano.com> Date: Thu, 30 Jul 2020 09:20:40 -0700 In-Reply-To: <20200730041217.6893-1-me@pluvano.com> (Emma Brooks's message of "Thu, 30 Jul 2020 04:12:17 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Pobox-Relay-ID: 9C9779F4-D280-11EA-A5D2-2F5D23BA3BAF-77302942!pb-smtp2.pobox.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org [jc: Cc'ing Jakub, hoping he's still our resident gitweb expert, as an "RFC" requests help from experts] Emma Brooks writes: > Add an option to map names and emails to their canonical forms via a > .mailmap file. This is enabled by default, consistent with the behavior > of Git itself. > > Signed-off-by: Emma Brooks > --- > > This works, but needs some polish. The read_mailmap code is not > particularly clever. > > Documentation/gitweb.conf.txt | 5 +++ > gitweb/gitweb.perl | 79 +++++++++++++++++++++++++++++++++-- > 2 files changed, 80 insertions(+), 4 deletions(-) > > diff --git a/Documentation/gitweb.conf.txt b/Documentation/gitweb.conf.txt > index 7963a79ba9..2d7551a6a5 100644 > --- a/Documentation/gitweb.conf.txt > +++ b/Documentation/gitweb.conf.txt > @@ -751,6 +751,11 @@ default font sizes or lineheights are changed (e.g. via adding extra > CSS stylesheet in `@stylesheets`), it may be appropriate to change > these values. > > +mailmap:: > + Use mailmap to find the canonical name/email for > + committers/authors (see linkgit:git-shortlog[1]). Enabled by > + default. > + > highlight:: > Server-side syntax highlight support in "blob" view. It requires > `$highlight_bin` program to be available (see the description of > diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl > index 0959a782ec..00256704a7 100755 > --- a/gitweb/gitweb.perl > +++ b/gitweb/gitweb.perl > @@ -505,6 +505,12 @@ sub evaluate_uri { > 'override' => 0, > 'default' => ['']}, > > + # Enable reading mailmap to determine canonical author > + # information. Enabled by default. > + 'mailmap' => { > + 'override' => 0, > + 'default' => [1]}, > + > # Enable displaying how much time and how many git commands > # it took to generate and display page. Disabled by default. > # Project specific override is not supported. > @@ -3490,6 +3496,61 @@ sub parse_tag { > return %tag > } > > +# Contents of mailmap stored as a referance to a hash with keys in the format > +# of "name " or "", and values that are hashes containing a > +# replacement "name" and/or "email". If set (even if empty) the mailmap has > +# already been read. > +my $mailmap; > + > +sub read_mailmap { > + my %mailmap = (); > + open my $fd, '-|', git_cmd(), 'cat-file', 'blob', 'HEAD:.mailmap' > + or die_error(500, 'Failed to read mailmap'); > + foreach (split '\n', <$fd>) { > + next if (/^#/); > + if (/(.*)\s+ <([^<>]+)>\s+ ((?:.*\s+)? <[^<>]+>) (?:\s+\#)/x || > + /(.*)\s+ <([^<>]+)>\s+ ((?:.*\s+)? <[^<>]+>)/x) { > + # New Name > + # New Name Old Name > + $mailmap{$3} = (); > + $mailmap{$3}{name} = $1; > + $mailmap{$3}{email} = $2; > + } elsif (/(?: <([^<>]+)>\s+ | (.+)\s+ ) (<[^<>]+>) (?:\s+\#)/x || > + /(?: <([^<>]+)>\s+ | (.+)\s+ ) (<[^<>]+>)/x) { > + # New Name > + # > + $mailmap{$3} = (); > + if ($1) { > + $mailmap{$3}{email} = $1; > + } else { > + $mailmap{$3}{name} = $2; > + } > + } > + } > + return \%mailmap; > +} > + > +# Map author name and email based on mailmap. A more specific match > +# ("name ") is preferred to a less specific one (""). > +sub map_author { > + my $name = shift; > + my $email = shift; > + > + if (!$mailmap) { > + $mailmap = read_mailmap; > + } > + > + if ($mailmap->{"$name <$email>"}) { > + $name = $mailmap->{"$name <$email>"}{name} || $name; > + $email = $mailmap->{"$name <$email>"}{email} || $email; > + } elsif ($mailmap->{"<$email>"}) { > + $name = $mailmap->{"<$email>"}{name} || $name; > + $email = $mailmap->{"<$email>"}{email} || $email; > + } > + > + return ($name, $email); > +} > + > sub parse_commit_text { > my ($commit_text, $withparents) = @_; > my @commit_lines = split '\n', $commit_text; > @@ -3517,8 +3578,13 @@ sub parse_commit_text { > $co{'author_epoch'} = $2; > $co{'author_tz'} = $3; > if ($co{'author'} =~ m/^([^<]+) <([^>]*)>/) { > - $co{'author_name'} = $1; > - $co{'author_email'} = $2; > + my ($name, $email) = @_; > + if (gitweb_check_feature('mailmap')) { > + ($name, $email) = map_author($1, $2); > + $co{'author'} = "$name <$email>"; > + } > + $co{'author_name'} = $name; > + $co{'author_email'} = $email; > } else { > $co{'author_name'} = $co{'author'}; > } > @@ -3527,8 +3593,13 @@ sub parse_commit_text { > $co{'committer_epoch'} = $2; > $co{'committer_tz'} = $3; > if ($co{'committer'} =~ m/^([^<]+) <([^>]*)>/) { > - $co{'committer_name'} = $1; > - $co{'committer_email'} = $2; > + my ($name, $email) = @_; > + if (gitweb_check_feature('mailmap')) { > + ($name, $email) = map_author($1, $2); > + $co{'committer'} = "$name <$email>"; > + } > + $co{'committer_name'} = $name; > + $co{'committer_email'} = $email; > } else { > $co{'committer_name'} = $co{'committer'}; > }