3 # List people who might be interested in a patch. Useful as the argument to
4 # git-send-email --cc-cmd option, and in other situations.
6 # Usage: git contacts <file> ...
12 my $since = '5-years-ago';
14 my $labels_rx = qr/Signed-off-by|Reviewed-by|Acked-by|Cc/i;
18 my ($name, $email) = @_;
19 return "$name <$email>";
23 my ($commit, $data) = @_;
24 my $contacts = $commit->{contacts
};
26 for (split(/^/m, $data)) {
28 if (/^author ([^<>]+) <(\S+)> .+$/) {
29 $contacts->{format_contact
($1, $2)} = 1;
33 } elsif (/^$labels_rx:\s+([^<>]+)\s+<(\S+?)>$/o) {
34 $contacts->{format_contact
($1, $2)} = 1;
41 return unless %$commits;
42 my $pid = open2
my $reader, my $writer, qw(git cat-file --batch);
43 for my $id (keys(%$commits)) {
44 print $writer "$id\n";
46 if ($line =~ /^([0-9a-f]{40}) commit (\d+)/) {
47 my ($cid, $len) = ($1, $2);
48 die "expected $id but got $cid\n" unless $id eq $cid;
50 # cat-file emits newline after data, so read len+1
51 read $reader, $data, $len + 1;
52 parse_commit
($commits->{$id}, $data);
58 die "git-cat-file error: $?\n" if $?
;
62 my ($commits, $source, $start, $len, $from) = @_;
63 $len = 1 unless defined($len);
66 qw(git blame --porcelain -C), '-L', "$start,+$len",
67 '--since', $since, "$from^", '--', $source or die;
69 if (/^([0-9a-f]{40}) \d+ \d+ \d+$/) {
71 $commits->{$id} = { id
=> $id, contacts
=> {} }
80 my ($commits, $f) = @_;
83 if (/^From ([0-9a-f]{40}) Mon Sep 17 00:00:00 2001$/) {
88 if (m{^--- (?:a/(.+)|/dev/null)$}) {
91 die "Cannot parse hunk source: $_\n";
92 } elsif (/^@@ -(\d+)(?:,(\d+))?/ && $source) {
93 get_blame
($commits, $source, $1, $2, $id);
99 my ($commits, $file) = @_;
100 open my $f, '<', $file or die "read failure: $file: $!\n";
101 scan_patches
($commits, $f);
106 die "No input patch files\n";
111 scan_patch_file
(\
%commits, $_);
113 import_commits
(\
%commits);
116 for my $commit (values %commits) {
117 for my $contact (keys %{$commit->{contacts
}}) {
118 $contacts->{$contact}++;
122 my $ncommits = scalar(keys %commits);
123 for my $contact (keys %$contacts) {
124 my $percent = $contacts->{$contact} * 100 / $ncommits;
125 next if $percent < $min_percent;