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) . "\)";
58 # rfc822 - preloaded methods go here.
59 my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
60 my $rfc822_char = '[\\000-\\177]';
64 'git!' => \$email_git,
65 'git-chief-penguins!' => \$email_git_penguin_chiefs,
66 'git-min-signatures=i' => \$email_git_min_signatures,
67 'git-max-maintainers=i' => \$email_git_max_maintainers,
68 'git-since=s' => \$email_git_since,
69 'm!' => \$email_maintainer,
70 'n!' => \$email_usename,
72 's!' => \$email_subscriber_list,
73 'multiline!' => \$output_multiline,
74 'separator=s' => \$output_separator,
75 'subsystem!' => \$subsystem,
76 'status!' => \$status,
79 'f|file' => \$from_filename,
80 'v|version' => \$version,
84 die "$P: invalid argument\n";
99 die "$P: argument missing: patchfile or -f file please\n";
102 my $selections = $email + $scm + $status + $subsystem + $web;
103 if ($selections == 0) {
105 die "$P: Missing required option: email, scm, status, subsystem or web\n";
108 if ($email && ($email_maintainer + $email_list + $email_subscriber_list
109 + $email_git + $email_git_penguin_chiefs) == 0) {
111 die "$P: Please select at least 1 email option\n";
114 if (!top_of_kernel_tree($lk_path)) {
115 die "$P: The current directory does not appear to be "
116 . "a linux kernel source tree.\n";
119 ## Read MAINTAINERS for type/value pairs
122 open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
126 if ($line =~ m/^(\C):\s*(.*)/) {
130 ##Filename pattern matching
131 if ($type eq "F" || $type eq "X") {
132 $value =~ s@\.@\\\.@g; ##Convert . to \.
133 $value =~ s/\*/\.\*/g; ##Convert * to .*
134 $value =~ s/\?/\./g; ##Convert ? to .
136 push(@typevalue, "$type:$value");
137 } elsif (!/^(\s)*$/) {
139 push(@typevalue, $line);
144 ## use the filenames on the command line or find the filenames in the patchfiles
148 foreach my $file (@ARGV) {
149 next if ((-d $file));
151 die "$P: file '${file}' not found\n";
153 if ($from_filename) {
156 my $file_cnt = @files;
157 open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
159 if (m/^\+\+\+\s+(\S+)/) {
161 $filename =~ s@^[^/]*/@@;
163 push(@files, $filename);
167 if ($file_cnt == @files) {
168 die "$P: file '${file}' doesn't appear to be a patch. "
169 . "Add -f to options?\n";
171 @files = sort_and_uniq(@files);
182 # Find responsible parties
184 foreach my $file (@files) {
186 #Do not match excluded file patterns
189 foreach my $line (@typevalue) {
190 if ($line =~ m/^(\C):\s*(.*)/) {
194 if (file_match_pattern($file, $value)) {
203 foreach my $line (@typevalue) {
204 if ($line =~ m/^(\C):\s*(.*)/) {
208 if (file_match_pattern($file, $value)) {
209 add_categories($tvi);
217 if ($email && $email_git) {
218 recent_git_signoffs($file);
224 foreach my $chief (@penguin_chief) {
225 if ($chief =~ m/^(.*):(.*)/) {
227 if ($email_usename) {
228 $email_address = format_email($1, $2);
232 if ($email_git_penguin_chiefs) {
233 push(@email_to, $email_address);
235 @email_to = grep(!/${email_address}/, @email_to);
241 if ($email || $email_list) {
244 @to = (@to, @email_to);
247 @to = (@to, @list_to);
253 @scm = sort_and_uniq(@scm);
258 @status = sort_and_uniq(@status);
263 @subsystem = sort_and_uniq(@subsystem);
268 @web = sort_and_uniq(@web);
274 sub file_match_pattern {
275 my ($file, $pattern) = @_;
276 if (substr($pattern, -1) eq "/") {
277 if ($file =~ m@^$pattern@) {
281 if ($file =~ m@^$pattern@) {
282 my $s1 = ($file =~ tr@/@@);
283 my $s2 = ($pattern =~ tr@/@@);
294 usage: $P [options] patchfile
298 MAINTAINER field selection options:
299 --email => print email address(es) if any
300 --git => include recent git \*-by: signers
301 --git-chief-penguins => include ${penguin_chiefs}
302 --git-min-signatures => number of signatures required (default: 1)
303 --git-max-maintainers => maximum maintainers to add (default: 5)
304 --git-since => git history to use (default: 1-year-ago)
305 --m => include maintainer(s) if any
306 --n => include name 'Full Name <addr\@domain.tld>'
307 --l => include list(s) if any
308 --s => include subscriber only list(s) if any
309 --scm => print SCM tree(s) if any
310 --status => print status if any
311 --subsystem => print subsystem name if any
312 --web => print website(s) if any
315 --separator [, ] => separator for multiple entries on 1 line
316 --multiline => print 1 entry per line
319 [--email --git --m --n --l --multiline]
322 --version => show version
323 --help => show this help information
328 sub top_of_kernel_tree {
331 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
334 if ( (-f "${lk_path}COPYING")
335 && (-f "${lk_path}CREDITS")
336 && (-f "${lk_path}Kbuild")
337 && (-f "${lk_path}MAINTAINERS")
338 && (-f "${lk_path}Makefile")
339 && (-f "${lk_path}README")
340 && (-d "${lk_path}Documentation")
341 && (-d "${lk_path}arch")
342 && (-d "${lk_path}include")
343 && (-d "${lk_path}drivers")
344 && (-d "${lk_path}fs")
345 && (-d "${lk_path}init")
346 && (-d "${lk_path}ipc")
347 && (-d "${lk_path}kernel")
348 && (-d "${lk_path}lib")
349 && (-d "${lk_path}scripts")) {
356 my ($name, $email) = @_;
358 $name =~ s/^\s+|\s+$//g;
359 $name =~ s/^\"|\"$//g;
360 $email =~ s/^\s+|\s+$//g;
362 my $formatted_email = "";
364 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
365 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
366 $formatted_email = "\"${name}\"\ \<${email}\>";
368 $formatted_email = "${name} \<${email}\>";
370 return $formatted_email;
377 while ($index >= 0) {
378 my $tv = $typevalue[$index];
379 if ($tv =~ m/^(\C):\s*(.*)/) {
383 my $list_address = $pvalue;
384 my $list_additional = "";
385 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
387 $list_additional = $2;
389 if ($list_additional =~ m/subscribers-only/) {
390 if ($email_subscriber_list) {
391 push(@list_to, $list_address);
395 push(@list_to, $list_address);
398 } elsif ($ptype eq "M") {
399 if ($email_maintainer) {
400 push_email_addresses($pvalue);
402 } elsif ($ptype eq "T") {
404 } elsif ($ptype eq "W") {
406 } elsif ($ptype eq "S") {
407 push(@status, $pvalue);
412 push(@subsystem,$tv);
418 sub push_email_address {
419 my ($email_address) = @_;
422 if ($email_address =~ m/([^<]+)<(.*\@.*)>$/) {
427 if ($email_usename && $email_name) {
428 push(@email_to, format_email($email_name, $email_address));
430 push(@email_to, $email_address);
434 sub push_email_addresses {
437 my @address_list = ();
439 if (@address_list = rfc822_validlist($address)) {
440 my $array_count = shift(@address_list);
441 while (my $entry = shift(@address_list)) {
442 push_email_address($entry);
451 foreach my $path (split(/:/, $ENV{PATH})) {
452 if (-e "$path/$bin") {
460 sub recent_git_signoffs {
469 if (which("git") eq "") {
470 warn("$P: git not found. Add --nogit to options?\n");
474 warn("$P: .git repository not found.\n");
475 warn("Use a .git repository for better results.\n");
476 warn("ie: git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n");
480 $cmd = "git log --since=${email_git_since} -- ${file}";
481 $cmd .= " | grep -Ei \"^[-_ a-z]+by:.*\\\@.*\$\"";
482 if (!$email_git_penguin_chiefs) {
483 $cmd .= " | grep -Ev \"${penguin_chiefs}\"";
485 $cmd .= " | cut -f2- -d\":\"";
486 $cmd .= " | sort | uniq -c | sort -rn";
489 $output =~ s/^\s*//gm;
491 @lines = split("\n", $output);
492 foreach my $line (@lines) {
493 if ($line =~ m/([0-9]+)\s+(.*)/) {
497 if ($sign_offs < $email_git_min_signatures ||
498 $count > $email_git_max_maintainers) {
502 die("$P: Unexpected git output: ${line}\n");
504 if ($line =~ m/(.+)<(.+)>/) {
507 if ($email_usename) {
508 push(@email_to, format_email($git_name, $git_addr));
510 push(@email_to, $git_addr);
512 } elsif ($line =~ m/<(.+)>/) {
514 push(@email_to, $git_addr);
516 push(@email_to, $line);
525 @parms = grep(!$saw{$_}++, @parms);
533 @parms = sort @parms;
534 @parms = grep(!$saw{$_}++, @parms);
541 if ($output_multiline) {
542 foreach my $line (@parms) {
546 print(join($output_separator, @parms));
554 # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
555 # comment. We must allow for rfc822_lwsp (or comments) after each of these.
556 # This regexp will only work on addresses which have had comments stripped
557 # and replaced with rfc822_lwsp.
559 my $specials = '()<>@,;:\\\\".\\[\\]';
560 my $controls = '\\000-\\037\\177';
562 my $dtext = "[^\\[\\]\\r\\\\]";
563 my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
565 my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
567 # Use zero-width assertion to spot the limit of an atom. A simple
568 # $rfc822_lwsp* causes the regexp engine to hang occasionally.
569 my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
570 my $word = "(?:$atom|$quoted_string)";
571 my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
573 my $sub_domain = "(?:$atom|$domain_literal)";
574 my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
576 my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
578 my $phrase = "$word*";
579 my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
580 my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
581 my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
583 my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
584 my $address = "(?:$mailbox|$group)";
586 return "$rfc822_lwsp*$address";
589 sub rfc822_strip_comments {
591 # Recursively remove comments, and replace with a single space. The simpler
592 # regexps in the Email Addressing FAQ are imperfect - they will miss escaped
593 # chars in atoms, for example.
595 while ($s =~ s/^((?:[^"\\]|\\.)*
596 (?:"(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*)*)
597 \((?:[^()\\]|\\.)*\)/$1 /osx) {}
601 # valid: returns true if the parameter is an RFC822 valid address
603 sub rfc822_valid ($) {
604 my $s = rfc822_strip_comments(shift);
607 $rfc822re = make_rfc822re();
610 return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
613 # validlist: In scalar context, returns true if the parameter is an RFC822
614 # valid list of addresses.
616 # In list context, returns an empty list on failure (an invalid
617 # address was found); otherwise a list whose first element is the
618 # number of addresses found and whose remaining elements are the
619 # addresses. This is needed to disambiguate failure (invalid)
620 # from success with no addresses found, because an empty string is
623 sub rfc822_validlist ($) {
624 my $s = rfc822_strip_comments(shift);
627 $rfc822re = make_rfc822re();
629 # * null list items are valid according to the RFC
630 # * the '1' business is to aid in distinguishing failure from no results
633 if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
634 $s =~ m/^$rfc822_char*$/) {
635 while($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
638 return wantarray ? (scalar(@r), @r) : 1;
641 return wantarray ? () : 0;