Meta/add-by: filter to add Ack/Review to submitted patches
Junio C Hamano committed
May 3, 2011 at 22:14 UTC
9adafd875a84ac08774947bdd4ecf3c0e9e9a680
1 file changed
+95
add-by
new
+95
@@ -0,0 +1,95 @@
1
+#!/usr/bin/perl
2
+
3
+use warnings;
4
+use strict;
5
+use Getopt::Long;
6
+
7
+my $byline = undef;
8
+my @more;
9
+my $append;
10
+my $debug;
11
+
12
+sub find_author {
13
+ my $map = shift;
14
+ for my $name (@_) {
15
+ my $fh;
16
+ print STDERR "Checking <$name>..."
17
+ if ($debug);
18
+ if (!open($fh, "-|",
19
+ qw(git log -1 --no-merges),
20
+ '--format=%an <%ae>',
21
+ "--author=$name",
22
+ "--all")) {
23
+ print STDERR "opening pipe to read from git log failed\n"
24
+ if ($debug);
25
+ $map->{$name} = $name;
26
+ next;
27
+ }
28
+ my $line = <$fh>;
29
+ if ($line) {
30
+ chomp $line;
31
+ print STDERR "read <$line> from git log\n"
32
+ if ($debug);
33
+ $map->{$name} = $line;
34
+ } else {
35
+ print STDERR "read false ($line) from git log\n"
36
+ if ($debug);
37
+ $map->{$name} = $name;
38
+ }
39
+ }
40
+}
41
+
42
+sub accumulate {
43
+ push @more, [@_];
44
+}
45
+
46
+sub add_more_bylines {
47
+ if (@more && !defined $append) {
48
+ my %names = map { $_->[1] => 1 } @more;
49
+ my %map = ();
50
+ my @append;
51
+ find_author(\%map, keys (%names));
52
+ for (@more) {
53
+ my ($tag, $name) = @$_;
54
+ $tag = ucfirst($tag);
55
+ push @append, "$tag: $map{$name}";
56
+ }
57
+ if (@append) {
58
+ $append = join("\n", @append) . "\n";
59
+ } else {
60
+ $append = "";
61
+ }
62
+ }
63
+ print $append;
64
+}
65
+
66
+my $check_only;
67
+
68
+exit 1 unless (GetOptions("signed-off-by=s" => \&accumulate,
69
+ "acked-by=s" => \&accumulate,
70
+ "reviewed-by=s" => \&accumulate,
71
+ "tested-by=s" => \&accumulate,
72
+ "helped-by=s" => \&accumulate,
73
+ "check-only!" => \$check_only,
74
+ "debug!" => \$debug,
75
+ ));
76
+
77
+if ($check_only) {
78
+ add_more_bylines();
79
+ exit 0;
80
+}
81
+
82
+while (<>) {
83
+ if (/^[-A-Za-z]+-by: /) {
84
+ $byline = 1;
85
+ } elsif ($byline) {
86
+ add_more_bylines();
87
+ $byline = undef;
88
+ } else {
89
+ $byline = undef;
90
+ }
91
+ print;
92
+}
93
+if ($byline) {
94
+ add_more_bylines();
95
+}