contacts: validate hunk length earlier
[gitweb.git] / contrib / contacts / git-contacts
index 4553add0a6e0a7619b1c6b092d02bea126a14e0b..4fbb2ef85a76743780cfa1f81d0f9cdc75362e63 100755 (executable)
@@ -60,8 +60,6 @@ sub import_commits {
 
 sub get_blame {
        my ($commits, $source, $start, $len, $from) = @_;
-       $len = 1 unless defined($len);
-       return if $len == 0;
        open my $f, '-|',
                qw(git blame --porcelain -C), '-L', "$start,+$len",
                '--since', $since, "$from^", '--', $source or die;
@@ -90,7 +88,8 @@ sub scan_patches {
                } elsif (/^--- /) {
                        die "Cannot parse hunk source: $_\n";
                } elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
-                       get_blame($commits, $source, $1, $2, $id);
+                       my $len = defined($2) ? $2 : 1;
+                       get_blame($commits, $source, $1, $len, $id) if $len;
                }
        }
 }
@@ -133,6 +132,23 @@ sub scan_rev_args {
        close $f;
 }
 
+sub mailmap_contacts {
+       my ($contacts) = @_;
+       my %mapped;
+       my $pid = open2 my $reader, my $writer, qw(git check-mailmap --stdin);
+       for my $contact (keys(%$contacts)) {
+               print $writer "$contact\n";
+               my $canonical = <$reader>;
+               chomp $canonical;
+               $mapped{$canonical} += $contacts->{$contact};
+       }
+       close $reader;
+       close $writer;
+       waitpid($pid, 0);
+       die "git-check-mailmap error: $?\n" if $?;
+       return \%mapped;
+}
+
 if (!@ARGV) {
        die "No input revisions or patch files\n";
 }
@@ -161,6 +177,7 @@ for my $commit (values %commits) {
                $contacts->{$contact}++;
        }
 }
+$contacts = mailmap_contacts($contacts);
 
 my $ncommits = scalar(keys %commits);
 for my $contact (keys %$contacts) {