.mailmap-update 1.87 KB
Newer Older
1
#!/usr/bin/perl
2

3
use strict;
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

my %name2mails;
my %cmail2cname;

open IN, ".mailmap" or die $!;
while (<IN>) {
  chomp;

  my ($pname, $pmail, $cname, $cmail) = /^([^<]*?)\s*<([^>]*)>(?:\s*([^<]*?)\s*<([^>]*)>)?$/ or die;

  $cmail = $pmail if $cmail eq "";

  $name2mails{$pname}->{$pmail} = -1;
  $name2mails{$pname}->{$cmail} = 0 if !defined($name2mails{$pname}->{$cmail});
  $cmail2cname{$cmail} = $cname;

}
close IN;

23 24
open IN, "git shortlog -s -e -n |" or die $!;
while (<IN>) {
25 26 27 28 29 30 31 32 33
  chomp;

  my ($n, $cname, $cmail) = m/^\s*(\d+)\s+([^<>]+)\s+<([^>]+)>\s*$/ or die;

  $name2mails{$cname}->{$cmail} = $n if !defined($name2mails{$cname}->{$cmail});

}
close IN;

34 35
my @mailmap;

36 37
foreach my $pname (sort { $a cmp $b } keys(%name2mails)) {

Karl Wette's avatar
Karl Wette committed
38 39 40
  my $pname2mail = lc($pname);
  $pname2mail =~ s/\s+/./g;

41
  my @pmails;
Karl Wette's avatar
Karl Wette committed
42
  push @pmails, grep { /^${pname2mail}[@]ligo[.]org$/ } keys(%{$name2mails{$pname}});
43 44 45 46 47 48 49 50 51 52 53
  push @pmails, grep { /^[a-z.-]+[@]ligo[.]org$/ } keys(%{$name2mails{$pname}});
  push @pmails, grep { /[@]ligo[.]org$/ } keys(%{$name2mails{$pname}});
  push @pmails, grep { $name2mails{$pname}->{$_} < 0 } keys(%{$name2mails{$pname}});
  push @pmails, sort { $name2mails{$pname}->{$b} <=> $name2mails{$pname}->{$a} } keys(%{$name2mails{$pname}});
  shift @pmails if $pmails[0] =~ /^albert[.]einstein@/i;

  my $pmail = shift @pmails;
  die "Could not determine email address for $pname" unless defined($pmail);

  next unless keys(%{$name2mails{$pname}}) > 1 || $name2mails{$pname}->{$pmail} <= 0;

54
  push @mailmap, "$pname <$pmail>";
55 56 57
  foreach my $mail (sort { $a cmp $b } keys(%{$name2mails{$pname}})) {
    next if $mail eq $pmail;
    if ($cmail2cname{$mail} ne "") {
58
      push @mailmap, "$pname <$pmail> $cmail2cname{$mail} <$mail>";
59
    } else {
60
      push @mailmap, "$pname <$pmail> <$mail>";
61
    }
62 63
  }

64
}
65 66 67 68 69 70

open OUT, ">.mailmap" or die $!;
foreach my $line (@mailmap) {
  print OUT "$line\n";
}
close OUT;