#!/usr/bin/env perl use 5.016; use warnings; use autodie; use Encode qw(decode); use List::Util qw(any); use JSON::PP; my $identities = decode_json(scalar ); my %identity_map; for my $i (0 .. $#$identities) { for my $identifier (@{$identities->[$i]}) { my ($name, $mail) = @$identifier; if (exists $identity_map{$name}{$mail}) { die "Duplicate identifier '$identifier'\n"; } $identity_map{$name}{$mail} = $i; } } sub identify { my $name = shift // ''; my $mail = shift // ''; if (!length($name) && !length($mail)) { return undef; } my $index = $identity_map{$name}{$mail}; return defined($index) ? int($index) : undef; } my %commit_map; while () { my $commit = decode_json($_); $commit_map{$commit->{hash}} = { %$commit, author => identify(@{$commit}{ 'author_name', 'author_mail'}), committer => identify(@{$commit}{'committer_name', 'committer_mail'}), }; } print JSON::PP->new->utf8->pretty->canonical->encode({ identities => $identities, commits => \%commit_map, }); __END__ =head1 NAME assocman - associate commits with merged identities =head1 SYNOPSIS Just run this with C, it needs the output from both C and C, which is non-trivial to do with pipelines on the command line. =head1 DESCRIPTION The input on stdin takes the form of one JSON object per line, the first one being the C output and the rest being the C output. The output on stdout will be a pretty-printed JSON object, see F<../README.md> for the detailed description of the structure. If a single artifact cannot be clearly mapped to an identity or if an author or committer resolves to more than one identity, this will die, overwhelmed from all the ambiguity. =cut