2 # (c) 2007, Joe Perches <joe@perches.com>
3 # created from checkpatch.pl
5 # Print selected MAINTAINERS information for
6 # the files modified in a patch or for a file
8 # usage: perl scripts/get_maintainers.pl [OPTIONS] <patch>
9 # perl scripts/get_maintainers.pl [OPTIONS] -f <file>
11 # Licensed under the terms of the GNU GPL License version 2
18 use Getopt
::Long
qw(:config no_auto_abbrev);
22 my $email_usename = 1;
23 my $email_maintainer = 1;
25 my $email_subscriber_list = 0;
27 my $email_git_penguin_chiefs = 0;
28 my $email_git_min_signatures = 1;
29 my $email_git_max_maintainers = 5;
30 my $email_git_since = "1-year-ago";
31 my $output_multiline = 1;
32 my $output_separator = ", ";
43 my @penguin_chief = ();
44 push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org");
45 #Andrew wants in on most everything - 2009/01/14
46 #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org");
48 my @penguin_chief_names = ();
49 foreach my $chief (@penguin_chief) {
50 if ($chief =~ m/^(.*):(.*)/) {
53 push(@penguin_chief_names, $chief_name);
56 my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)";
60 'git!' => \
$email_git,
61 'git-chief-penguins!' => \
$email_git_penguin_chiefs,
62 'git-min-signatures=i' => \
$email_git_min_signatures,
63 'git-max-maintainers=i' => \
$email_git_max_maintainers,
64 'git-since=s' => \
$email_git_since,
65 'm!' => \
$email_maintainer,
66 'n!' => \
$email_usename,
68 's!' => \
$email_subscriber_list,
69 'multiline!' => \
$output_multiline,
70 'separator=s' => \
$output_separator,
71 'subsystem!' => \
$subsystem,
72 'status!' => \
$status,
75 'f|file' => \
$onefile,
76 'v|version' => \
$version,
80 die "$P: invalid argument\n";
93 my $infile = $ARGV[0];
97 die "$P: argument missing: patchfile or -f file please\n";
100 my $selections = $email + $scm + $status + $subsystem + $web;
101 if ($selections == 0) {
103 die "$P: Missing required option: email, scm, status, subsystem or web\n";
106 if ($email && ($email_maintainer + $email_list + $email_subscriber_list
107 + $email_git + $email_git_penguin_chiefs) == 0) {
109 die "$P: Please select at least 1 email option\n";
112 if (!top_of_kernel_tree
($lk_path)) {
113 die "$P: The current directory does not appear to be "
114 . "a linux kernel source tree.\n";
117 ## Read MAINTAINERS for type/value pairs
120 open(MAINT
, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
124 if ($line =~ m/^(\C):\s*(.*)/) {
128 ##Filename pattern matching
129 if ($type eq "F" || $type eq "X") {
130 $value =~ s@\
.@
\\\
.@g; ##Convert . to \.
131 $value =~ s/\*/\.\*/g; ##Convert * to .*
132 $value =~ s/\?/\./g; ##Convert ? to .
134 push(@typevalue, "$type:$value");
135 } elsif (!/^(\s)*$/) {
137 push(@typevalue, $line);
142 ## use the filename on the command line or find the filenames in the patchfile
148 die "$P: file '${infile}' not found\n";
150 push(@files, $infile);
152 open(PATCH
, "<$infile") or die "$P: Can't open ${infile}\n";
154 if (m/^\+\+\+\s+(\S+)/) {
156 $file =~ s@
^[^/]*/@@
;
162 my $file_cnt = @files;
163 if ($file_cnt == 0) {
164 print STDERR
"$P: file '${infile}' doesn't appear to be a patch. "
165 . "Add -f to options?\n";
167 @files = sort_and_uniq
(@files);
176 # Find responsible parties
178 foreach my $file (@files) {
180 #Do not match excluded file patterns
183 foreach my $line (@typevalue) {
184 if ($line =~ m/^(\C):(.*)/) {
188 if (file_match_pattern
($file, $value)) {
197 foreach my $line (@typevalue) {
198 if ($line =~ m/^(\C):(.*)/) {
202 if (file_match_pattern
($file, $value)) {
203 add_categories
($tvi);
212 recent_git_signoffs
($file);
217 if ($email_git_penguin_chiefs) {
218 foreach my $chief (@penguin_chief) {
219 if ($chief =~ m/^(.*):(.*)/) {
222 if ($email_usename) {
223 push(@email_to, format_email
($chief_name, $chief_addr));
225 push(@email_to, $chief_addr);
232 my $address_cnt = @email_to;
233 if ($address_cnt == 0 && $email_list) {
234 push(@email_to, "linux-kernel\@vger.kernel.org");
237 #Don't sort email address list, but do remove duplicates
238 @email_to = uniq
(@email_to);
244 @scm = sort_and_uniq
(@scm);
251 @status = sort_and_uniq
(@status);
258 @subsystem = sort_and_uniq
(@subsystem);
265 @web = sort_and_uniq
(@web);
272 sub file_match_pattern
{
273 my ($file, $pattern) = @_;
274 if (substr($pattern, -1) eq "/") {
275 if ($file =~ m@
^$pattern@
) {
279 if ($file =~ m@
^$pattern@
) {
280 my $s1 = ($file =~ tr@
/@@
);
281 my $s2 = ($pattern =~ tr@
/@@
);
292 usage: $P [options] patchfile
296 MAINTAINER field selection options:
297 --email => print email address(es) if any
298 --git => include recent git \*-by: signers
299 --git-chief-penguins => include ${penguin_chiefs}
300 --git-min-signatures => number of signatures required (default: 1)
301 --git-max-maintainers => maximum maintainers to add (default: 5)
302 --git-since => git history to use (default: 1-year-ago)
303 --m => include maintainer(s) if any
304 --n => include name 'Full Name <addr\@domain.tld>'
305 --l => include list(s) if any
306 --s => include subscriber only list(s) if any
307 --scm => print SCM tree(s) if any
308 --status => print status if any
309 --subsystem => print subsystem name if any
310 --web => print website(s) if any
313 --separator [, ] => separator for multiple entries on 1 line
314 --multiline => print 1 entry per line
317 [--email --git --m --l --multiline]
320 --version -> show version
321 --help => show this help information
326 sub top_of_kernel_tree
{
329 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
332 if ( (-f
"${lk_path}COPYING")
333 && (-f
"${lk_path}CREDITS")
334 && (-f
"${lk_path}Kbuild")
335 && (-f
"${lk_path}MAINTAINERS")
336 && (-f
"${lk_path}Makefile")
337 && (-f
"${lk_path}README")
338 && (-d
"${lk_path}Documentation")
339 && (-d
"${lk_path}arch")
340 && (-d
"${lk_path}include")
341 && (-d
"${lk_path}drivers")
342 && (-d
"${lk_path}fs")
343 && (-d
"${lk_path}init")
344 && (-d
"${lk_path}ipc")
345 && (-d
"${lk_path}kernel")
346 && (-d
"${lk_path}lib")
347 && (-d
"${lk_path}scripts")) {
354 my ($name, $email) = @_;
356 $name =~ s/^\s+|\s+$//g;
357 $email =~ s/^\s+|\s+$//g;
359 my $formatted_email = "";
361 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
362 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
363 $formatted_email = "\"${name}\"\ \<${email}\>";
365 $formatted_email = "${name} \<${email}\>";
367 return $formatted_email;
374 while ($index >= 0) {
375 my $tv = $typevalue[$index];
376 if ($tv =~ m/^(\C):(.*)/) {
380 my $subscr = $pvalue;
381 if ($subscr =~ m/\s*\(subscribers-only\)/) {
382 if ($email_subscriber_list) {
383 $subscr =~ s/\s*\(subscribers-only\)//g;
384 push(@email_to, $subscr);
388 push(@email_to, $pvalue);
391 } elsif ($ptype eq "M") {
392 if ($email_maintainer) {
394 my $tv = $typevalue[$index - 1];
395 if ($tv =~ m/^(\C):(.*)/) {
396 if ($1 eq "P" && $email_usename) {
397 push(@email_to, format_email
($2, $pvalue));
399 push(@email_to, $pvalue);
403 push(@email_to, $pvalue);
406 } elsif ($ptype eq "T") {
408 } elsif ($ptype eq "W") {
410 } elsif ($ptype eq "S") {
411 push(@status, $pvalue);
416 push(@subsystem,$tv);
425 foreach my $path (split /:/, $ENV{PATH
}) {
426 if (-e
"$path/$bin") {
434 sub recent_git_signoffs
{
443 if (which
("git") eq "") {
444 die("$P: git not found. Add --nogit to options?\n");
447 $cmd = "git log --since=${email_git_since} -- ${file}";
448 $cmd .= " | grep -P '^ [-A-Za-z]+by:.*\\\@'";
449 if (!$email_git_penguin_chiefs) {
450 $cmd .= " | grep -E -v \"${penguin_chiefs}\"";
452 $cmd .= " | sort | uniq -c | sort -rn";
455 $output =~ s/^\s*//gm;
457 @lines = split("\n", $output);
458 foreach my $line (@lines) {
459 if ($line =~ m/([0-9]+)\s+([-A-Za-z]+by:)\s+(.*)/) {
463 if ($sign_offs < $email_git_min_signatures ||
464 $count > $email_git_max_maintainers) {
468 die("$P: Unexpected git output: ${line}\n");
470 if ($line =~ m/(.*) <(.*)>/) {
473 $git_name =~ tr/^\"//;
474 $git_name =~ tr/\"$//;
475 if ($email_usename) {
476 push(@email_to, format_email
($git_name, $git_addr));
478 push(@email_to, $git_addr);
480 } elsif ($line =~ m/<(.*)>/) {
482 push(@email_to, $git_addr);
484 push(@email_to, $line);
494 @parms = grep(!$saw{$_}++, @parms);
502 @parms = sort @parms;
503 @parms = grep(!$saw{$_}++, @parms);
510 if ($output_multiline) {
511 foreach my $line (@parms) {
515 print(join($output_separator, @parms));