]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - scripts/get_maintainer.pl
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_min_percent = 5;
31 my $email_git_since = "1-year-ago";
32 my $email_git_blame = 0;
33 my $output_multiline = 1;
34 my $output_separator = ", ";
39 my $from_filename = 0;
40 my $pattern_depth = 0;
46 my @penguin_chief = ();
47 push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org");
48 #Andrew wants in on most everything - 2009/01/14
49 #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org");
51 my @penguin_chief_names = ();
52 foreach my $chief (@penguin_chief) {
53 if ($chief =~ m/^(.*):(.*)/) {
56 push(@penguin_chief_names, $chief_name);
59 my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)";
61 # rfc822 email address - preloaded methods go here.
62 my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
63 my $rfc822_char = '[\\000-\\377]';
67 'git!' => \
$email_git,
68 'git-chief-penguins!' => \
$email_git_penguin_chiefs,
69 'git-min-signatures=i' => \
$email_git_min_signatures,
70 'git-max-maintainers=i' => \
$email_git_max_maintainers,
71 'git-min-percent=i' => \
$email_git_min_percent,
72 'git-since=s' => \
$email_git_since,
73 'git-blame!' => \
$email_git_blame,
74 'm!' => \
$email_maintainer,
75 'n!' => \
$email_usename,
77 's!' => \
$email_subscriber_list,
78 'multiline!' => \
$output_multiline,
79 'separator=s' => \
$output_separator,
80 'subsystem!' => \
$subsystem,
81 'status!' => \
$status,
84 'pattern-depth=i' => \
$pattern_depth,
85 'f|file' => \
$from_filename,
86 'v|version' => \
$version,
90 die "$P: invalid argument\n";
105 die "$P: argument missing: patchfile or -f file please\n";
108 if ($output_separator ne ", ") {
109 $output_multiline = 0;
112 my $selections = $email + $scm + $status + $subsystem + $web;
113 if ($selections == 0) {
115 die "$P: Missing required option: email, scm, status, subsystem or web\n";
119 ($email_maintainer + $email_list + $email_subscriber_list +
120 $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
122 die "$P: Please select at least 1 email option\n";
125 if (!top_of_kernel_tree
($lk_path)) {
126 die "$P: The current directory does not appear to be "
127 . "a linux kernel source tree.\n";
130 ## Read MAINTAINERS for type/value pairs
133 open(MAINT
, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
137 if ($line =~ m/^(\C):\s*(.*)/) {
141 ##Filename pattern matching
142 if ($type eq "F" || $type eq "X") {
143 $value =~ s
@\.@\\\.@g; ##Convert . to \.
144 $value =~ s/\*/\.\*/g; ##Convert * to .*
145 $value =~ s/\?/\./g; ##Convert ? to .
146 ##if pattern is a directory and it lacks a trailing slash, add one
148 $value =~ s
@([^/])$@$1/@;
151 push(@typevalue, "$type:$value");
152 } elsif (!/^(\s)*$/) {
154 push(@typevalue, $line);
161 open(MAILMAP
, "<${lk_path}.mailmap") || warn "$P: Can't open .mailmap\n";
165 next if ($line =~ m/^\s*#/);
166 next if ($line =~ m/^\s*$/);
168 my ($name, $address) = parse_email
($line);
169 $line = format_email
($name, $address);
171 next if ($line =~ m/^\s*$/);
173 if (exists($mailmap{$name})) {
174 my $obj = $mailmap{$name};
175 push(@$obj, $address);
177 my @arr = ($address);
178 $mailmap{$name} = \
@arr;
183 foreach my $name (sort {$mailmap{$a} <=> $mailmap{$b}} keys %mailmap) {
184 my $obj = $mailmap{$name};
185 foreach my $address (@$obj) {
189 ## use the filenames on the command line or find the filenames in the patchfiles
194 foreach my $file (@ARGV) {
195 ##if $file is a directory and it lacks a trailing slash, add one
197 $file =~ s
@([^/])$@$1/@;
198 } elsif (!(-f
$file)) {
199 die "$P: file '${file}' not found\n";
201 if ($from_filename) {
204 my $file_cnt = @files;
206 open(PATCH
, "<$file") or die "$P: Can't open ${file}\n";
208 if (m/^\+\+\+\s+(\S+)/) {
210 $filename =~ s
@^[^/]*/@@;
212 $lastfile = $filename;
213 push(@files, $filename);
214 } elsif (m/^\@\@ -(\d+),(\d+)/) {
215 if ($email_git_blame) {
216 push(@range, "$lastfile:$1:$2");
221 if ($file_cnt == @files) {
222 warn "$P: file '${file}' doesn't appear to be a patch. "
223 . "Add -f to options?\n";
225 @files = sort_and_uniq
(@files);
236 # Find responsible parties
238 foreach my $file (@files) {
240 #Do not match excluded file patterns
243 foreach my $line (@typevalue) {
244 if ($line =~ m/^(\C):\s*(.*)/) {
248 if (file_match_pattern
($file, $value)) {
259 foreach my $line (@typevalue) {
260 if ($line =~ m/^(\C):\s*(.*)/) {
264 if (file_match_pattern
($file, $value)) {
265 my $value_pd = ($value =~ tr
@/@@);
266 my $file_pd = ($file =~ tr
@/@@);
267 $value_pd++ if (substr($value,-1,1) ne "/");
268 if ($pattern_depth == 0 ||
269 (($file_pd - $value_pd) < $pattern_depth)) {
270 $hash{$tvi} = $value_pd;
277 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
278 add_categories
($line);
282 if ($email && $email_git) {
283 recent_git_signoffs
($file);
286 if ($email && $email_git_blame) {
287 git_assign_blame
($file);
292 foreach my $chief (@penguin_chief) {
293 if ($chief =~ m/^(.*):(.*)/) {
296 $email_address = format_email
($1, $2);
297 if ($email_git_penguin_chiefs) {
298 push(@email_to, $email_address);
300 @email_to = grep(!/${email_address}/, @email_to);
306 if ($email || $email_list) {
309 @to = (@to, @email_to);
312 @to = (@to, @list_to);
318 @scm = sort_and_uniq
(@scm);
323 @status = sort_and_uniq
(@status);
328 @subsystem = sort_and_uniq
(@subsystem);
333 @web = sort_and_uniq
(@web);
339 sub file_match_pattern
{
340 my ($file, $pattern) = @_;
341 if (substr($pattern, -1) eq "/") {
342 if ($file =~ m
@^$pattern@) {
346 if ($file =~ m
@^$pattern@) {
347 my $s1 = ($file =~ tr
@/@@);
348 my $s2 = ($pattern =~ tr
@/@@);
359 usage: $P [options] patchfile
360 $P [options] -f file|directory
363 MAINTAINER field selection options:
364 --email => print email address(es) if any
365 --git => include recent git \*-by: signers
366 --git-chief-penguins => include ${penguin_chiefs}
367 --git-min-signatures => number of signatures required (default: 1)
368 --git-max-maintainers => maximum maintainers to add (default: 5)
369 --git-min-percent => minimum percentage of commits required (default: 5)
370 --git-since => git history to use (default: 1-year-ago)
371 --git-blame => use git blame to find modified commits for patch or file
372 --m => include maintainer(s) if any
373 --n => include name 'Full Name <addr\@domain.tld>'
374 --l => include list(s) if any
375 --s => include subscriber only list(s) if any
376 --scm => print SCM tree(s) if any
377 --status => print status if any
378 --subsystem => print subsystem name if any
379 --web => print website(s) if any
382 --separator [, ] => separator for multiple entries on 1 line
383 using --separator also sets --nomultiline if --separator is not [, ]
384 --multiline => print 1 entry per line
387 --pattern-depth => Number of pattern directory traversals (default: 0 (all))
388 --version => show version
389 --help => show this help information
392 [--email --git --m --n --l --multiline --pattern-depth=0]
395 Using "-f directory" may give unexpected results:
396 Used with "--git", git signators for _all_ files in and below
397 directory are examined as git recurses directories.
398 Any specified X: (exclude) pattern matches are _not_ ignored.
399 Used with "--nogit", directory is used as a pattern match,
400 no individual file within the directory or subdirectory
402 Used with "--git-blame", does not iterate all files in directory
403 Using "--git-blame" is slow and may add old committers and authors
404 that are no longer active maintainers to the output.
408 sub top_of_kernel_tree
{
411 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
414 if ( (-f
"${lk_path}COPYING")
415 && (-f
"${lk_path}CREDITS")
416 && (-f
"${lk_path}Kbuild")
417 && (-f
"${lk_path}MAINTAINERS")
418 && (-f
"${lk_path}Makefile")
419 && (-f
"${lk_path}README")
420 && (-d
"${lk_path}Documentation")
421 && (-d
"${lk_path}arch")
422 && (-d
"${lk_path}include")
423 && (-d
"${lk_path}drivers")
424 && (-d
"${lk_path}fs")
425 && (-d
"${lk_path}init")
426 && (-d
"${lk_path}ipc")
427 && (-d
"${lk_path}kernel")
428 && (-d
"${lk_path}lib")
429 && (-d
"${lk_path}scripts")) {
436 my ($formatted_email) = @_;
441 if ($formatted_email =~ /^([^<]+)<(.*\@.*)>.*$/) {
444 } elsif ($formatted_email =~ /^\s*<(.*\@.*)>.*$/) {
446 } elsif ($formatted_email =~ /^\s*(.*\@.*)$/) {
450 $name =~ s/^\s+|\s+$//g;
451 $name =~ s/^\"|\"$//g;
452 $address =~ s/^\s+|\s+$//g;
454 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
455 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
459 return ($name, $address);
463 my ($name, $address) = @_;
467 $name =~ s/^\s+|\s+$//g;
468 $name =~ s/^\"|\"$//g;
469 $address =~ s/^\s+|\s+$//g;
471 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote
" chars
472 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
476 if ($email_usename) {
478 $formatted_email = "$address";
480 $formatted_email = "$name <${address}>";
483 $formatted_email = $address;
486 return $formatted_email;
493 while ($index >= 0) {
494 my $tv = $typevalue[$index];
495 if ($tv =~ m/^(\C):\s*(.*)/) {
499 my $list_address = $pvalue;
500 my $list_additional = "";
501 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
503 $list_additional = $2;
505 if ($list_additional =~ m/subscribers-only/) {
506 if ($email_subscriber_list) {
507 push(@list_to, $list_address);
511 push(@list_to, $list_address);
514 } elsif ($ptype eq "M") {
515 my ($name, $address) = parse_email
($pvalue);
518 my $tv = $typevalue[$index - 1];
519 if ($tv =~ m/^(\C):\s*(.*)/) {
526 if ($email_maintainer) {
527 push_email_addresses
($pvalue);
529 } elsif ($ptype eq "T") {
531 } elsif ($ptype eq "W") {
533 } elsif ($ptype eq "S") {
534 push(@status, $pvalue);
539 push(@subsystem,$tv);
545 sub email_address_inuse
{
546 my ($test_address) = @_;
548 foreach my $line (@email_to) {
549 my ($name, $address) = parse_email
($line);
551 return 1 if ($address eq $test_address);
556 sub push_email_address
{
559 my ($name, $address) = parse_email
($line);
561 if (!email_address_inuse
($address)) {
562 push(@email_to, format_email
($name, $address));
566 sub push_email_addresses
{
569 my @address_list = ();
571 if (rfc822_valid
($address)) {
572 push_email_address
($address);
573 } elsif (@address_list = rfc822_validlist
($address)) {
574 my $array_count = shift(@address_list);
575 while (my $entry = shift(@address_list)) {
576 push_email_address
($entry);
579 warn("Invalid MAINTAINERS address: '" . $address . "'\n");
586 foreach my $path (split(/:/, $ENV{PATH
})) {
587 if (-e
"$path/$bin") {
599 foreach my $line (@lines) {
600 my ($name, $address) = parse_email
($line);
601 if (!exists($hash{$name})) {
602 $hash{$name} = $address;
604 if (exists($mailmap{$name})) {
605 my $obj = $mailmap{$name};
606 foreach my $map_address (@$obj) {
607 if (($map_address eq $address) &&
608 ($map_address ne $hash{$name})) {
609 $line = format_email
($name, $hash{$name});
618 sub recent_git_signoffs
{
629 if (which
("git") eq "") {
630 warn("$P: git not found. Add --nogit to options?\n");
634 warn("$P: .git directory not found. Use a git repository for better results.\n");
635 warn("$P: perhaps 'git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git'\n");
639 $cmd = "git log --since=${email_git_since} -- ${file}";
642 $output =~ s/^\s*//gm;
644 @lines = split("\n", $output);
646 @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines);
647 if (!$email_git_penguin_chiefs) {
648 @lines = grep(!/${penguin_chiefs}/i, @lines);
651 s/.*:\s*(.+)\s*/$1/ for (@lines);
653 $total_sign_offs = @lines;
655 @lines = mailmap
(@lines);
657 @lines = sort(@lines);
659 foreach my $line (@lines) {
664 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
665 push(@lines,"$hash{$line} $line");
668 foreach my $line (@lines) {
669 if ($line =~ m/([0-9]+)\s+(.*)/) {
673 if ($sign_offs < $email_git_min_signatures ||
674 $count > $email_git_max_maintainers ||
675 $sign_offs * 100 / $total_sign_offs < $email_git_min_percent) {
678 push_email_address
($line);
684 my ($cmd, @commits) = @_;
690 @lines = split("\n", $output);
691 foreach my $line (@lines) {
692 if ($line =~ m/^(\w+) /) {
699 sub git_assign_blame
{
711 foreach my $file_range_diff (@range) {
712 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
715 my $diff_length = $3;
716 next if (!("$file" eq "$diff_file"));
717 $cmd = "git blame -l -L $diff_start,+$diff_length $file";
718 @commits = save_commits
($cmd, @commits);
722 $cmd = "git blame -l $file";
723 @commits = save_commits
($cmd, @commits);
727 $total_sign_offs = 0;
728 @commits = uniq
(@commits);
729 foreach my $commit (@commits) {
730 $cmd = "git log -1 ${commit}";
733 $output =~ s/^\s*//gm;
734 @lines = split("\n", $output);
736 @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines);
737 if (!$email_git_penguin_chiefs) {
738 @lines = grep(!/${penguin_chiefs}/i, @lines);
742 s/.*:\s*(.+)\s*/$1/ for (@lines);
744 $total_sign_offs += @lines;
746 @lines = mailmap
(@lines);
748 $hash{$_}++ for @lines;
752 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
753 my $sign_offs = $hash{$line};
755 last if ($sign_offs < $email_git_min_signatures ||
756 $count > $email_git_max_maintainers ||
757 $sign_offs * 100 / $total_sign_offs < $email_git_min_percent);
758 push_email_address
($line);
766 @parms = grep(!$saw{$_}++, @parms);
774 @parms = sort @parms;
775 @parms = grep(!$saw{$_}++, @parms);
782 if ($output_multiline) {
783 foreach my $line (@parms) {
787 print(join($output_separator, @parms));
795 # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
796 # comment. We must allow for rfc822_lwsp (or comments) after each of these.
797 # This regexp will only work on addresses which have had comments stripped
798 # and replaced with rfc822_lwsp.
800 my $specials = '()<>@,;:\\\\".\\[\\]';
801 my $controls = '\\000-\\037\\177';
803 my $dtext = "[^\\[\\]\\r\\\\]";
804 my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
806 my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
808 # Use zero-width assertion to spot the limit of an atom. A simple
809 # $rfc822_lwsp* causes the regexp engine to hang occasionally.
810 my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
811 my $word = "(?:$atom|$quoted_string)";
812 my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
814 my $sub_domain = "(?:$atom|$domain_literal)";
815 my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
817 my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
819 my $phrase = "$word*";
820 my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
821 my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
822 my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
824 my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
825 my $address = "(?:$mailbox|$group)";
827 return "$rfc822_lwsp*$address";
830 sub rfc822_strip_comments
{
832 # Recursively remove comments, and replace with a single space. The simpler
833 # regexps in the Email Addressing FAQ are imperfect - they will miss escaped
834 # chars in atoms, for example.
836 while ($s =~ s
/^((?
:[^"\\]|\\.)*
837 (?:"(?
:[^"\\]|\\.)*"(?
:[^"\\]|\\.)*)*)
838 \((?:[^()\\]|\\.)*\)/$1 /osx) {}
842 # valid: returns true if the parameter is an RFC822 valid address
844 sub rfc822_valid ($) {
845 my $s = rfc822_strip_comments(shift);
848 $rfc822re = make_rfc822re();
851 return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
854 # validlist: In scalar context, returns true if the parameter is an RFC822
855 # valid list of addresses.
857 # In list context, returns an empty list on failure (an invalid
858 # address was found); otherwise a list whose first element is the
859 # number of addresses found and whose remaining elements are the
860 # addresses. This is needed to disambiguate failure (invalid)
861 # from success with no addresses found, because an empty string is
864 sub rfc822_validlist ($) {
865 my $s = rfc822_strip_comments(shift);
868 $rfc822re = make_rfc822re();
870 # * null list items are valid according to the RFC
871 # * the '1' business is to aid in distinguishing failure from no results
874 if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
875 $s =~ m/^$rfc822_char*$/) {
876 while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
879 return wantarray ? (scalar(@r), @r) : 1;
882 return wantarray ? () : 0;