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 = ", ";
37 my $from_filename = 0;
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' => \
$from_filename,
76 'v|version' => \
$version,
80 die "$P: invalid argument\n";
95 die "$P: argument missing: patchfile or -f file please\n";
98 my $selections = $email + $scm + $status + $subsystem + $web;
99 if ($selections == 0) {
101 die "$P: Missing required option: email, scm, status, subsystem or web\n";
104 if ($email && ($email_maintainer + $email_list + $email_subscriber_list
105 + $email_git + $email_git_penguin_chiefs) == 0) {
107 die "$P: Please select at least 1 email option\n";
110 if (!top_of_kernel_tree
($lk_path)) {
111 die "$P: The current directory does not appear to be "
112 . "a linux kernel source tree.\n";
115 ## Read MAINTAINERS for type/value pairs
118 open(MAINT
, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
122 if ($line =~ m/^(\C):\s*(.*)/) {
126 ##Filename pattern matching
127 if ($type eq "F" || $type eq "X") {
128 $value =~ s@\
.@
\\\
.@g; ##Convert . to \.
129 $value =~ s/\*/\.\*/g; ##Convert * to .*
130 $value =~ s/\?/\./g; ##Convert ? to .
132 push(@typevalue, "$type:$value");
133 } elsif (!/^(\s)*$/) {
135 push(@typevalue, $line);
140 ## use the filenames on the command line or find the filenames in the patchfiles
144 foreach my $file (@ARGV) {
145 next if ((-d
$file));
147 die "$P: file '${file}' not found\n";
149 if ($from_filename) {
152 my $file_cnt = @files;
153 open(PATCH
, "<$file") or die "$P: Can't open ${file}\n";
155 if (m/^\+\+\+\s+(\S+)/) {
157 $filename =~ s@
^[^/]*/@@
;
159 push(@files, $filename);
163 if ($file_cnt == @files) {
164 die "$P: file '${file}' doesn't appear to be a patch. "
165 . "Add -f to options?\n";
167 @files = sort_and_uniq
(@files);
177 # Find responsible parties
179 foreach my $file (@files) {
181 #Do not match excluded file patterns
184 foreach my $line (@typevalue) {
185 if ($line =~ m/^(\C):(.*)/) {
189 if (file_match_pattern
($file, $value)) {
198 foreach my $line (@typevalue) {
199 if ($line =~ m/^(\C):(.*)/) {
203 if (file_match_pattern
($file, $value)) {
204 add_categories
($tvi);
212 if ($email && $email_git) {
213 recent_git_signoffs
($file);
218 if ($email_git_penguin_chiefs) {
219 foreach my $chief (@penguin_chief) {
220 if ($chief =~ m/^(.*):(.*)/) {
223 if ($email_usename) {
224 push(@email_to, format_email
($chief_name, $chief_addr));
226 push(@email_to, $chief_addr);
233 my $address_cnt = @email_to;
234 if ($address_cnt == 0 && $email_list) {
235 push(@email_to, "linux-kernel\@vger.kernel.org");
238 #Don't sort email address list, but do remove duplicates
239 @email_to = uniq
(@email_to);
244 @scm = sort_and_uniq
(@scm);
249 @status = sort_and_uniq
(@status);
254 @subsystem = sort_and_uniq
(@subsystem);
259 @web = sort_and_uniq
(@web);
265 sub file_match_pattern
{
266 my ($file, $pattern) = @_;
267 if (substr($pattern, -1) eq "/") {
268 if ($file =~ m@
^$pattern@
) {
272 if ($file =~ m@
^$pattern@
) {
273 my $s1 = ($file =~ tr@
/@@
);
274 my $s2 = ($pattern =~ tr@
/@@
);
285 usage: $P [options] patchfile
289 MAINTAINER field selection options:
290 --email => print email address(es) if any
291 --git => include recent git \*-by: signers
292 --git-chief-penguins => include ${penguin_chiefs}
293 --git-min-signatures => number of signatures required (default: 1)
294 --git-max-maintainers => maximum maintainers to add (default: 5)
295 --git-since => git history to use (default: 1-year-ago)
296 --m => include maintainer(s) if any
297 --n => include name 'Full Name <addr\@domain.tld>'
298 --l => include list(s) if any
299 --s => include subscriber only list(s) if any
300 --scm => print SCM tree(s) if any
301 --status => print status if any
302 --subsystem => print subsystem name if any
303 --web => print website(s) if any
306 --separator [, ] => separator for multiple entries on 1 line
307 --multiline => print 1 entry per line
310 [--email --git --m --l --multiline]
313 --version -> show version
314 --help => show this help information
319 sub top_of_kernel_tree
{
322 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
325 if ( (-f
"${lk_path}COPYING")
326 && (-f
"${lk_path}CREDITS")
327 && (-f
"${lk_path}Kbuild")
328 && (-f
"${lk_path}MAINTAINERS")
329 && (-f
"${lk_path}Makefile")
330 && (-f
"${lk_path}README")
331 && (-d
"${lk_path}Documentation")
332 && (-d
"${lk_path}arch")
333 && (-d
"${lk_path}include")
334 && (-d
"${lk_path}drivers")
335 && (-d
"${lk_path}fs")
336 && (-d
"${lk_path}init")
337 && (-d
"${lk_path}ipc")
338 && (-d
"${lk_path}kernel")
339 && (-d
"${lk_path}lib")
340 && (-d
"${lk_path}scripts")) {
347 my ($name, $email) = @_;
349 $name =~ s/^\s+|\s+$//g;
350 $email =~ s/^\s+|\s+$//g;
352 my $formatted_email = "";
354 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
355 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
356 $formatted_email = "\"${name}\"\ \<${email}\>";
358 $formatted_email = "${name} \<${email}\>";
360 return $formatted_email;
367 while ($index >= 0) {
368 my $tv = $typevalue[$index];
369 if ($tv =~ m/^(\C):(.*)/) {
373 my $subscr = $pvalue;
374 if ($subscr =~ m/\s*\(subscribers-only\)/) {
375 if ($email_subscriber_list) {
376 $subscr =~ s/\s*\(subscribers-only\)//g;
377 push(@email_to, $subscr);
381 push(@email_to, $pvalue);
384 } elsif ($ptype eq "M") {
385 if ($email_maintainer) {
387 my $tv = $typevalue[$index - 1];
388 if ($tv =~ m/^(\C):(.*)/) {
389 if ($1 eq "P" && $email_usename) {
390 push(@email_to, format_email
($2, $pvalue));
392 push(@email_to, $pvalue);
396 push(@email_to, $pvalue);
399 } elsif ($ptype eq "T") {
401 } elsif ($ptype eq "W") {
403 } elsif ($ptype eq "S") {
404 push(@status, $pvalue);
409 push(@subsystem,$tv);
418 foreach my $path (split /:/, $ENV{PATH
}) {
419 if (-e
"$path/$bin") {
427 sub recent_git_signoffs
{
436 if (which
("git") eq "") {
437 die("$P: git not found. Add --nogit to options?\n");
440 $cmd = "git log --since=${email_git_since} -- ${file}";
441 $cmd .= " | grep -Pi \"^[-_ a-z]+by:.*\\\@\"";
442 if (!$email_git_penguin_chiefs) {
443 $cmd .= " | grep -Pv \"${penguin_chiefs}\"";
445 $cmd .= " | cut -f2- -d\":\"";
446 $cmd .= " | sed -e \"s/^\\s+//g\"";
447 $cmd .= " | sort | uniq -c | sort -rn";
450 $output =~ s/^\s*//gm;
452 @lines = split("\n", $output);
453 foreach my $line (@lines) {
454 if ($line =~ m/([0-9]+)\s+(.*)/) {
458 if ($sign_offs < $email_git_min_signatures ||
459 $count > $email_git_max_maintainers) {
463 die("$P: Unexpected git output: ${line}\n");
465 if ($line =~ m/(.+)<(.+)>/) {
468 $git_name =~ tr/^\"//;
469 $git_name =~ tr/^\\s*//;
470 $git_name =~ tr/\"$//;
471 $git_name =~ tr/\\s*$//;
472 if ($email_usename) {
473 push(@email_to, format_email
($git_name, $git_addr));
475 push(@email_to, $git_addr);
477 } elsif ($line =~ m/<(.+)>/) {
479 push(@email_to, $git_addr);
481 push(@email_to, $line);
491 @parms = grep(!$saw{$_}++, @parms);
499 @parms = sort @parms;
500 @parms = grep(!$saw{$_}++, @parms);
507 if ($output_multiline) {
508 foreach my $line (@parms) {
512 print(join($output_separator, @parms));