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;
45 my $from_filename = 0;
46 my $pattern_depth = 0;
52 my @penguin_chief = ();
53 push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org");
54 #Andrew wants in on most everything - 2009/01/14
55 #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org");
57 my @penguin_chief_names = ();
58 foreach my $chief (@penguin_chief) {
59 if ($chief =~ m/^(.*):(.*)/) {
62 push(@penguin_chief_names, $chief_name);
65 my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)";
67 # rfc822 email address - preloaded methods go here.
68 my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
69 my $rfc822_char = '[\\000-\\377]';
71 # VCS command support: class-like functions and strings
76 "execute_cmd" => \&git_execute_cmd,
77 "available" => '(which("git") ne "") && (-d ".git")',
78 "find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file",
79 "find_commit_signers_cmd" => "git log --no-color -1 \$commit",
80 "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
81 "blame_file_cmd" => "git blame -l \$file",
82 "commit_pattern" => "^commit [0-9a-f]{40,40}",
83 "blame_commit_pattern" => "^([0-9a-f]+) "
87 "execute_cmd" => \&hg_execute_cmd,
88 "available" => '(which("hg") ne "") && (-d ".hg")',
90 "hg log --date=\$email_hg_since" .
91 " --template='commit {node}\\n{desc}\\n' -- \$file",
92 "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit",
93 "blame_range_cmd" => "", # not supported
94 "blame_file_cmd" => "hg blame -c \$file",
95 "commit_pattern" => "^commit [0-9a-f]{40,40}",
96 "blame_commit_pattern" => "^([0-9a-f]+):"
101 'git!' => \$email_git,
102 'git-blame!' => \$email_git_blame,
103 'git-chief-penguins!' => \$email_git_penguin_chiefs,
104 'git-min-signatures=i' => \$email_git_min_signatures,
105 'git-max-maintainers=i' => \$email_git_max_maintainers,
106 'git-min-percent=i' => \$email_git_min_percent,
107 'git-since=s' => \$email_git_since,
108 'hg-since=s' => \$email_hg_since,
109 'remove-duplicates!' => \$email_remove_duplicates,
110 'm!' => \$email_maintainer,
111 'n!' => \$email_usename,
112 'l!' => \$email_list,
113 's!' => \$email_subscriber_list,
114 'multiline!' => \$output_multiline,
115 'roles!' => \$output_roles,
116 'rolestats!' => \$output_rolestats,
117 'separator=s' => \$output_separator,
118 'subsystem!' => \$subsystem,
119 'status!' => \$status,
122 'pattern-depth=i' => \$pattern_depth,
123 'k|keywords!' => \$keywords,
124 'fe|file-emails!' => \$file_emails,
125 'f|file' => \$from_filename,
126 'v|version' => \$version,
129 die "$P: invalid argument - use --help if necessary\n";
138 print("${P} ${V}\n");
144 die "$P: argument missing: patchfile or -f file please\n";
147 if ($output_separator ne ", ") {
148 $output_multiline = 0;
151 if ($output_rolestats) {
155 my $selections = $email + $scm + $status + $subsystem + $web;
156 if ($selections == 0) {
158 die "$P: Missing required option: email, scm, status, subsystem or web\n";
162 ($email_maintainer + $email_list + $email_subscriber_list +
163 $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
165 die "$P: Please select at least 1 email option\n";
168 if (!top_of_kernel_tree($lk_path)) {
169 die "$P: The current directory does not appear to be "
170 . "a linux kernel source tree.\n";
173 ## Read MAINTAINERS for type/value pairs
178 open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
182 if ($line =~ m/^(\C):\s*(.*)/) {
186 ##Filename pattern matching
187 if ($type eq "F" || $type eq "X") {
188 $value =~ s@\.@\\\.@g; ##Convert . to \.
189 $value =~ s/\*/\.\*/g; ##Convert * to .*
190 $value =~ s/\?/\./g; ##Convert ? to .
191 ##if pattern is a directory and it lacks a trailing slash, add one
193 $value =~ s@([^/])$@$1/@;
195 } elsif ($type eq "K") {
196 $keyword_hash{@typevalue} = $value;
198 push(@typevalue, "$type:$value");
199 } elsif (!/^(\s)*$/) {
201 push(@typevalue, $line);
208 if ($email_remove_duplicates) {
209 open(MAILMAP, "<${lk_path}.mailmap") || warn "$P: Can't open .mailmap\n";
213 next if ($line =~ m/^\s*#/);
214 next if ($line =~ m/^\s*$/);
216 my ($name, $address) = parse_email($line);
217 $line = format_email($name, $address, $email_usename);
219 next if ($line =~ m/^\s*$/);
221 if (exists($mailmap{$name})) {
222 my $obj = $mailmap{$name};
223 push(@$obj, $address);
225 my @arr = ($address);
226 $mailmap{$name} = \@arr;
232 ## use the filenames on the command line or find the filenames in the patchfiles
236 my @keyword_tvi = ();
237 my @file_emails = ();
239 foreach my $file (@ARGV) {
240 ##if $file is a directory and it lacks a trailing slash, add one
242 $file =~ s@([^/])$@$1/@;
243 } elsif (!(-f $file)) {
244 die "$P: file '${file}' not found\n";
246 if ($from_filename) {
248 if (-f $file && ($keywords || $file_emails)) {
249 open(FILE, "<$file") or die "$P: Can't open ${file}\n";
250 my $text = do { local($/) ; <FILE> };
253 foreach my $line (keys %keyword_hash) {
254 if ($text =~ m/$keyword_hash{$line}/x) {
255 push(@keyword_tvi, $line);
260 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;
261 push(@file_emails, clean_file_emails(@poss_addr));
265 my $file_cnt = @files;
267 open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
270 if (m/^\+\+\+\s+(\S+)/) {
272 $filename =~ s@^[^/]*/@@;
274 $lastfile = $filename;
275 push(@files, $filename);
276 } elsif (m/^\@\@ -(\d+),(\d+)/) {
277 if ($email_git_blame) {
278 push(@range, "$lastfile:$1:$2");
280 } elsif ($keywords) {
281 foreach my $line (keys %keyword_hash) {
282 if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) {
283 push(@keyword_tvi, $line);
289 if ($file_cnt == @files) {
290 warn "$P: file '${file}' doesn't appear to be a patch. "
291 . "Add -f to options?\n";
293 @files = sort_and_uniq(@files);
297 @file_emails = uniq(@file_emails);
306 # Find responsible parties
308 foreach my $file (@files) {
311 my $tvi = find_first_section();
312 while ($tvi < @typevalue) {
313 my $start = find_starting_index($tvi);
314 my $end = find_ending_index($tvi);
318 #Do not match excluded file patterns
320 for ($i = $start; $i < $end; $i++) {
321 my $line = $typevalue[$i];
322 if ($line =~ m/^(\C):\s*(.*)/) {
326 if (file_match_pattern($file, $value)) {
334 for ($i = $start; $i < $end; $i++) {
335 my $line = $typevalue[$i];
336 if ($line =~ m/^(\C):\s*(.*)/) {
340 if (file_match_pattern($file, $value)) {
341 my $value_pd = ($value =~ tr@/@@);
342 my $file_pd = ($file =~ tr@/@@);
343 $value_pd++ if (substr($value,-1,1) ne "/");
344 if ($pattern_depth == 0 ||
345 (($file_pd - $value_pd) < $pattern_depth)) {
346 $hash{$tvi} = $value_pd;
354 $tvi += ($end - $start);
358 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
359 add_categories($line);
362 if ($email && $email_git) {
363 vcs_file_signoffs($file);
366 if ($email && $email_git_blame) {
367 vcs_file_blame($file);
372 @keyword_tvi = sort_and_uniq(@keyword_tvi);
373 foreach my $line (@keyword_tvi) {
374 add_categories($line);
379 foreach my $chief (@penguin_chief) {
380 if ($chief =~ m/^(.*):(.*)/) {
383 $email_address = format_email($1, $2, $email_usename);
384 if ($email_git_penguin_chiefs) {
385 push(@email_to, [$email_address, 'chief penguin']);
387 @email_to = grep($_->[0] !~ /${email_address}/, @email_to);
392 foreach my $email (@file_emails) {
393 my ($name, $address) = parse_email($email);
395 my $tmp_email = format_email($name, $address, $email_usename);
396 push_email_address($tmp_email, '');
397 add_role($tmp_email, 'in file');
401 if ($email || $email_list) {
404 @to = (@to, @email_to);
407 @to = (@to, @list_to);
409 output(merge_email(@to));
418 @status = uniq(@status);
423 @subsystem = uniq(@subsystem);
434 sub file_match_pattern {
435 my ($file, $pattern) = @_;
436 if (substr($pattern, -1) eq "/") {
437 if ($file =~ m@^$pattern@) {
441 if ($file =~ m@^$pattern@) {
442 my $s1 = ($file =~ tr@/@@);
443 my $s2 = ($pattern =~ tr@/@@);
454 usage: $P [options] patchfile
455 $P [options] -f file|directory
458 MAINTAINER field selection options:
459 --email => print email address(es) if any
460 --git => include recent git \*-by: signers
461 --git-chief-penguins => include ${penguin_chiefs}
462 --git-min-signatures => number of signatures required (default: 1)
463 --git-max-maintainers => maximum maintainers to add (default: 5)
464 --git-min-percent => minimum percentage of commits required (default: 5)
465 --git-blame => use git blame to find modified commits for patch or file
466 --git-since => git history to use (default: 1-year-ago)
467 --hg-since => hg history to use (default: -365)
468 --m => include maintainer(s) if any
469 --n => include name 'Full Name <addr\@domain.tld>'
470 --l => include list(s) if any
471 --s => include subscriber only list(s) if any
472 --remove-duplicates => minimize duplicate email names/addresses
473 --roles => show roles (status:subsystem, git-signer, list, etc...)
474 --rolestats => show roles and statistics (commits/total_commits, %)
475 --file-emails => add email addresses found in -f file (default: 0 (off))
476 --scm => print SCM tree(s) if any
477 --status => print status if any
478 --subsystem => print subsystem name if any
479 --web => print website(s) if any
482 --separator [, ] => separator for multiple entries on 1 line
483 using --separator also sets --nomultiline if --separator is not [, ]
484 --multiline => print 1 entry per line
487 --pattern-depth => Number of pattern directory traversals (default: 0 (all))
488 --keywords => scan patch for keywords (default: 1 (on))
489 --version => show version
490 --help => show this help information
493 [--email --git --m --n --l --multiline --pattern-depth=0 --remove-duplicates]
496 Using "-f directory" may give unexpected results:
497 Used with "--git", git signators for _all_ files in and below
498 directory are examined as git recurses directories.
499 Any specified X: (exclude) pattern matches are _not_ ignored.
500 Used with "--nogit", directory is used as a pattern match,
501 no individual file within the directory or subdirectory
503 Used with "--git-blame", does not iterate all files in directory
504 Using "--git-blame" is slow and may add old committers and authors
505 that are no longer active maintainers to the output.
506 Using "--roles" or "--rolestats" with git send-email --cc-cmd or any
507 other automated tools that expect only ["name"] <email address>
508 may not work because of additional output after <email address>.
509 Using "--rolestats" and "--git-blame" shows the #/total=% commits,
510 not the percentage of the entire file authored. # of commits is
511 not a good measure of amount of code authored. 1 major commit may
512 contain a thousand lines, 5 trivial commits may modify a single line.
513 If git is not installed, but mercurial (hg) is installed and an .hg
514 repository exists, the following options apply to mercurial:
516 --git-min-signatures, --git-max-maintainers, --git-min-percent, and
518 Use --hg-since not --git-since to control date selection
522 sub top_of_kernel_tree {
525 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
528 if ( (-f "${lk_path}COPYING")
529 && (-f "${lk_path}CREDITS")
530 && (-f "${lk_path}Kbuild")
531 && (-f "${lk_path}MAINTAINERS")
532 && (-f "${lk_path}Makefile")
533 && (-f "${lk_path}README")
534 && (-d "${lk_path}Documentation")
535 && (-d "${lk_path}arch")
536 && (-d "${lk_path}include")
537 && (-d "${lk_path}drivers")
538 && (-d "${lk_path}fs")
539 && (-d "${lk_path}init")
540 && (-d "${lk_path}ipc")
541 && (-d "${lk_path}kernel")
542 && (-d "${lk_path}lib")
543 && (-d "${lk_path}scripts")) {
550 my ($formatted_email) = @_;
555 if ($formatted_email =~ /^([^<]+)<(.+\@.*)>.*$/) {
558 } elsif ($formatted_email =~ /^\s*<(.+\@\S*)>.*$/) {
560 } elsif ($formatted_email =~ /^(.+\@\S*).*$/) {
564 $name =~ s/^\s+|\s+$//g;
565 $name =~ s/^\"|\"$//g;
566 $address =~ s/^\s+|\s+$//g;
568 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
569 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
573 return ($name, $address);
577 my ($name, $address, $usename) = @_;
581 $name =~ s/^\s+|\s+$//g;
582 $name =~ s/^\"|\"$//g;
583 $address =~ s/^\s+|\s+$//g;
585 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
586 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
592 $formatted_email = "$address";
594 $formatted_email = "$name <$address>";
597 $formatted_email = $address;
600 return $formatted_email;
603 sub find_first_section {
606 while ($index < @typevalue) {
607 my $tv = $typevalue[$index];
608 if (($tv =~ m/^(\C):\s*(.*)/)) {
617 sub find_starting_index {
621 my $tv = $typevalue[$index];
622 if (!($tv =~ m/^(\C):\s*(.*)/)) {
631 sub find_ending_index {
634 while ($index < @typevalue) {
635 my $tv = $typevalue[$index];
636 if (!($tv =~ m/^(\C):\s*(.*)/)) {
645 sub get_maintainer_role {
649 my $start = find_starting_index($index);
650 my $end = find_ending_index($index);
653 my $subsystem = $typevalue[$start];
654 if (length($subsystem) > 20) {
655 $subsystem = substr($subsystem, 0, 17);
656 $subsystem =~ s/\s*$//;
657 $subsystem = $subsystem . "...";
660 for ($i = $start + 1; $i < $end; $i++) {
661 my $tv = $typevalue[$i];
662 if ($tv =~ m/^(\C):\s*(.*)/) {
672 if ($role eq "supported") {
674 } elsif ($role eq "maintained") {
675 $role = "maintainer";
676 } elsif ($role eq "odd fixes") {
678 } elsif ($role eq "orphan") {
679 $role = "orphan minder";
680 } elsif ($role eq "obsolete") {
681 $role = "obsolete minder";
682 } elsif ($role eq "buried alive in reporters") {
683 $role = "chief penguin";
686 return $role . ":" . $subsystem;
693 my $start = find_starting_index($index);
694 my $end = find_ending_index($index);
696 my $subsystem = $typevalue[$start];
697 if (length($subsystem) > 20) {
698 $subsystem = substr($subsystem, 0, 17);
699 $subsystem =~ s/\s*$//;
700 $subsystem = $subsystem . "...";
703 if ($subsystem eq "THE REST") {
714 my $start = find_starting_index($index);
715 my $end = find_ending_index($index);
717 push(@subsystem, $typevalue[$start]);
719 for ($i = $start + 1; $i < $end; $i++) {
720 my $tv = $typevalue[$i];
721 if ($tv =~ m/^(\C):\s*(.*)/) {
725 my $list_address = $pvalue;
726 my $list_additional = "";
727 my $list_role = get_list_role($i);
729 if ($list_role ne "") {
730 $list_role = ":" . $list_role;
732 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
734 $list_additional = $2;
736 if ($list_additional =~ m/subscribers-only/) {
737 if ($email_subscriber_list) {
738 push(@list_to, [$list_address, "subscriber list${list_role}"]);
742 push(@list_to, [$list_address, "open list${list_role}"]);
745 } elsif ($ptype eq "M") {
746 my ($name, $address) = parse_email($pvalue);
749 my $tv = $typevalue[$i - 1];
750 if ($tv =~ m/^(\C):\s*(.*)/) {
753 $pvalue = format_email($name, $address, $email_usename);
758 if ($email_maintainer) {
759 my $role = get_maintainer_role($i);
760 push_email_addresses($pvalue, $role);
762 } elsif ($ptype eq "T") {
764 } elsif ($ptype eq "W") {
766 } elsif ($ptype eq "S") {
767 push(@status, $pvalue);
774 my %email_hash_address;
777 my ($name, $address) = @_;
779 return 1 if (($name eq "") && ($address eq ""));
780 return 1 if (($name ne "") && exists($email_hash_name{$name}));
781 return 1 if (($address ne "") && exists($email_hash_address{$address}));
786 sub push_email_address {
787 my ($line, $role) = @_;
789 my ($name, $address) = parse_email($line);
791 if ($address eq "") {
795 if (!$email_remove_duplicates) {
796 push(@email_to, [format_email($name, $address, $email_usename), $role]);
797 } elsif (!email_inuse($name, $address)) {
798 push(@email_to, [format_email($name, $address, $email_usename), $role]);
799 $email_hash_name{$name}++;
800 $email_hash_address{$address}++;
806 sub push_email_addresses {
807 my ($address, $role) = @_;
809 my @address_list = ();
811 if (rfc822_valid($address)) {
812 push_email_address($address, $role);
813 } elsif (@address_list = rfc822_validlist($address)) {
814 my $array_count = shift(@address_list);
815 while (my $entry = shift(@address_list)) {
816 push_email_address($entry, $role);
819 if (!push_email_address($address, $role)) {
820 warn("Invalid MAINTAINERS address: '" . $address . "'\n");
826 my ($line, $role) = @_;
828 my ($name, $address) = parse_email($line);
829 my $email = format_email($name, $address, $email_usename);
831 foreach my $entry (@email_to) {
832 if ($email_remove_duplicates) {
833 my ($entry_name, $entry_address) = parse_email($entry->[0]);
834 if (($name eq $entry_name || $address eq $entry_address)
835 && ($role eq "" || !($entry->[1] =~ m/$role/))
837 if ($entry->[1] eq "") {
838 $entry->[1] = "$role";
840 $entry->[1] = "$entry->[1],$role";
844 if ($email eq $entry->[0]
845 && ($role eq "" || !($entry->[1] =~ m/$role/))
847 if ($entry->[1] eq "") {
848 $entry->[1] = "$role";
850 $entry->[1] = "$entry->[1],$role";
860 foreach my $path (split(/:/, $ENV{PATH})) {
861 if (-e "$path/$bin") {
873 foreach my $line (@lines) {
874 my ($name, $address) = parse_email($line);
875 if (!exists($hash{$name})) {
876 $hash{$name} = $address;
877 } elsif ($address ne $hash{$name}) {
878 $address = $hash{$name};
879 $line = format_email($name, $address, $email_usename);
881 if (exists($mailmap{$name})) {
882 my $obj = $mailmap{$name};
883 foreach my $map_address (@$obj) {
884 if (($map_address eq $address) &&
885 ($map_address ne $hash{$name})) {
886 $line = format_email($name, $hash{$name}, $email_usename);
895 sub git_execute_cmd {
900 $output =~ s/^\s*//gm;
901 @lines = split("\n", $output);
911 @lines = split("\n", $output);
916 sub vcs_find_signers {
921 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
923 my $pattern = $VCS_cmds{"commit_pattern"};
925 $commits = grep(/$pattern/, @lines); # of commits
927 @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines);
928 if (!$email_git_penguin_chiefs) {
929 @lines = grep(!/${penguin_chiefs}/i, @lines);
932 s/.*:\s*(.+)\s*/$1/ for (@lines);
934 ## Reformat email addresses (with names) to avoid badly written signatures
936 foreach my $line (@lines) {
937 my ($name, $address) = parse_email($line);
938 $line = format_email($name, $address, 1);
941 return ($commits, @lines);
944 sub vcs_save_commits {
949 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
951 foreach my $line (@lines) {
952 if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) {
965 return @commits if (!(-f $file));
967 if (@range && $VCS_cmds{"blame_range_cmd"} eq "") {
968 my @all_commits = ();
970 $cmd = $VCS_cmds{"blame_file_cmd"};
971 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
972 @all_commits = vcs_save_commits($cmd);
974 foreach my $file_range_diff (@range) {
975 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
978 my $diff_length = $3;
979 next if ("$file" ne "$diff_file");
980 for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) {
981 push(@commits, $all_commits[$i]);
985 foreach my $file_range_diff (@range) {
986 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
989 my $diff_length = $3;
990 next if ("$file" ne "$diff_file");
991 $cmd = $VCS_cmds{"blame_range_cmd"};
992 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
993 push(@commits, vcs_save_commits($cmd));
996 $cmd = $VCS_cmds{"blame_file_cmd"};
997 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
998 @commits = vcs_save_commits($cmd);
1004 my $printed_novcs = 0;
1006 %VCS_cmds = %VCS_cmds_git;
1007 return 1 if eval $VCS_cmds{"available"};
1008 %VCS_cmds = %VCS_cmds_hg;
1009 return 1 if eval $VCS_cmds{"available"};
1011 if (!$printed_novcs) {
1012 warn("$P: No supported VCS found. Add --nogit to options?\n");
1013 warn("Using a git repository produces better results.\n");
1014 warn("Try Linus Torvalds' latest git repository using:\n");
1015 warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n");
1022 my ($role, $divisor, @lines) = @_;
1027 return if (@lines <= 0);
1029 if ($divisor <= 0) {
1030 warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n");
1034 if ($email_remove_duplicates) {
1035 @lines = mailmap(@lines);
1038 @lines = sort(@lines);
1041 $hash{$_}++ for @lines;
1044 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
1045 my $sign_offs = $hash{$line};
1046 my $percent = $sign_offs * 100 / $divisor;
1048 $percent = 100 if ($percent > 100);
1050 last if ($sign_offs < $email_git_min_signatures ||
1051 $count > $email_git_max_maintainers ||
1052 $percent < $email_git_min_percent);
1053 push_email_address($line, '');
1054 if ($output_rolestats) {
1055 my $fmt_percent = sprintf("%.0f", $percent);
1056 add_role($line, "$role:$sign_offs/$divisor=$fmt_percent%");
1058 add_role($line, $role);
1063 sub vcs_file_signoffs {
1069 return if (!vcs_exists());
1071 my $cmd = $VCS_cmds{"find_signers_cmd"};
1072 $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
1074 ($commits, @signers) = vcs_find_signers($cmd);
1075 vcs_assign("commit_signer", $commits, @signers);
1078 sub vcs_file_blame {
1085 return if (!vcs_exists());
1087 @commits = vcs_blame($file);
1088 @commits = uniq(@commits);
1089 $total_commits = @commits;
1091 foreach my $commit (@commits) {
1093 my @commit_signers = ();
1095 my $cmd = $VCS_cmds{"find_commit_signers_cmd"};
1096 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1098 ($commit_count, @commit_signers) = vcs_find_signers($cmd);
1099 push(@signers, @commit_signers);
1102 if ($from_filename) {
1103 vcs_assign("commits", $total_commits, @signers);
1105 vcs_assign("modified commits", $total_commits, @signers);
1113 @parms = grep(!$saw{$_}++, @parms);
1121 @parms = sort @parms;
1122 @parms = grep(!$saw{$_}++, @parms);
1126 sub clean_file_emails {
1127 my (@file_emails) = @_;
1128 my @fmt_emails = ();
1130 foreach my $email (@file_emails) {
1131 $email =~ s/[\(\<\{]{0,1}([A-Za-z0-9_\.\+-]+\@[A-Za-z0-9\.-]+)[\)\>\}]{0,1}/\<$1\>/g;
1132 my ($name, $address) = parse_email($email);
1133 if ($name eq '"[,\.]"') {
1137 my @nw = split(/[^A-Za-zÀ-ÿ\'\,\.\+-]/, $name);
1139 my $first = $nw[@nw - 3];
1140 my $middle = $nw[@nw - 2];
1141 my $last = $nw[@nw - 1];
1143 if (((length($first) == 1 && $first =~ m/[A-Za-z]/) ||
1144 (length($first) == 2 && substr($first, -1) eq ".")) ||
1145 (length($middle) == 1 ||
1146 (length($middle) == 2 && substr($middle, -1) eq "."))) {
1147 $name = "$first $middle $last";
1149 $name = "$middle $last";
1153 if (substr($name, -1) =~ /[,\.]/) {
1154 $name = substr($name, 0, length($name) - 1);
1155 } elsif (substr($name, -2) =~ /[,\.]"/) {
1156 $name = substr($name, 0, length($name) - 2) . '"';
1159 if (substr($name, 0, 1) =~ /[,\.]/) {
1160 $name = substr($name, 1, length($name) - 1);
1161 } elsif (substr($name, 0, 2) =~ /"[,\.]/) {
1162 $name = '"' . substr($name, 2, length($name) - 2);
1165 my $fmt_email = format_email($name, $address, $email_usename);
1166 push(@fmt_emails, $fmt_email);
1176 my ($address, $role) = @$_;
1177 if (!$saw{$address}) {
1178 if ($output_roles) {
1179 push(@lines, "$address ($role)");
1181 push(@lines, $address);
1193 if ($output_multiline) {
1194 foreach my $line (@parms) {
1198 print(join($output_separator, @parms));
1206 # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
1207 # comment. We must allow for rfc822_lwsp (or comments) after each of these.
1208 # This regexp will only work on addresses which have had comments stripped
1209 # and replaced with rfc822_lwsp.
1211 my $specials = '()<>@,;:\\\\".\\[\\]';
1212 my $controls = '\\000-\\037\\177';
1214 my $dtext = "[^\\[\\]\\r\\\\]";
1215 my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
1217 my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
1219 # Use zero-width assertion to spot the limit of an atom. A simple
1220 # $rfc822_lwsp* causes the regexp engine to hang occasionally.
1221 my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
1222 my $word = "(?:$atom|$quoted_string)";
1223 my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
1225 my $sub_domain = "(?:$atom|$domain_literal)";
1226 my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
1228 my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
1230 my $phrase = "$word*";
1231 my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
1232 my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
1233 my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
1235 my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
1236 my $address = "(?:$mailbox|$group)";
1238 return "$rfc822_lwsp*$address";
1241 sub rfc822_strip_comments {
1243 # Recursively remove comments, and replace with a single space. The simpler
1244 # regexps in the Email Addressing FAQ are imperfect - they will miss escaped
1245 # chars in atoms, for example.
1247 while ($s =~ s/^((?:[^"\\]|\\.)*
1248 (?:"(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*)*)
1249 \((?:[^()\\]|\\.)*\)/$1 /osx) {}
1253 # valid: returns true if the parameter is an RFC822 valid address
1255 sub rfc822_valid ($) {
1256 my $s = rfc822_strip_comments(shift);
1259 $rfc822re = make_rfc822re();
1262 return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
1265 # validlist: In scalar context, returns true if the parameter is an RFC822
1266 # valid list of addresses.
1268 # In list context, returns an empty list on failure (an invalid
1269 # address was found); otherwise a list whose first element is the
1270 # number of addresses found and whose remaining elements are the
1271 # addresses. This is needed to disambiguate failure (invalid)
1272 # from success with no addresses found, because an empty string is
1275 sub rfc822_validlist ($) {
1276 my $s = rfc822_strip_comments(shift);
1279 $rfc822re = make_rfc822re();
1281 # * null list items are valid according to the RFC
1282 # * the '1' business is to aid in distinguishing failure from no results
1285 if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
1286 $s =~ m/^$rfc822_char*$/) {
1287 while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
1290 return wantarray ? (scalar(@r), @r) : 1;
1292 return wantarray ? () : 0;