#!/usr/bin/perl
use strict;
use Git::Wrapper;
use List::MoreUtils qw(uniq);

my $git = Git::Wrapper->new('./');

sub git_log_grep {
  my $string = shift;
  return map { s/^\s*$string\s*//; $_ }
         grep { /$string/ }
         $git->RUN('log', {grep => $string});
}

my @authors = $git->RUN('log', {pretty => "format:%aN <%aE>"});
my @signed_authors = git_log_grep('Signed-off-by:');
my @co_authors = git_log_grep('Co-authored-by:');

foreach (@signed_authors, @co_authors) {
  eval {
    my @_co_authors = $git->RUN('check-mailmap', $_);
    push @authors, @_co_authors;
  };
}

print join("\n", uniq sort @authors);