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_maintainer.pl [OPTIONS] <patch>
9 # perl scripts/get_maintainer.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;
26 my $email_git_penguin_chiefs = 0;
28 my $email_git_blame = 0;
29 my $email_git_min_signatures = 1;
30 my $email_git_max_maintainers = 5;
31 my $email_git_min_percent = 5;
32 my $email_git_since = "1-year-ago";
33 my $email_hg_since = "-365";
34 my $email_remove_duplicates = 1;
35 my $output_multiline = 1;
36 my $output_separator = ", ";
38 my $output_rolestats = 0;
46 my $from_filename = 0;
47 my $pattern_depth = 0;
53 my @penguin_chief = ();
54 push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org");
55 #Andrew wants in on most everything - 2009/01/14
56 #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org");
58 my @penguin_chief_names = ();
59 foreach my $chief (@penguin_chief) {
60 if ($chief =~ m/^(.*):(.*)/) {
63 push(@penguin_chief_names, $chief_name);
66 my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)";
68 # rfc822 email address - preloaded methods go here.
69 my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
70 my $rfc822_char = '[\\000-\\377]';
72 # VCS command support: class-like functions and strings
77 "execute_cmd" => \
&git_execute_cmd
,
78 "available" => '(which("git") ne "") && (-d ".git")',
79 "find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file",
80 "find_commit_signers_cmd" => "git log --no-color -1 \$commit",
81 "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
82 "blame_file_cmd" => "git blame -l \$file",
83 "commit_pattern" => "^commit [0-9a-f]{40,40}",
84 "blame_commit_pattern" => "^([0-9a-f]+) "
88 "execute_cmd" => \
&hg_execute_cmd
,
89 "available" => '(which("hg") ne "") && (-d ".hg")',
91 "hg log --date=\$email_hg_since" .
92 " --template='commit {node}\\n{desc}\\n' -- \$file",
93 "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit",
94 "blame_range_cmd" => "", # not supported
95 "blame_file_cmd" => "hg blame -c \$file",
96 "commit_pattern" => "^commit [0-9a-f]{40,40}",
97 "blame_commit_pattern" => "^([0-9a-f]+):"
102 'git!' => \
$email_git,
103 'git-blame!' => \
$email_git_blame,
104 'git-chief-penguins!' => \
$email_git_penguin_chiefs,
105 'git-min-signatures=i' => \
$email_git_min_signatures,
106 'git-max-maintainers=i' => \
$email_git_max_maintainers,
107 'git-min-percent=i' => \
$email_git_min_percent,
108 'git-since=s' => \
$email_git_since,
109 'hg-since=s' => \
$email_hg_since,
110 'remove-duplicates!' => \
$email_remove_duplicates,
111 'm!' => \
$email_maintainer,
112 'n!' => \
$email_usename,
113 'l!' => \
$email_list,
114 's!' => \
$email_subscriber_list,
115 'multiline!' => \
$output_multiline,
116 'roles!' => \
$output_roles,
117 'rolestats!' => \
$output_rolestats,
118 'separator=s' => \
$output_separator,
119 'subsystem!' => \
$subsystem,
120 'status!' => \
$status,
123 'pattern-depth=i' => \
$pattern_depth,
124 'k|keywords!' => \
$keywords,
125 'sections!' => \
$sections,
126 'fe|file-emails!' => \
$file_emails,
127 'f|file' => \
$from_filename,
128 'v|version' => \
$version,
131 die "$P: invalid argument - use --help if necessary\n";
140 print("${P} ${V}\n");
146 die "$P: argument missing: patchfile or -f file please\n";
149 if ($output_separator ne ", ") {
150 $output_multiline = 0;
153 if ($output_rolestats) {
166 my $selections = $email + $scm + $status + $subsystem + $web;
167 if ($selections == 0) {
169 die "$P: Missing required option: email, scm, status, subsystem or web\n";
174 ($email_maintainer + $email_list + $email_subscriber_list +
175 $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
177 die "$P: Please select at least 1 email option\n";
180 if (!top_of_kernel_tree
($lk_path)) {
181 die "$P: The current directory does not appear to be "
182 . "a linux kernel source tree.\n";
185 ## Read MAINTAINERS for type/value pairs
190 open(MAINT
, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
194 if ($line =~ m/^(\C):\s*(.*)/) {
198 ##Filename pattern matching
199 if ($type eq "F" || $type eq "X") {
200 $value =~ s@\
.@
\\\
.@g; ##Convert . to \.
201 $value =~ s/\*/\.\*/g; ##Convert * to .*
202 $value =~ s/\?/\./g; ##Convert ? to .
203 ##if pattern is a directory and it lacks a trailing slash, add one
205 $value =~ s@
([^/])$@$1/@
;
207 } elsif ($type eq "K") {
208 $keyword_hash{@typevalue} = $value;
210 push(@typevalue, "$type:$value");
211 } elsif (!/^(\s)*$/) {
213 push(@typevalue, $line);
220 if ($email_remove_duplicates) {
221 open(MAILMAP
, "<${lk_path}.mailmap") || warn "$P: Can't open .mailmap\n";
225 next if ($line =~ m/^\s*#/);
226 next if ($line =~ m/^\s*$/);
228 my ($name, $address) = parse_email
($line);
229 $line = format_email
($name, $address, $email_usename);
231 next if ($line =~ m/^\s*$/);
233 if (exists($mailmap{$name})) {
234 my $obj = $mailmap{$name};
235 push(@
$obj, $address);
237 my @arr = ($address);
238 $mailmap{$name} = \
@arr;
244 ## use the filenames on the command line or find the filenames in the patchfiles
248 my @keyword_tvi = ();
249 my @file_emails = ();
251 foreach my $file (@ARGV) {
252 ##if $file is a directory and it lacks a trailing slash, add one
254 $file =~ s@
([^/])$@$1/@
;
255 } elsif (!(-f
$file)) {
256 die "$P: file '${file}' not found\n";
258 if ($from_filename) {
260 if (-f
$file && ($keywords || $file_emails)) {
261 open(FILE
, "<$file") or die "$P: Can't open ${file}\n";
262 my $text = do { local($/) ; <FILE
> };
265 foreach my $line (keys %keyword_hash) {
266 if ($text =~ m/$keyword_hash{$line}/x) {
267 push(@keyword_tvi, $line);
272 my @poss_addr = $text =~ m
$[A
-Za
-zÀ
-ÿ
\"\' \
,\
.\
+-]*\s
*[\
,]*\s
*[\
(\
<\
{]{0,1}[A
-Za
-z0
-9_\
.\
+-]+\@
[A
-Za
-z0
-9\
.-]+\
.[A
-Za
-z0
-9]+[\
)\
>\
}]{0,1}$g;
273 push(@file_emails, clean_file_emails
(@poss_addr));
277 my $file_cnt = @files;
279 open(PATCH
, "<$file") or die "$P: Can't open ${file}\n";
282 if (m/^\+\+\+\s+(\S+)/) {
284 $filename =~ s@
^[^/]*/@@
;
286 $lastfile = $filename;
287 push(@files, $filename);
288 } elsif (m/^\@\@ -(\d+),(\d+)/) {
289 if ($email_git_blame) {
290 push(@range, "$lastfile:$1:$2");
292 } elsif ($keywords) {
293 foreach my $line (keys %keyword_hash) {
294 if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) {
295 push(@keyword_tvi, $line);
301 if ($file_cnt == @files) {
302 warn "$P: file '${file}' doesn't appear to be a patch. "
303 . "Add -f to options?\n";
305 @files = sort_and_uniq
(@files);
309 @file_emails = uniq
(@file_emails);
318 # Find responsible parties
320 foreach my $file (@files) {
323 my $tvi = find_first_section
();
324 while ($tvi < @typevalue) {
325 my $start = find_starting_index
($tvi);
326 my $end = find_ending_index
($tvi);
330 #Do not match excluded file patterns
332 for ($i = $start; $i < $end; $i++) {
333 my $line = $typevalue[$i];
334 if ($line =~ m/^(\C):\s*(.*)/) {
338 if (file_match_pattern
($file, $value)) {
346 for ($i = $start; $i < $end; $i++) {
347 my $line = $typevalue[$i];
348 if ($line =~ m/^(\C):\s*(.*)/) {
352 if (file_match_pattern
($file, $value)) {
353 my $value_pd = ($value =~ tr@
/@@
);
354 my $file_pd = ($file =~ tr@
/@@
);
355 $value_pd++ if (substr($value,-1,1) ne "/");
356 if ($pattern_depth == 0 ||
357 (($file_pd - $value_pd) < $pattern_depth)) {
358 $hash{$tvi} = $value_pd;
366 $tvi += ($end - $start);
370 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
371 add_categories
($line);
374 my $start = find_starting_index
($line);
375 my $end = find_ending_index
($line);
376 for ($i = $start; $i < $end; $i++) {
377 my $line = $typevalue[$i];
378 if ($line =~ /^[FX]:/) { ##Restore file patterns
379 $line =~ s/([^\\])\.([^\*])/$1\?$2/g;
380 $line =~ s/([^\\])\.$/$1\?/g; ##Convert . back to ?
381 $line =~ s/\\\./\./g; ##Convert \. to .
382 $line =~ s/\.\*/\*/g; ##Convert .* to *
384 $line =~ s/^([A-Z]):/$1:\t/g;
391 if ($email && $email_git) {
392 vcs_file_signoffs
($file);
395 if ($email && $email_git_blame) {
396 vcs_file_blame
($file);
401 @keyword_tvi = sort_and_uniq
(@keyword_tvi);
402 foreach my $line (@keyword_tvi) {
403 add_categories
($line);
408 foreach my $chief (@penguin_chief) {
409 if ($chief =~ m/^(.*):(.*)/) {
412 $email_address = format_email
($1, $2, $email_usename);
413 if ($email_git_penguin_chiefs) {
414 push(@email_to, [$email_address, 'chief penguin']);
416 @email_to = grep($_->[0] !~ /${email_address}/, @email_to);
421 foreach my $email (@file_emails) {
422 my ($name, $address) = parse_email
($email);
424 my $tmp_email = format_email
($name, $address, $email_usename);
425 push_email_address
($tmp_email, '');
426 add_role
($tmp_email, 'in file');
430 if ($email || $email_list) {
433 @to = (@to, @email_to);
436 @to = (@to, @list_to);
438 output
(merge_email
(@to));
447 @status = uniq
(@status);
452 @subsystem = uniq
(@subsystem);
463 sub file_match_pattern
{
464 my ($file, $pattern) = @_;
465 if (substr($pattern, -1) eq "/") {
466 if ($file =~ m@
^$pattern@
) {
470 if ($file =~ m@
^$pattern@
) {
471 my $s1 = ($file =~ tr@
/@@
);
472 my $s2 = ($pattern =~ tr@
/@@
);
483 usage: $P [options] patchfile
484 $P [options] -f file|directory
487 MAINTAINER field selection options:
488 --email => print email address(es) if any
489 --git => include recent git \*-by: signers
490 --git-chief-penguins => include ${penguin_chiefs}
491 --git-min-signatures => number of signatures required (default: 1)
492 --git-max-maintainers => maximum maintainers to add (default: 5)
493 --git-min-percent => minimum percentage of commits required (default: 5)
494 --git-blame => use git blame to find modified commits for patch or file
495 --git-since => git history to use (default: 1-year-ago)
496 --hg-since => hg history to use (default: -365)
497 --m => include maintainer(s) if any
498 --n => include name 'Full Name <addr\@domain.tld>'
499 --l => include list(s) if any
500 --s => include subscriber only list(s) if any
501 --remove-duplicates => minimize duplicate email names/addresses
502 --roles => show roles (status:subsystem, git-signer, list, etc...)
503 --rolestats => show roles and statistics (commits/total_commits, %)
504 --file-emails => add email addresses found in -f file (default: 0 (off))
505 --scm => print SCM tree(s) if any
506 --status => print status if any
507 --subsystem => print subsystem name if any
508 --web => print website(s) if any
511 --separator [, ] => separator for multiple entries on 1 line
512 using --separator also sets --nomultiline if --separator is not [, ]
513 --multiline => print 1 entry per line
516 --pattern-depth => Number of pattern directory traversals (default: 0 (all))
517 --keywords => scan patch for keywords (default: 1 (on))
518 --sections => print the entire subsystem sections with pattern matches
519 --version => show version
520 --help => show this help information
523 [--email --git --m --n --l --multiline --pattern-depth=0 --remove-duplicates]
526 Using "-f directory" may give unexpected results:
527 Used with "--git", git signators for _all_ files in and below
528 directory are examined as git recurses directories.
529 Any specified X: (exclude) pattern matches are _not_ ignored.
530 Used with "--nogit", directory is used as a pattern match,
531 no individual file within the directory or subdirectory
533 Used with "--git-blame", does not iterate all files in directory
534 Using "--git-blame" is slow and may add old committers and authors
535 that are no longer active maintainers to the output.
536 Using "--roles" or "--rolestats" with git send-email --cc-cmd or any
537 other automated tools that expect only ["name"] <email address>
538 may not work because of additional output after <email address>.
539 Using "--rolestats" and "--git-blame" shows the #/total=% commits,
540 not the percentage of the entire file authored. # of commits is
541 not a good measure of amount of code authored. 1 major commit may
542 contain a thousand lines, 5 trivial commits may modify a single line.
543 If git is not installed, but mercurial (hg) is installed and an .hg
544 repository exists, the following options apply to mercurial:
546 --git-min-signatures, --git-max-maintainers, --git-min-percent, and
548 Use --hg-since not --git-since to control date selection
552 sub top_of_kernel_tree
{
555 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
558 if ( (-f
"${lk_path}COPYING")
559 && (-f
"${lk_path}CREDITS")
560 && (-f
"${lk_path}Kbuild")
561 && (-f
"${lk_path}MAINTAINERS")
562 && (-f
"${lk_path}Makefile")
563 && (-f
"${lk_path}README")
564 && (-d
"${lk_path}Documentation")
565 && (-d
"${lk_path}arch")
566 && (-d
"${lk_path}include")
567 && (-d
"${lk_path}drivers")
568 && (-d
"${lk_path}fs")
569 && (-d
"${lk_path}init")
570 && (-d
"${lk_path}ipc")
571 && (-d
"${lk_path}kernel")
572 && (-d
"${lk_path}lib")
573 && (-d
"${lk_path}scripts")) {
580 my ($formatted_email) = @_;
585 if ($formatted_email =~ /^([^<]+)<(.+\@.*)>.*$/) {
588 } elsif ($formatted_email =~ /^\s*<(.+\@\S*)>.*$/) {
590 } elsif ($formatted_email =~ /^(.+\@\S*).*$/) {
594 $name =~ s/^\s+|\s+$//g;
595 $name =~ s/^\"|\"$//g;
596 $address =~ s/^\s+|\s+$//g;
598 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
599 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
603 return ($name, $address);
607 my ($name, $address, $usename) = @_;
611 $name =~ s/^\s+|\s+$//g;
612 $name =~ s/^\"|\"$//g;
613 $address =~ s/^\s+|\s+$//g;
615 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
616 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
622 $formatted_email = "$address";
624 $formatted_email = "$name <$address>";
627 $formatted_email = $address;
630 return $formatted_email;
633 sub find_first_section
{
636 while ($index < @typevalue) {
637 my $tv = $typevalue[$index];
638 if (($tv =~ m/^(\C):\s*(.*)/)) {
647 sub find_starting_index
{
651 my $tv = $typevalue[$index];
652 if (!($tv =~ m/^(\C):\s*(.*)/)) {
661 sub find_ending_index
{
664 while ($index < @typevalue) {
665 my $tv = $typevalue[$index];
666 if (!($tv =~ m/^(\C):\s*(.*)/)) {
675 sub get_maintainer_role
{
679 my $start = find_starting_index
($index);
680 my $end = find_ending_index
($index);
683 my $subsystem = $typevalue[$start];
684 if (length($subsystem) > 20) {
685 $subsystem = substr($subsystem, 0, 17);
686 $subsystem =~ s/\s*$//;
687 $subsystem = $subsystem . "...";
690 for ($i = $start + 1; $i < $end; $i++) {
691 my $tv = $typevalue[$i];
692 if ($tv =~ m/^(\C):\s*(.*)/) {
702 if ($role eq "supported") {
704 } elsif ($role eq "maintained") {
705 $role = "maintainer";
706 } elsif ($role eq "odd fixes") {
708 } elsif ($role eq "orphan") {
709 $role = "orphan minder";
710 } elsif ($role eq "obsolete") {
711 $role = "obsolete minder";
712 } elsif ($role eq "buried alive in reporters") {
713 $role = "chief penguin";
716 return $role . ":" . $subsystem;
723 my $start = find_starting_index
($index);
724 my $end = find_ending_index
($index);
726 my $subsystem = $typevalue[$start];
727 if (length($subsystem) > 20) {
728 $subsystem = substr($subsystem, 0, 17);
729 $subsystem =~ s/\s*$//;
730 $subsystem = $subsystem . "...";
733 if ($subsystem eq "THE REST") {
744 my $start = find_starting_index
($index);
745 my $end = find_ending_index
($index);
747 push(@subsystem, $typevalue[$start]);
749 for ($i = $start + 1; $i < $end; $i++) {
750 my $tv = $typevalue[$i];
751 if ($tv =~ m/^(\C):\s*(.*)/) {
755 my $list_address = $pvalue;
756 my $list_additional = "";
757 my $list_role = get_list_role
($i);
759 if ($list_role ne "") {
760 $list_role = ":" . $list_role;
762 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
764 $list_additional = $2;
766 if ($list_additional =~ m/subscribers-only/) {
767 if ($email_subscriber_list) {
768 push(@list_to, [$list_address, "subscriber list${list_role}"]);
772 push(@list_to, [$list_address, "open list${list_role}"]);
775 } elsif ($ptype eq "M") {
776 my ($name, $address) = parse_email
($pvalue);
779 my $tv = $typevalue[$i - 1];
780 if ($tv =~ m/^(\C):\s*(.*)/) {
783 $pvalue = format_email
($name, $address, $email_usename);
788 if ($email_maintainer) {
789 my $role = get_maintainer_role
($i);
790 push_email_addresses
($pvalue, $role);
792 } elsif ($ptype eq "T") {
794 } elsif ($ptype eq "W") {
796 } elsif ($ptype eq "S") {
797 push(@status, $pvalue);
804 my %email_hash_address;
807 my ($name, $address) = @_;
809 return 1 if (($name eq "") && ($address eq ""));
810 return 1 if (($name ne "") && exists($email_hash_name{$name}));
811 return 1 if (($address ne "") && exists($email_hash_address{$address}));
816 sub push_email_address
{
817 my ($line, $role) = @_;
819 my ($name, $address) = parse_email
($line);
821 if ($address eq "") {
825 if (!$email_remove_duplicates) {
826 push(@email_to, [format_email
($name, $address, $email_usename), $role]);
827 } elsif (!email_inuse
($name, $address)) {
828 push(@email_to, [format_email
($name, $address, $email_usename), $role]);
829 $email_hash_name{$name}++;
830 $email_hash_address{$address}++;
836 sub push_email_addresses
{
837 my ($address, $role) = @_;
839 my @address_list = ();
841 if (rfc822_valid
($address)) {
842 push_email_address
($address, $role);
843 } elsif (@address_list = rfc822_validlist
($address)) {
844 my $array_count = shift(@address_list);
845 while (my $entry = shift(@address_list)) {
846 push_email_address
($entry, $role);
849 if (!push_email_address
($address, $role)) {
850 warn("Invalid MAINTAINERS address: '" . $address . "'\n");
856 my ($line, $role) = @_;
858 my ($name, $address) = parse_email
($line);
859 my $email = format_email
($name, $address, $email_usename);
861 foreach my $entry (@email_to) {
862 if ($email_remove_duplicates) {
863 my ($entry_name, $entry_address) = parse_email
($entry->[0]);
864 if (($name eq $entry_name || $address eq $entry_address)
865 && ($role eq "" || !($entry->[1] =~ m/$role/))
867 if ($entry->[1] eq "") {
868 $entry->[1] = "$role";
870 $entry->[1] = "$entry->[1],$role";
874 if ($email eq $entry->[0]
875 && ($role eq "" || !($entry->[1] =~ m/$role/))
877 if ($entry->[1] eq "") {
878 $entry->[1] = "$role";
880 $entry->[1] = "$entry->[1],$role";
890 foreach my $path (split(/:/, $ENV{PATH
})) {
891 if (-e
"$path/$bin") {
903 foreach my $line (@lines) {
904 my ($name, $address) = parse_email
($line);
905 if (!exists($hash{$name})) {
906 $hash{$name} = $address;
907 } elsif ($address ne $hash{$name}) {
908 $address = $hash{$name};
909 $line = format_email
($name, $address, $email_usename);
911 if (exists($mailmap{$name})) {
912 my $obj = $mailmap{$name};
913 foreach my $map_address (@
$obj) {
914 if (($map_address eq $address) &&
915 ($map_address ne $hash{$name})) {
916 $line = format_email
($name, $hash{$name}, $email_usename);
925 sub git_execute_cmd
{
930 $output =~ s/^\s*//gm;
931 @lines = split("\n", $output);
941 @lines = split("\n", $output);
946 sub vcs_find_signers
{
951 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
953 my $pattern = $VCS_cmds{"commit_pattern"};
955 $commits = grep(/$pattern/, @lines); # of commits
957 @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines);
958 if (!$email_git_penguin_chiefs) {
959 @lines = grep(!/${penguin_chiefs}/i, @lines);
962 s/.*:\s*(.+)\s*/$1/ for (@lines);
964 ## Reformat email addresses (with names) to avoid badly written signatures
966 foreach my $line (@lines) {
967 my ($name, $address) = parse_email
($line);
968 $line = format_email
($name, $address, 1);
971 return ($commits, @lines);
974 sub vcs_save_commits
{
979 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
981 foreach my $line (@lines) {
982 if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) {
995 return @commits if (!(-f
$file));
997 if (@range && $VCS_cmds{"blame_range_cmd"} eq "") {
998 my @all_commits = ();
1000 $cmd = $VCS_cmds{"blame_file_cmd"};
1001 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1002 @all_commits = vcs_save_commits
($cmd);
1004 foreach my $file_range_diff (@range) {
1005 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
1007 my $diff_start = $2;
1008 my $diff_length = $3;
1009 next if ("$file" ne "$diff_file");
1010 for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) {
1011 push(@commits, $all_commits[$i]);
1015 foreach my $file_range_diff (@range) {
1016 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
1018 my $diff_start = $2;
1019 my $diff_length = $3;
1020 next if ("$file" ne "$diff_file");
1021 $cmd = $VCS_cmds{"blame_range_cmd"};
1022 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1023 push(@commits, vcs_save_commits
($cmd));
1026 $cmd = $VCS_cmds{"blame_file_cmd"};
1027 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1028 @commits = vcs_save_commits
($cmd);
1034 my $printed_novcs = 0;
1036 %VCS_cmds = %VCS_cmds_git;
1037 return 1 if eval $VCS_cmds{"available"};
1038 %VCS_cmds = %VCS_cmds_hg;
1039 return 1 if eval $VCS_cmds{"available"};
1041 if (!$printed_novcs) {
1042 warn("$P: No supported VCS found. Add --nogit to options?\n");
1043 warn("Using a git repository produces better results.\n");
1044 warn("Try Linus Torvalds' latest git repository using:\n");
1045 warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n");
1052 my ($role, $divisor, @lines) = @_;
1057 return if (@lines <= 0);
1059 if ($divisor <= 0) {
1060 warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n");
1064 if ($email_remove_duplicates) {
1065 @lines = mailmap
(@lines);
1068 @lines = sort(@lines);
1071 $hash{$_}++ for @lines;
1074 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
1075 my $sign_offs = $hash{$line};
1076 my $percent = $sign_offs * 100 / $divisor;
1078 $percent = 100 if ($percent > 100);
1080 last if ($sign_offs < $email_git_min_signatures ||
1081 $count > $email_git_max_maintainers ||
1082 $percent < $email_git_min_percent);
1083 push_email_address
($line, '');
1084 if ($output_rolestats) {
1085 my $fmt_percent = sprintf("%.0f", $percent);
1086 add_role
($line, "$role:$sign_offs/$divisor=$fmt_percent%");
1088 add_role
($line, $role);
1093 sub vcs_file_signoffs
{
1099 return if (!vcs_exists
());
1101 my $cmd = $VCS_cmds{"find_signers_cmd"};
1102 $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
1104 ($commits, @signers) = vcs_find_signers
($cmd);
1105 vcs_assign
("commit_signer", $commits, @signers);
1108 sub vcs_file_blame
{
1115 return if (!vcs_exists
());
1117 @commits = vcs_blame
($file);
1118 @commits = uniq
(@commits);
1119 $total_commits = @commits;
1121 foreach my $commit (@commits) {
1123 my @commit_signers = ();
1125 my $cmd = $VCS_cmds{"find_commit_signers_cmd"};
1126 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1128 ($commit_count, @commit_signers) = vcs_find_signers
($cmd);
1129 push(@signers, @commit_signers);
1132 if ($from_filename) {
1133 vcs_assign
("commits", $total_commits, @signers);
1135 vcs_assign
("modified commits", $total_commits, @signers);
1143 @parms = grep(!$saw{$_}++, @parms);
1151 @parms = sort @parms;
1152 @parms = grep(!$saw{$_}++, @parms);
1156 sub clean_file_emails
{
1157 my (@file_emails) = @_;
1158 my @fmt_emails = ();
1160 foreach my $email (@file_emails) {
1161 $email =~ s/[\(\<\{]{0,1}([A-Za-z0-9_\.\+-]+\@[A-Za-z0-9\.-]+)[\)\>\}]{0,1}/\<$1\>/g;
1162 my ($name, $address) = parse_email
($email);
1163 if ($name eq '"[,\.]"') {
1167 my @nw = split(/[^A-Za-zÀ-ÿ\'\,\.\+-]/, $name);
1169 my $first = $nw[@nw - 3];
1170 my $middle = $nw[@nw - 2];
1171 my $last = $nw[@nw - 1];
1173 if (((length($first) == 1 && $first =~ m/[A-Za-z]/) ||
1174 (length($first) == 2 && substr($first, -1) eq ".")) ||
1175 (length($middle) == 1 ||
1176 (length($middle) == 2 && substr($middle, -1) eq "."))) {
1177 $name = "$first $middle $last";
1179 $name = "$middle $last";
1183 if (substr($name, -1) =~ /[,\.]/) {
1184 $name = substr($name, 0, length($name) - 1);
1185 } elsif (substr($name, -2) =~ /[,\.]"/) {
1186 $name = substr($name, 0, length($name) - 2) . '"';
1189 if (substr($name, 0, 1) =~ /[,\.]/) {
1190 $name = substr($name, 1, length($name) - 1);
1191 } elsif (substr($name, 0, 2) =~ /"[,\.]/) {
1192 $name = '"' . substr($name, 2, length($name) - 2);
1195 my $fmt_email = format_email
($name, $address, $email_usename);
1196 push(@fmt_emails, $fmt_email);
1206 my ($address, $role) = @
$_;
1207 if (!$saw{$address}) {
1208 if ($output_roles) {
1209 push(@lines, "$address ($role)");
1211 push(@lines, $address);
1223 if ($output_multiline) {
1224 foreach my $line (@parms) {
1228 print(join($output_separator, @parms));
1236 # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
1237 # comment. We must allow for rfc822_lwsp (or comments) after each of these.
1238 # This regexp will only work on addresses which have had comments stripped
1239 # and replaced with rfc822_lwsp.
1241 my $specials = '()<>@,;:\\\\".\\[\\]';
1242 my $controls = '\\000-\\037\\177';
1244 my $dtext = "[^\\[\\]\\r\\\\]";
1245 my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
1247 my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
1249 # Use zero-width assertion to spot the limit of an atom. A simple
1250 # $rfc822_lwsp* causes the regexp engine to hang occasionally.
1251 my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
1252 my $word = "(?:$atom|$quoted_string)";
1253 my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
1255 my $sub_domain = "(?:$atom|$domain_literal)";
1256 my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
1258 my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
1260 my $phrase = "$word*";
1261 my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
1262 my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
1263 my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
1265 my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
1266 my $address = "(?:$mailbox|$group)";
1268 return "$rfc822_lwsp*$address";
1271 sub rfc822_strip_comments
{
1273 # Recursively remove comments, and replace with a single space. The simpler
1274 # regexps in the Email Addressing FAQ are imperfect - they will miss escaped
1275 # chars in atoms, for example.
1277 while ($s =~ s
/^((?
:[^"\\]|\\.)*
1278 (?:"(?
:[^"\\]|\\.)*"(?
:[^"\\]|\\.)*)*)
1279 \((?:[^()\\]|\\.)*\)/$1 /osx) {}
1283 # valid: returns true if the parameter is an RFC822 valid address
1285 sub rfc822_valid ($) {
1286 my $s = rfc822_strip_comments(shift);
1289 $rfc822re = make_rfc822re();
1292 return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
1295 # validlist: In scalar context, returns true if the parameter is an RFC822
1296 # valid list of addresses.
1298 # In list context, returns an empty list on failure (an invalid
1299 # address was found); otherwise a list whose first element is the
1300 # number of addresses found and whose remaining elements are the
1301 # addresses. This is needed to disambiguate failure (invalid)
1302 # from success with no addresses found, because an empty string is
1305 sub rfc822_validlist ($) {
1306 my $s = rfc822_strip_comments(shift);
1309 $rfc822re = make_rfc822re();
1311 # * null list items are valid according to the RFC
1312 # * the '1' business is to aid in distinguishing failure from no results
1315 if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
1316 $s =~ m/^$rfc822_char*$/) {
1317 while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
1320 return wantarray ? (scalar(@r), @r) : 1;
1322 return wantarray ? () : 0;
This page took 0.095587 seconds and 6 git commands to generate.