]>
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;
45 my @penguin_chief = ();
46 push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org");
47 #Andrew wants in on most everything - 2009/01/14
48 #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org");
50 my @penguin_chief_names = ();
51 foreach my $chief (@penguin_chief) {
52 if ($chief =~ m/^(.*):(.*)/) {
55 push(@penguin_chief_names, $chief_name);
58 my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)";
60 # rfc822 email address - preloaded methods go here.
61 my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
62 my $rfc822_char = '[\\000-\\377]';
66 'git!' => \
$email_git,
67 'git-chief-penguins!' => \
$email_git_penguin_chiefs,
68 'git-min-signatures=i' => \
$email_git_min_signatures,
69 'git-max-maintainers=i' => \
$email_git_max_maintainers,
70 'git-min-percent=i' => \
$email_git_min_percent,
71 'git-since=s' => \
$email_git_since,
72 'git-blame!' => \
$email_git_blame,
73 'm!' => \
$email_maintainer,
74 'n!' => \
$email_usename,
76 's!' => \
$email_subscriber_list,
77 'multiline!' => \
$output_multiline,
78 'separator=s' => \
$output_separator,
79 'subsystem!' => \
$subsystem,
80 'status!' => \
$status,
83 'f|file' => \
$from_filename,
84 'v|version' => \
$version,
88 die "$P: invalid argument\n";
103 die "$P: argument missing: patchfile or -f file please\n";
106 my $selections = $email + $scm + $status + $subsystem + $web;
107 if ($selections == 0) {
109 die "$P: Missing required option: email, scm, status, subsystem or web\n";
113 ($email_maintainer + $email_list + $email_subscriber_list +
114 $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
116 die "$P: Please select at least 1 email option\n";
119 if (!top_of_kernel_tree
($lk_path)) {
120 die "$P: The current directory does not appear to be "
121 . "a linux kernel source tree.\n";
124 ## Read MAINTAINERS for type/value pairs
127 open(MAINT
, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
131 if ($line =~ m/^(\C):\s*(.*)/) {
135 ##Filename pattern matching
136 if ($type eq "F" || $type eq "X") {
137 $value =~ s
@\.@\\\.@g; ##Convert . to \.
138 $value =~ s/\*/\.\*/g; ##Convert * to .*
139 $value =~ s/\?/\./g; ##Convert ? to .
140 ##if pattern is a directory and it lacks a trailing slash, add one
142 $value =~ s
@([^/])$@$1/@;
145 push(@typevalue, "$type:$value");
146 } elsif (!/^(\s)*$/) {
148 push(@typevalue, $line);
153 ## use the filenames on the command line or find the filenames in the patchfiles
158 foreach my $file (@ARGV) {
159 ##if $file is a directory and it lacks a trailing slash, add one
161 $file =~ s
@([^/])$@$1/@;
162 } elsif (!(-f
$file)) {
163 die "$P: file '${file}' not found\n";
165 if ($from_filename) {
168 my $file_cnt = @files;
170 open(PATCH
, "<$file") or die "$P: Can't open ${file}\n";
172 if (m/^\+\+\+\s+(\S+)/) {
174 $filename =~ s
@^[^/]*/@@;
176 $lastfile = $filename;
177 push(@files, $filename);
178 } elsif (m/^\@\@ -(\d+),(\d+)/) {
179 if ($email_git_blame) {
180 push(@range, "$lastfile:$1:$2");
185 if ($file_cnt == @files) {
186 warn "$P: file '${file}' doesn't appear to be a patch. "
187 . "Add -f to options?\n";
189 @files = sort_and_uniq
(@files);
200 # Find responsible parties
202 foreach my $file (@files) {
204 #Do not match excluded file patterns
207 foreach my $line (@typevalue) {
208 if ($line =~ m/^(\C):\s*(.*)/) {
212 if (file_match_pattern
($file, $value)) {
223 foreach my $line (@typevalue) {
224 if ($line =~ m/^(\C):\s*(.*)/) {
228 if (file_match_pattern
($file, $value)) {
229 my $pattern_depth = ($value =~ tr
@/@@);
230 $pattern_depth++ if (!(substr($value,-1,1) eq "/"));
231 $hash{$tvi} = $pattern_depth;
237 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
238 add_categories
($line);
242 if ($email && $email_git) {
243 recent_git_signoffs
($file);
246 if ($email && $email_git_blame) {
247 git_assign_blame
($file);
252 foreach my $chief (@penguin_chief) {
253 if ($chief =~ m/^(.*):(.*)/) {
255 if ($email_usename) {
256 $email_address = format_email
($1, $2);
260 if ($email_git_penguin_chiefs) {
261 push(@email_to, $email_address);
263 @email_to = grep(!/${email_address}/, @email_to);
269 if ($email || $email_list) {
272 @to = (@to, @email_to);
275 @to = (@to, @list_to);
281 @scm = sort_and_uniq
(@scm);
286 @status = sort_and_uniq
(@status);
291 @subsystem = sort_and_uniq
(@subsystem);
296 @web = sort_and_uniq
(@web);
302 sub file_match_pattern
{
303 my ($file, $pattern) = @_;
304 if (substr($pattern, -1) eq "/") {
305 if ($file =~ m
@^$pattern@) {
309 if ($file =~ m
@^$pattern@) {
310 my $s1 = ($file =~ tr
@/@@);
311 my $s2 = ($pattern =~ tr
@/@@);
322 usage: $P [options] patchfile
323 $P [options] -f file|directory
326 MAINTAINER field selection options:
327 --email => print email address(es) if any
328 --git => include recent git \*-by: signers
329 --git-chief-penguins => include ${penguin_chiefs}
330 --git-min-signatures => number of signatures required (default: 1)
331 --git-max-maintainers => maximum maintainers to add (default: 5)
332 --git-min-percent => minimum percentage of commits required (default: 5)
333 --git-since => git history to use (default: 1-year-ago)
334 --git-blame => use git blame to find modified commits for patch or file
335 --m => include maintainer(s) if any
336 --n => include name 'Full Name <addr\@domain.tld>'
337 --l => include list(s) if any
338 --s => include subscriber only list(s) if any
339 --scm => print SCM tree(s) if any
340 --status => print status if any
341 --subsystem => print subsystem name if any
342 --web => print website(s) if any
345 --separator [, ] => separator for multiple entries on 1 line
346 --multiline => print 1 entry per line
349 [--email --git --m --n --l --multiline]
352 --version => show version
353 --help => show this help information
356 Using "-f directory" may give unexpected results:
357 Used with "--git", git signators for _all_ files in and below
358 directory are examined as git recurses directories.
359 Any specified X: (exclude) pattern matches are _not_ ignored.
360 Used with "--nogit", directory is used as a pattern match,
361 no individual file within the directory or subdirectory
363 Used with "--git-blame", does not iterate all files in directory
364 Using "--git-blame" is slow and may add old committers and authors
365 that are no longer active maintainers to the output.
369 sub top_of_kernel_tree
{
372 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
375 if ( (-f
"${lk_path}COPYING")
376 && (-f
"${lk_path}CREDITS")
377 && (-f
"${lk_path}Kbuild")
378 && (-f
"${lk_path}MAINTAINERS")
379 && (-f
"${lk_path}Makefile")
380 && (-f
"${lk_path}README")
381 && (-d
"${lk_path}Documentation")
382 && (-d
"${lk_path}arch")
383 && (-d
"${lk_path}include")
384 && (-d
"${lk_path}drivers")
385 && (-d
"${lk_path}fs")
386 && (-d
"${lk_path}init")
387 && (-d
"${lk_path}ipc")
388 && (-d
"${lk_path}kernel")
389 && (-d
"${lk_path}lib")
390 && (-d
"${lk_path}scripts")) {
397 my ($name, $email) = @_;
399 $name =~ s/^\s+|\s+$//g;
400 $name =~ s/^\"|\"$//g;
401 $email =~ s/^\s+|\s+$//g;
403 my $formatted_email = "";
405 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
406 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
407 $formatted_email = "\"${name}\"\ \<${email}\>";
409 $formatted_email = "${name} \<${email}\>";
411 return $formatted_email;
418 while ($index >= 0) {
419 my $tv = $typevalue[$index];
420 if ($tv =~ m/^(\C):\s*(.*)/) {
424 my $list_address = $pvalue;
425 my $list_additional = "";
426 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
428 $list_additional = $2;
430 if ($list_additional =~ m/subscribers-only/) {
431 if ($email_subscriber_list) {
432 push(@list_to, $list_address);
436 push(@list_to, $list_address);
439 } elsif ($ptype eq "M") {
442 my $tv = $typevalue[$index - 1];
443 if ($tv =~ m/^(\C):\s*(.*)/) {
445 if ($email_usename) {
446 push_email_address
(format_email
($2, $pvalue));
453 push_email_addresses
($pvalue);
455 } elsif ($ptype eq "T") {
457 } elsif ($ptype eq "W") {
459 } elsif ($ptype eq "S") {
460 push(@status, $pvalue);
465 push(@subsystem,$tv);
471 sub push_email_address
{
472 my ($email_address) = @_;
476 if ($email_maintainer) {
477 if ($email_address =~ m/([^<]+)<(.*\@.*)>$/) {
480 if ($email_usename) {
481 push(@email_to, format_email
($email_name, $email_address));
483 push(@email_to, $email_address);
485 } elsif ($email_address =~ m/<(.+)>/) {
487 push(@email_to, $email_address);
489 push(@email_to, $email_address);
494 sub push_email_addresses
{
497 my @address_list = ();
499 if (rfc822_valid
($address)) {
500 push_email_address
($address);
501 } elsif (@address_list = rfc822_validlist
($address)) {
502 my $array_count = shift(@address_list);
503 while (my $entry = shift(@address_list)) {
504 push_email_address
($entry);
507 warn("Invalid MAINTAINERS address: '" . $address . "'\n");
514 foreach my $path (split(/:/, $ENV{PATH
})) {
515 if (-e
"$path/$bin") {
523 sub recent_git_signoffs
{
533 if (which
("git") eq "") {
534 warn("$P: git not found. Add --nogit to options?\n");
538 warn("$P: .git directory not found. Use a git repository for better results.\n");
539 warn("$P: perhaps 'git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git'\n");
543 $cmd = "git log --since=${email_git_since} -- ${file}";
544 $cmd .= " | grep -Ei \"^[-_ a-z]+by:.*\\\@.*\$\"";
545 if (!$email_git_penguin_chiefs) {
546 $cmd .= " | grep -Ev
\"${penguin_chiefs
}\"";
548 $cmd .= " | cut
-f2-
-d
\":\"";
549 $cmd .= " | sort | uniq
-c
| sort -rn
";
552 $output =~ s/^\s*//gm;
554 @lines = split("\n", $output);
556 $total_sign_offs = 0;
557 foreach my $line (@lines) {
558 if ($line =~ m/([0-9]+)\s+(.*)/) {
559 $total_sign_offs += $1;
561 die("$P: Unexpected git output
: ${line
}\n");
565 foreach my $line (@lines) {
566 if ($line =~ m/([0-9]+)\s+(.*)/) {
570 if ($sign_offs < $email_git_min_signatures ||
571 $count > $email_git_max_maintainers ||
572 $sign_offs * 100 / $total_sign_offs < $email_git_min_percent) {
576 push_email_address($line);
581 my ($cmd, @commits) = @_;
587 @lines = split("\n", $output);
588 foreach my $line (@lines) {
589 if ($line =~ m/^(\w+) /) {
596 sub git_assign_blame {
608 foreach my $file_range_diff (@range) {
609 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
612 my $diff_length = $3;
613 next if (!("$file" eq "$diff_file"));
614 $cmd = "git blame
-l
-L
$diff_start,+$diff_length $file\n";
615 @commits = save_commits($cmd, @commits);
619 $cmd = "git blame
-l
$file\n";
620 @commits = save_commits($cmd, @commits);
624 $total_sign_offs = 0;
625 @commits = uniq(@commits);
626 foreach my $commit (@commits) {
627 $cmd = "git
log -1 ${commit
}";
628 $cmd .= " | grep -Ei
\"^[-_ a-z
]+by
:.*\\\
@.*\
$\"";
629 if (!$email_git_penguin_chiefs) {
630 $cmd .= " | grep -Ev \"${penguin_chiefs}\"";
632 $cmd .= " | cut -f2- -d\":\"";
635 $output =~ s/^\s*//gm;
636 @lines = split("\n", $output);
637 $hash{$_}++ for @lines;
638 $total_sign_offs += @lines;
642 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
643 my $sign_offs = $hash{$line};
645 last if ($sign_offs < $email_git_min_signatures ||
646 $count > $email_git_max_maintainers ||
647 $sign_offs * 100 / $total_sign_offs < $email_git_min_percent);
648 push_email_address
($line);
656 @parms = grep(!$saw{$_}++, @parms);
664 @parms = sort @parms;
665 @parms = grep(!$saw{$_}++, @parms);
672 if ($output_multiline) {
673 foreach my $line (@parms) {
677 print(join($output_separator, @parms));
685 # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
686 # comment. We must allow for rfc822_lwsp (or comments) after each of these.
687 # This regexp will only work on addresses which have had comments stripped
688 # and replaced with rfc822_lwsp.
690 my $specials = '()<>@,;:\\\\".\\[\\]';
691 my $controls = '\\000-\\037\\177';
693 my $dtext = "[^\\[\\]\\r\\\\]";
694 my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
696 my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
698 # Use zero-width assertion to spot the limit of an atom. A simple
699 # $rfc822_lwsp* causes the regexp engine to hang occasionally.
700 my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
701 my $word = "(?:$atom|$quoted_string)";
702 my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
704 my $sub_domain = "(?:$atom|$domain_literal)";
705 my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
707 my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
709 my $phrase = "$word*";
710 my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
711 my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
712 my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
714 my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
715 my $address = "(?:$mailbox|$group)";
717 return "$rfc822_lwsp*$address";
720 sub rfc822_strip_comments
{
722 # Recursively remove comments, and replace with a single space. The simpler
723 # regexps in the Email Addressing FAQ are imperfect - they will miss escaped
724 # chars in atoms, for example.
726 while ($s =~ s
/^((?
:[^"\\]|\\.)*
727 (?:"(?
:[^"\\]|\\.)*"(?
:[^"\\]|\\.)*)*)
728 \((?:[^()\\]|\\.)*\)/$1 /osx) {}
732 # valid: returns true if the parameter is an RFC822 valid address
734 sub rfc822_valid ($) {
735 my $s = rfc822_strip_comments(shift);
738 $rfc822re = make_rfc822re();
741 return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
744 # validlist: In scalar context, returns true if the parameter is an RFC822
745 # valid list of addresses.
747 # In list context, returns an empty list on failure (an invalid
748 # address was found); otherwise a list whose first element is the
749 # number of addresses found and whose remaining elements are the
750 # addresses. This is needed to disambiguate failure (invalid)
751 # from success with no addresses found, because an empty string is
754 sub rfc822_validlist ($) {
755 my $s = rfc822_strip_comments(shift);
758 $rfc822re = make_rfc822re();
760 # * null list items are valid according to the RFC
761 # * the '1' business is to aid in distinguishing failure from no results
764 if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
765 $s =~ m/^$rfc822_char*$/) {
766 while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
769 return wantarray ? (scalar(@r), @r) : 1;
772 return wantarray ? () : 0;