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);
178 # Find responsible parties
180 foreach my $file (@files) {
182 #Do not match excluded file patterns
185 foreach my $line (@typevalue) {
186 if ($line =~ m/^(\C):\s*(.*)/) {
190 if (file_match_pattern($file, $value)) {
199 foreach my $line (@typevalue) {
200 if ($line =~ m/^(\C):\s*(.*)/) {
204 if (file_match_pattern($file, $value)) {
205 add_categories($tvi);
213 if ($email && $email_git) {
214 recent_git_signoffs($file);
219 if ($email_git_penguin_chiefs) {
220 foreach my $chief (@penguin_chief) {
221 if ($chief =~ m/^(.*):(.*)/) {
224 if ($email_usename) {
225 push(@email_to, format_email($chief_name, $chief_addr));
227 push(@email_to, $chief_addr);
233 if ($email || $email_list) {
236 @to = (@to, @email_to);
240 push(@list_to, "linux-kernel\@vger.kernel.org");
241 @to = (@to, @list_to);
248 @scm = sort_and_uniq(@scm);
253 @status = sort_and_uniq(@status);
258 @subsystem = sort_and_uniq(@subsystem);
263 @web = sort_and_uniq(@web);
269 sub file_match_pattern {
270 my ($file, $pattern) = @_;
271 if (substr($pattern, -1) eq "/") {
272 if ($file =~ m@^$pattern@) {
276 if ($file =~ m@^$pattern@) {
277 my $s1 = ($file =~ tr@/@@);
278 my $s2 = ($pattern =~ tr@/@@);
289 usage: $P [options] patchfile
293 MAINTAINER field selection options:
294 --email => print email address(es) if any
295 --git => include recent git \*-by: signers
296 --git-chief-penguins => include ${penguin_chiefs}
297 --git-min-signatures => number of signatures required (default: 1)
298 --git-max-maintainers => maximum maintainers to add (default: 5)
299 --git-since => git history to use (default: 1-year-ago)
300 --m => include maintainer(s) if any
301 --n => include name 'Full Name <addr\@domain.tld>'
302 --l => include list(s) if any
303 --s => include subscriber only list(s) if any
304 --scm => print SCM tree(s) if any
305 --status => print status if any
306 --subsystem => print subsystem name if any
307 --web => print website(s) if any
310 --separator [, ] => separator for multiple entries on 1 line
311 --multiline => print 1 entry per line
314 [--email --git --m --n --l --multiline]
317 --version -> show version
318 --help => show this help information
323 sub top_of_kernel_tree {
326 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
329 if ( (-f "${lk_path}COPYING")
330 && (-f "${lk_path}CREDITS")
331 && (-f "${lk_path}Kbuild")
332 && (-f "${lk_path}MAINTAINERS")
333 && (-f "${lk_path}Makefile")
334 && (-f "${lk_path}README")
335 && (-d "${lk_path}Documentation")
336 && (-d "${lk_path}arch")
337 && (-d "${lk_path}include")
338 && (-d "${lk_path}drivers")
339 && (-d "${lk_path}fs")
340 && (-d "${lk_path}init")
341 && (-d "${lk_path}ipc")
342 && (-d "${lk_path}kernel")
343 && (-d "${lk_path}lib")
344 && (-d "${lk_path}scripts")) {
351 my ($name, $email) = @_;
353 $name =~ s/^\s+|\s+$//g;
354 $email =~ s/^\s+|\s+$//g;
356 my $formatted_email = "";
358 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
359 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
360 $formatted_email = "\"${name}\"\ \<${email}\>";
362 $formatted_email = "${name} \<${email}\>";
364 return $formatted_email;
371 while ($index >= 0) {
372 my $tv = $typevalue[$index];
373 if ($tv =~ m/^(\C):\s*(.*)/) {
377 my $list_address = $pvalue;
378 my $list_additional = "";
379 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
381 $list_additional = $2;
383 if ($list_additional =~ m/subscribers-only/) {
384 if ($email_subscriber_list) {
385 push(@list_to, $list_address);
389 push(@list_to, $list_address);
392 } elsif ($ptype eq "M") {
393 if ($email_maintainer) {
395 my $tv = $typevalue[$index - 1];
396 if ($tv =~ m/^(\C):\s*(.*)/) {
397 if ($1 eq "P" && $email_usename) {
398 push(@email_to, format_email($2, $pvalue));
400 push(@email_to, $pvalue);
404 push(@email_to, $pvalue);
407 } elsif ($ptype eq "T") {
409 } elsif ($ptype eq "W") {
411 } elsif ($ptype eq "S") {
412 push(@status, $pvalue);
417 push(@subsystem,$tv);
426 foreach my $path (split /:/, $ENV{PATH}) {
427 if (-e "$path/$bin") {
435 sub recent_git_signoffs {
444 if (which("git") eq "") {
445 die("$P: git not found. Add --nogit to options?\n");
448 $cmd = "git log --since=${email_git_since} -- ${file}";
449 $cmd .= " | grep -Pi \"^[-_ a-z]+by:.*\\\@\"";
450 if (!$email_git_penguin_chiefs) {
451 $cmd .= " | grep -Pv \"${penguin_chiefs}\"";
453 $cmd .= " | cut -f2- -d\":\"";
454 $cmd .= " | sed -e \"s/^\\s+//g\"";
455 $cmd .= " | sort | uniq -c | sort -rn";
458 $output =~ s/^\s*//gm;
460 @lines = split("\n", $output);
461 foreach my $line (@lines) {
462 if ($line =~ m/([0-9]+)\s+(.*)/) {
466 if ($sign_offs < $email_git_min_signatures ||
467 $count > $email_git_max_maintainers) {
471 die("$P: Unexpected git output: ${line}\n");
473 if ($line =~ m/(.+)<(.+)>/) {
476 $git_name =~ tr/^\"//;
477 $git_name =~ tr/^\\s*//;
478 $git_name =~ tr/\"$//;
479 $git_name =~ tr/\\s*$//;
480 if ($email_usename) {
481 push(@email_to, format_email($git_name, $git_addr));
483 push(@email_to, $git_addr);
485 } elsif ($line =~ m/<(.+)>/) {
487 push(@email_to, $git_addr);
489 push(@email_to, $line);
499 @parms = grep(!$saw{$_}++, @parms);
507 @parms = sort @parms;
508 @parms = grep(!$saw{$_}++, @parms);
515 if ($output_multiline) {
516 foreach my $line (@parms) {
520 print(join($output_separator, @parms));