From: florian@mickler.org
To: linux-kernel@vger.kernel.org
Cc: ebiederm@xmission.com, greg@kroah.com, stefanr@s5r6.in-berlin.de,
broonie@opensource.wolfsonmicro.com,
"florian@mickler.org" <florian@mickler.org>,
Andrew Morton <akpm@linux-foundation.org>,
Joe Perches <joe@perches.com>,
Stephen Hemminger <shemminger@vyatta.com>
Subject: [PATCH] scripts/get_maintainer.pl: fix .mailmap handling
Date: Tue, 21 Sep 2010 00:35:56 +0200 [thread overview]
Message-ID: <1285022156-14501-1-git-send-email-florian@mickler.org> (raw)
In-Reply-To: <1285021645-14311-1-git-send-email-florian@mickler.org>
From: florian@mickler.org <florian@mickler.org>
The .mailmap handling was broken.
Implement it like the git-shortlog man page explains it.
Signed-off-by: Florian Mickler <florian@mickler.org>
---
changes: added sign off
scripts/get_maintainer.pl | 148 +++++++++++++++++++++++++++++++++------------
1 files changed, 110 insertions(+), 38 deletions(-)
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index a91ae63..d6fdd1a 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -255,31 +255,77 @@ while (<$maint>) {
}
close($maint);
-my %mailmap;
-if ($email_remove_duplicates) {
- open(my $mailmap, '<', "${lk_path}.mailmap")
+#
+# Read mail address map
+#
+
+my $mailmap = read_mailmap();
+
+sub read_mailmap {
+ my $mailmap = {
+ names => {},
+ addresses => {}
+ };
+
+ if (!$email_remove_duplicates) {
+ return $mailmap;
+ }
+
+ open(my $mailmap_file, '<', "${lk_path}.mailmap")
or warn "$P: Can't open .mailmap: $!\n";
- while (<$mailmap>) {
- my $line = $_;
- next if ($line =~ m/^\s*#/);
- next if ($line =~ m/^\s*$/);
+ while (<$mailmap_file>) {
+ s/#.*$//; #strip comments
+ s/^\s+|\s+$//g; #trim
- my ($name, $address) = parse_email($line);
- $line = format_email($name, $address, $email_usename);
+ next if (/^\s*$/); #skip empty lines
+ #print "entry: \"$_\"\n";
+ #entries have one of the following formats:
+ # name1 <mail1>
+ # <mail1> <mail2>
+ # name1 <mail1> <mail2>
+ # name1 <mail1> name2 <mail2>
+ # (see man git-shortlog)
+ if (/^(.+)<(.+)>$/) {
+ my $real_name = $1;
+ my $address = $2;
- next if ($line =~ m/^\s*$/);
+ $real_name =~ s/\s+$//;
+ $mailmap->{names}->{$address} = $real_name;
- if (exists($mailmap{$name})) {
- my $obj = $mailmap{$name};
- push(@$obj, $address);
- } else {
- my @arr = ($address);
- $mailmap{$name} = \@arr;
+ } elsif (/^<([^\s]+)>\s*<([^\s]+)>$/) {
+ my $real_address = $1;
+ my $wrong_address = $2;
+
+ $mailmap->{addresses}->{$wrong_address} = $real_address;
+
+ } elsif (/^(.+)<([^\s]+)>\s*<([^\s]+)>$/) {
+ my $real_name= $1;
+ my $real_address = $2;
+ my $wrong_address = $3;
+
+ $real_name =~ s/\s+$//;
+
+ $mailmap->{names}->{$wrong_address} = $real_name;
+ $mailmap->{addresses}->{$wrong_address} = $real_address;
+
+ } elsif (/^(.+)<([^\s]+)>\s*([^\s].*)<([^\s]+)>$/) {
+ my $real_name = $1;
+ my $real_address = $2;
+ my $wrong_name = $3;
+ my $wrong_address = $4;
+
+ $real_name =~ s/\s+$//;
+ $wrong_name =~ s/\s+$//;
+
+ $mailmap->{names}->{format_email($wrong_name,$wrong_address,1)} = $real_name;
+ $mailmap->{addresses}->{format_email($wrong_name,$wrong_address,1)} = $real_address;
}
}
- close($mailmap);
+ close($mailmap_file);
+
+ return $mailmap;
}
## use the filenames on the command line or find the filenames in the patchfiles
@@ -954,30 +1000,58 @@ sub which {
return "";
}
-sub mailmap {
- my (@lines) = @_;
- my %hash;
+sub mailmap_email {
+ my $line = shift;
- foreach my $line (@lines) {
my ($name, $address) = parse_email($line);
- if (!exists($hash{$name})) {
- $hash{$name} = $address;
- } elsif ($address ne $hash{$name}) {
- $address = $hash{$name};
- $line = format_email($name, $address, $email_usename);
- }
- if (exists($mailmap{$name})) {
- my $obj = $mailmap{$name};
- foreach my $map_address (@$obj) {
- if (($map_address eq $address) &&
- ($map_address ne $hash{$name})) {
- $line = format_email($name, $hash{$name}, $email_usename);
+ my $email = format_email($name, $address, 1);
+ my $real_name = $name;
+ my $real_address = $address;
+
+ if (exists $mailmap->{names}->{$email} || exists $mailmap->{addresses}->{$email}) {
+ if (exists $mailmap->{names}->{$email}) {
+ $real_name = $mailmap->{names}->{$email};
+ }
+ if (exists $mailmap->{addresses}->{$email}) {
+ $real_address = $mailmap->{addresses}->{$email};
+ }
+ } else {
+ if (exists $mailmap->{names}->{$address}) {
+ $real_name = $mailmap->{names}->{$address};
+ }
+ if (exists $mailmap->{addresses}->{$address}) {
+ $real_address = $mailmap->{addresses}->{$address};
}
- }
}
+ return format_email($real_name, $real_address, 1);
+}
+
+sub mailmap {
+ my (@addresses) = @_;
+
+ my @ret = ();
+ foreach my $line (@addresses) {
+ push(@ret, mailmap_email($line), 1);
}
- return @lines;
+ merge_by_realname(@ret) if $email_remove_duplicates;
+
+ return @ret;
+}
+
+sub merge_by_realname {
+ my %address_map;
+ my (@emails) = @_;
+ foreach my $email (@emails) {
+ my ($name, $address) = parse_email($email);
+ if (!exists $address_map{$name}) {
+ $address_map{$name} = $address;
+ } else {
+ $address = $address_map{$name};
+ $email = format_email($name,$address,1);
+ }
+ }
+
}
sub git_execute_cmd {
@@ -1148,9 +1222,7 @@ sub vcs_assign {
$divisor = 1;
}
- if ($email_remove_duplicates) {
- @lines = mailmap(@lines);
- }
+ @lines = mailmap(@lines);
return if (@lines <= 0);
--
1.7.3
next prev parent reply other threads:[~2010-09-20 22:36 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-15 12:13 [PATCH rfc] scripts/get_maintainer.pl: add interactive mode florian
2010-09-15 13:43 ` [v2 PATCH " florian
2010-09-15 15:16 ` [PATCH RFC v3] " florian
2010-09-15 15:35 ` Joe Perches
2010-09-20 19:43 ` [RFC PATCH] " Joe Perches
2010-09-20 21:53 ` Florian Mickler
2010-09-20 22:27 ` [PATCH] scripts/get_maintainer.pl: fix .mailmap handling florian
2010-09-20 22:35 ` florian [this message]
2010-09-21 0:14 ` Joe Perches
2010-09-21 4:59 ` Florian Mickler
2010-09-21 5:20 ` Joe Perches
2010-09-21 6:23 ` Florian Mickler
2010-09-21 0:38 ` [RFC PATCH] scripts/get_maintainer.pl: add interactive mode Joe Perches
2010-09-21 5:31 ` Florian Mickler
2010-09-21 6:12 ` Joe Perches
2010-09-21 6:30 ` [PATCH v2] scripts/get_maintainer.pl: fix mailmap handling florian
2010-09-15 15:27 ` [v2 PATCH rfc] scripts/get_maintainer.pl: add interactive mode Joe Perches
2010-09-16 8:30 ` Florian Mickler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1285022156-14501-1-git-send-email-florian@mickler.org \
--to=florian@mickler.org \
--cc=akpm@linux-foundation.org \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=ebiederm@xmission.com \
--cc=greg@kroah.com \
--cc=joe@perches.com \
--cc=linux-kernel@vger.kernel.org \
--cc=shemminger@vyatta.com \
--cc=stefanr@s5r6.in-berlin.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox