Meta/cook: notice 'I think this is ready'
[alt-git.git] / add-by
blob4e7983e3a239680aed34f11f46db79706692d58d
1 #!/usr/bin/perl
3 use warnings;
4 use strict;
5 use Getopt::Long;
7 sub parsing () { 1; }
8 sub waiting () { 2; }
9 my $state = parsing;
11 my @more;
12 my $append;
13 my $debug;
15 sub find_author {
16 my $map = shift;
17 for my $name (@_) {
18 my $fh;
19 print STDERR "Checking <$name>..."
20 if ($debug);
21 if (!open($fh, "-|",
22 qw(git log -1 --no-merges),
23 '--format=%an <%ae>',
24 "--author=$name",
25 "--all")) {
26 print STDERR "opening pipe to read from git log failed\n"
27 if ($debug);
28 $map->{$name} = $name;
29 next;
31 my $line = <$fh>;
32 if ($line) {
33 chomp $line;
34 print STDERR "read <$line> from git log\n"
35 if ($debug);
36 $map->{$name} = $line;
37 } else {
38 print STDERR "read false ($line) from git log\n"
39 if ($debug);
40 $map->{$name} = $name;
45 sub accumulate {
46 push @more, [@_];
49 sub add_more_bylines {
50 if (!defined $append) {
51 my %names = map { $_->[1] => 1 } @more;
52 my %map = ();
53 my @append;
54 find_author(\%map, keys (%names));
55 for (@more) {
56 my ($tag, $name) = @$_;
57 $tag = ucfirst($tag);
58 push @append, "$tag: $map{$name}";
60 if (@append) {
61 $append = join("\n", @append) . "\n";
62 } else {
63 $append = "";
66 print $append;
69 my $check_only;
71 exit 1 unless (GetOptions("signed-off-by=s" => \&accumulate,
72 "acked-by=s" => \&accumulate,
73 "reviewed-by=s" => \&accumulate,
74 "tested-by=s" => \&accumulate,
75 "helped-by=s" => \&accumulate,
76 "check-only!" => \$check_only,
77 "debug!" => \$debug,
78 ));
80 if ($check_only) {
81 add_more_bylines();
82 exit 0;
85 while (<>) {
86 if ($state == parsing) {
87 if (/^[-A-Za-z]+-by: /i || /^Cc: /i) {
88 $state = waiting;
90 } elsif ($state == waiting) {
91 if (/^[-A-Za-z]+-by: /i || /^Cc: /i) {
92 $state = waiting;
93 } else {
94 add_more_bylines();
95 $state = parsing;
98 print;