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;
44 my $from_filename = 0;
45 my $pattern_depth = 0;
51 my @penguin_chief = ();
52 push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org");
53 #Andrew wants in on most everything - 2009/01/14
54 #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org");
56 my @penguin_chief_names = ();
57 foreach my $chief (@penguin_chief) {
58 if ($chief =~ m/^(.*):(.*)/) {
61 push(@penguin_chief_names, $chief_name);
64 my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)";
66 # rfc822 email address - preloaded methods go here.
67 my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
68 my $rfc822_char = '[\\000-\\377]';
70 # VCS command support: class-like functions and strings
75 "execute_cmd" => \
&git_execute_cmd
,
76 "available" => '(which("git") ne "") && (-d ".git")',
77 "find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file",
78 "find_commit_signers_cmd" => "git log --no-color -1 \$commit",
79 "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
80 "blame_file_cmd" => "git blame -l \$file",
81 "commit_pattern" => "^commit [0-9a-f]{40,40}",
82 "blame_commit_pattern" => "^([0-9a-f]+) "
86 "execute_cmd" => \
&hg_execute_cmd
,
87 "available" => '(which("hg") ne "") && (-d ".hg")',
89 "hg log --date=\$email_hg_since" .
90 " --template='commit {node}\\n{desc}\\n' -- \$file",
91 "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit",
92 "blame_range_cmd" => "", # not supported
93 "blame_file_cmd" => "hg blame -c \$file",
94 "commit_pattern" => "^commit [0-9a-f]{40,40}",
95 "blame_commit_pattern" => "^([0-9a-f]+):"
100 'git!' => \
$email_git,
101 'git-blame!' => \
$email_git_blame,
102 'git-chief-penguins!' => \
$email_git_penguin_chiefs,
103 'git-min-signatures=i' => \
$email_git_min_signatures,
104 'git-max-maintainers=i' => \
$email_git_max_maintainers,
105 'git-min-percent=i' => \
$email_git_min_percent,
106 'git-since=s' => \
$email_git_since,
107 'hg-since=s' => \
$email_hg_since,
108 'remove-duplicates!' => \
$email_remove_duplicates,
109 'm!' => \
$email_maintainer,
110 'n!' => \
$email_usename,
111 'l!' => \
$email_list,
112 's!' => \
$email_subscriber_list,
113 'multiline!' => \
$output_multiline,
114 'roles!' => \
$output_roles,
115 'rolestats!' => \
$output_rolestats,
116 'separator=s' => \
$output_separator,
117 'subsystem!' => \
$subsystem,
118 'status!' => \
$status,
121 'pattern-depth=i' => \
$pattern_depth,
122 'k|keywords!' => \
$keywords,
123 'f|file' => \
$from_filename,
124 'v|version' => \
$version,
127 die "$P: invalid argument - use --help if necessary\n";
136 print("${P} ${V}\n");
142 die "$P: argument missing: patchfile or -f file please\n";
145 if ($output_separator ne ", ") {
146 $output_multiline = 0;
149 if ($output_rolestats) {
153 my $selections = $email + $scm + $status + $subsystem + $web;
154 if ($selections == 0) {
156 die "$P: Missing required option: email, scm, status, subsystem or web\n";
160 ($email_maintainer + $email_list + $email_subscriber_list +
161 $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
163 die "$P: Please select at least 1 email option\n";
166 if (!top_of_kernel_tree
($lk_path)) {
167 die "$P: The current directory does not appear to be "
168 . "a linux kernel source tree.\n";
171 ## Read MAINTAINERS for type/value pairs
176 open(MAINT
, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
180 if ($line =~ m/^(\C):\s*(.*)/) {
184 ##Filename pattern matching
185 if ($type eq "F" || $type eq "X") {
186 $value =~ s@\
.@
\\\
.@g; ##Convert . to \.
187 $value =~ s/\*/\.\*/g; ##Convert * to .*
188 $value =~ s/\?/\./g; ##Convert ? to .
189 ##if pattern is a directory and it lacks a trailing slash, add one
191 $value =~ s@
([^/])$@$1/@
;
193 } elsif ($type eq "K") {
194 $keyword_hash{@typevalue} = $value;
196 push(@typevalue, "$type:$value");
197 } elsif (!/^(\s)*$/) {
199 push(@typevalue, $line);
206 if ($email_remove_duplicates) {
207 open(MAILMAP
, "<${lk_path}.mailmap") || warn "$P: Can't open .mailmap\n";
211 next if ($line =~ m/^\s*#/);
212 next if ($line =~ m/^\s*$/);
214 my ($name, $address) = parse_email
($line);
215 $line = format_email
($name, $address, $email_usename);
217 next if ($line =~ m/^\s*$/);
219 if (exists($mailmap{$name})) {
220 my $obj = $mailmap{$name};
221 push(@
$obj, $address);
223 my @arr = ($address);
224 $mailmap{$name} = \
@arr;
230 ## use the filenames on the command line or find the filenames in the patchfiles
234 my @keyword_tvi = ();
236 foreach my $file (@ARGV) {
237 ##if $file is a directory and it lacks a trailing slash, add one
239 $file =~ s@
([^/])$@$1/@
;
240 } elsif (!(-f
$file)) {
241 die "$P: file '${file}' not found\n";
243 if ($from_filename) {
245 if (-f
$file && $keywords) {
246 open(FILE
, "<$file") or die "$P: Can't open ${file}\n";
247 my $text = do { local($/) ; <FILE
> };
248 foreach my $line (keys %keyword_hash) {
249 if ($text =~ m/$keyword_hash{$line}/x) {
250 push(@keyword_tvi, $line);
256 my $file_cnt = @files;
258 open(PATCH
, "<$file") or die "$P: Can't open ${file}\n";
261 if (m/^\+\+\+\s+(\S+)/) {
263 $filename =~ s@
^[^/]*/@@
;
265 $lastfile = $filename;
266 push(@files, $filename);
267 } elsif (m/^\@\@ -(\d+),(\d+)/) {
268 if ($email_git_blame) {
269 push(@range, "$lastfile:$1:$2");
271 } elsif ($keywords) {
272 foreach my $line (keys %keyword_hash) {
273 if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) {
274 push(@keyword_tvi, $line);
280 if ($file_cnt == @files) {
281 warn "$P: file '${file}' doesn't appear to be a patch. "
282 . "Add -f to options?\n";
284 @files = sort_and_uniq
(@files);
295 # Find responsible parties
297 foreach my $file (@files) {
300 my $tvi = find_first_section
();
301 while ($tvi < @typevalue) {
302 my $start = find_starting_index
($tvi);
303 my $end = find_ending_index
($tvi);
307 #Do not match excluded file patterns
309 for ($i = $start; $i < $end; $i++) {
310 my $line = $typevalue[$i];
311 if ($line =~ m/^(\C):\s*(.*)/) {
315 if (file_match_pattern
($file, $value)) {
323 for ($i = $start; $i < $end; $i++) {
324 my $line = $typevalue[$i];
325 if ($line =~ m/^(\C):\s*(.*)/) {
329 if (file_match_pattern
($file, $value)) {
330 my $value_pd = ($value =~ tr@
/@@
);
331 my $file_pd = ($file =~ tr@
/@@
);
332 $value_pd++ if (substr($value,-1,1) ne "/");
333 if ($pattern_depth == 0 ||
334 (($file_pd - $value_pd) < $pattern_depth)) {
335 $hash{$tvi} = $value_pd;
343 $tvi += ($end - $start);
347 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
348 add_categories
($line);
351 if ($email && $email_git) {
352 vcs_file_signoffs
($file);
355 if ($email && $email_git_blame) {
356 vcs_file_blame
($file);
361 @keyword_tvi = sort_and_uniq
(@keyword_tvi);
362 foreach my $line (@keyword_tvi) {
363 add_categories
($line);
368 foreach my $chief (@penguin_chief) {
369 if ($chief =~ m/^(.*):(.*)/) {
372 $email_address = format_email
($1, $2, $email_usename);
373 if ($email_git_penguin_chiefs) {
374 push(@email_to, [$email_address, 'chief penguin']);
376 @email_to = grep($_->[0] !~ /${email_address}/, @email_to);
382 if ($email || $email_list) {
385 @to = (@to, @email_to);
388 @to = (@to, @list_to);
390 output
(merge_email
(@to));
399 @status = uniq
(@status);
404 @subsystem = uniq
(@subsystem);
415 sub file_match_pattern
{
416 my ($file, $pattern) = @_;
417 if (substr($pattern, -1) eq "/") {
418 if ($file =~ m@
^$pattern@
) {
422 if ($file =~ m@
^$pattern@
) {
423 my $s1 = ($file =~ tr@
/@@
);
424 my $s2 = ($pattern =~ tr@
/@@
);
435 usage: $P [options] patchfile
436 $P [options] -f file|directory
439 MAINTAINER field selection options:
440 --email => print email address(es) if any
441 --git => include recent git \*-by: signers
442 --git-chief-penguins => include ${penguin_chiefs}
443 --git-min-signatures => number of signatures required (default: 1)
444 --git-max-maintainers => maximum maintainers to add (default: 5)
445 --git-min-percent => minimum percentage of commits required (default: 5)
446 --git-blame => use git blame to find modified commits for patch or file
447 --git-since => git history to use (default: 1-year-ago)
448 --hg-since => hg history to use (default: -365)
449 --m => include maintainer(s) if any
450 --n => include name 'Full Name <addr\@domain.tld>'
451 --l => include list(s) if any
452 --s => include subscriber only list(s) if any
453 --remove-duplicates => minimize duplicate email names/addresses
454 --roles => show roles (status:subsystem, git-signer, list, etc...)
455 --rolestats => show roles and statistics (commits/total_commits, %)
456 --scm => print SCM tree(s) if any
457 --status => print status if any
458 --subsystem => print subsystem name if any
459 --web => print website(s) if any
462 --separator [, ] => separator for multiple entries on 1 line
463 using --separator also sets --nomultiline if --separator is not [, ]
464 --multiline => print 1 entry per line
467 --pattern-depth => Number of pattern directory traversals (default: 0 (all))
468 --keywords => scan patch for keywords (default: 1 (on))
469 --version => show version
470 --help => show this help information
473 [--email --git --m --n --l --multiline --pattern-depth=0 --remove-duplicates]
476 Using "-f directory" may give unexpected results:
477 Used with "--git", git signators for _all_ files in and below
478 directory are examined as git recurses directories.
479 Any specified X: (exclude) pattern matches are _not_ ignored.
480 Used with "--nogit", directory is used as a pattern match,
481 no individual file within the directory or subdirectory
483 Used with "--git-blame", does not iterate all files in directory
484 Using "--git-blame" is slow and may add old committers and authors
485 that are no longer active maintainers to the output.
486 Using "--roles" or "--rolestats" with git send-email --cc-cmd or any
487 other automated tools that expect only ["name"] <email address>
488 may not work because of additional output after <email address>.
489 Using "--rolestats" and "--git-blame" shows the #/total=% commits,
490 not the percentage of the entire file authored. # of commits is
491 not a good measure of amount of code authored. 1 major commit may
492 contain a thousand lines, 5 trivial commits may modify a single line.
493 If git is not installed, but mercurial (hg) is installed and an .hg
494 repository exists, the following options apply to mercurial:
496 --git-min-signatures, --git-max-maintainers, --git-min-percent, and
498 Use --hg-since not --git-since to control date selection
502 sub top_of_kernel_tree
{
505 if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
508 if ( (-f
"${lk_path}COPYING")
509 && (-f
"${lk_path}CREDITS")
510 && (-f
"${lk_path}Kbuild")
511 && (-f
"${lk_path}MAINTAINERS")
512 && (-f
"${lk_path}Makefile")
513 && (-f
"${lk_path}README")
514 && (-d
"${lk_path}Documentation")
515 && (-d
"${lk_path}arch")
516 && (-d
"${lk_path}include")
517 && (-d
"${lk_path}drivers")
518 && (-d
"${lk_path}fs")
519 && (-d
"${lk_path}init")
520 && (-d
"${lk_path}ipc")
521 && (-d
"${lk_path}kernel")
522 && (-d
"${lk_path}lib")
523 && (-d
"${lk_path}scripts")) {
530 my ($formatted_email) = @_;
535 if ($formatted_email =~ /^([^<]+)<(.+\@.*)>.*$/) {
538 } elsif ($formatted_email =~ /^\s*<(.+\@\S*)>.*$/) {
540 } elsif ($formatted_email =~ /^(.+\@\S*).*$/) {
544 $name =~ s/^\s+|\s+$//g;
545 $name =~ s/^\"|\"$//g;
546 $address =~ s/^\s+|\s+$//g;
548 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
549 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
553 return ($name, $address);
557 my ($name, $address, $usename) = @_;
561 $name =~ s/^\s+|\s+$//g;
562 $name =~ s/^\"|\"$//g;
563 $address =~ s/^\s+|\s+$//g;
565 if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
566 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
572 $formatted_email = "$address";
574 $formatted_email = "$name <$address>";
577 $formatted_email = $address;
580 return $formatted_email;
583 sub find_first_section
{
586 while ($index < @typevalue) {
587 my $tv = $typevalue[$index];
588 if (($tv =~ m/^(\C):\s*(.*)/)) {
597 sub find_starting_index
{
601 my $tv = $typevalue[$index];
602 if (!($tv =~ m/^(\C):\s*(.*)/)) {
611 sub find_ending_index
{
614 while ($index < @typevalue) {
615 my $tv = $typevalue[$index];
616 if (!($tv =~ m/^(\C):\s*(.*)/)) {
625 sub get_maintainer_role
{
629 my $start = find_starting_index
($index);
630 my $end = find_ending_index
($index);
633 my $subsystem = $typevalue[$start];
634 if (length($subsystem) > 20) {
635 $subsystem = substr($subsystem, 0, 17);
636 $subsystem =~ s/\s*$//;
637 $subsystem = $subsystem . "...";
640 for ($i = $start + 1; $i < $end; $i++) {
641 my $tv = $typevalue[$i];
642 if ($tv =~ m/^(\C):\s*(.*)/) {
652 if ($role eq "supported") {
654 } elsif ($role eq "maintained") {
655 $role = "maintainer";
656 } elsif ($role eq "odd fixes") {
658 } elsif ($role eq "orphan") {
659 $role = "orphan minder";
660 } elsif ($role eq "obsolete") {
661 $role = "obsolete minder";
662 } elsif ($role eq "buried alive in reporters") {
663 $role = "chief penguin";
666 return $role . ":" . $subsystem;
673 my $start = find_starting_index
($index);
674 my $end = find_ending_index
($index);
676 my $subsystem = $typevalue[$start];
677 if (length($subsystem) > 20) {
678 $subsystem = substr($subsystem, 0, 17);
679 $subsystem =~ s/\s*$//;
680 $subsystem = $subsystem . "...";
683 if ($subsystem eq "THE REST") {
694 my $start = find_starting_index
($index);
695 my $end = find_ending_index
($index);
697 push(@subsystem, $typevalue[$start]);
699 for ($i = $start + 1; $i < $end; $i++) {
700 my $tv = $typevalue[$i];
701 if ($tv =~ m/^(\C):\s*(.*)/) {
705 my $list_address = $pvalue;
706 my $list_additional = "";
707 my $list_role = get_list_role
($i);
709 if ($list_role ne "") {
710 $list_role = ":" . $list_role;
712 if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
714 $list_additional = $2;
716 if ($list_additional =~ m/subscribers-only/) {
717 if ($email_subscriber_list) {
718 push(@list_to, [$list_address, "subscriber list${list_role}"]);
722 push(@list_to, [$list_address, "open list${list_role}"]);
725 } elsif ($ptype eq "M") {
726 my ($name, $address) = parse_email
($pvalue);
729 my $tv = $typevalue[$i - 1];
730 if ($tv =~ m/^(\C):\s*(.*)/) {
733 $pvalue = format_email
($name, $address, $email_usename);
738 if ($email_maintainer) {
739 my $role = get_maintainer_role
($i);
740 push_email_addresses
($pvalue, $role);
742 } elsif ($ptype eq "T") {
744 } elsif ($ptype eq "W") {
746 } elsif ($ptype eq "S") {
747 push(@status, $pvalue);
754 my %email_hash_address;
757 my ($name, $address) = @_;
759 return 1 if (($name eq "") && ($address eq ""));
760 return 1 if (($name ne "") && exists($email_hash_name{$name}));
761 return 1 if (($address ne "") && exists($email_hash_address{$address}));
766 sub push_email_address
{
767 my ($line, $role) = @_;
769 my ($name, $address) = parse_email
($line);
771 if ($address eq "") {
775 if (!$email_remove_duplicates) {
776 push(@email_to, [format_email
($name, $address, $email_usename), $role]);
777 } elsif (!email_inuse
($name, $address)) {
778 push(@email_to, [format_email
($name, $address, $email_usename), $role]);
779 $email_hash_name{$name}++;
780 $email_hash_address{$address}++;
786 sub push_email_addresses
{
787 my ($address, $role) = @_;
789 my @address_list = ();
791 if (rfc822_valid
($address)) {
792 push_email_address
($address, $role);
793 } elsif (@address_list = rfc822_validlist
($address)) {
794 my $array_count = shift(@address_list);
795 while (my $entry = shift(@address_list)) {
796 push_email_address
($entry, $role);
799 if (!push_email_address
($address, $role)) {
800 warn("Invalid MAINTAINERS address: '" . $address . "'\n");
806 my ($line, $role) = @_;
808 my ($name, $address) = parse_email
($line);
809 my $email = format_email
($name, $address, $email_usename);
811 foreach my $entry (@email_to) {
812 if ($email_remove_duplicates) {
813 my ($entry_name, $entry_address) = parse_email
($entry->[0]);
814 if ($name eq $entry_name || $address eq $entry_address) {
815 if ($entry->[1] eq "") {
816 $entry->[1] = "$role";
818 $entry->[1] = "$entry->[1],$role";
822 if ($email eq $entry->[0]) {
823 if ($entry->[1] eq "") {
824 $entry->[1] = "$role";
826 $entry->[1] = "$entry->[1],$role";
836 foreach my $path (split(/:/, $ENV{PATH
})) {
837 if (-e
"$path/$bin") {
849 foreach my $line (@lines) {
850 my ($name, $address) = parse_email
($line);
851 if (!exists($hash{$name})) {
852 $hash{$name} = $address;
853 } elsif ($address ne $hash{$name}) {
854 $address = $hash{$name};
855 $line = format_email
($name, $address, $email_usename);
857 if (exists($mailmap{$name})) {
858 my $obj = $mailmap{$name};
859 foreach my $map_address (@
$obj) {
860 if (($map_address eq $address) &&
861 ($map_address ne $hash{$name})) {
862 $line = format_email
($name, $hash{$name}, $email_usename);
871 sub git_execute_cmd
{
876 $output =~ s/^\s*//gm;
877 @lines = split("\n", $output);
887 @lines = split("\n", $output);
892 sub vcs_find_signers
{
897 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
899 my $pattern = $VCS_cmds{"commit_pattern"};
901 $commits = grep(/$pattern/, @lines); # of commits
903 @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines);
904 if (!$email_git_penguin_chiefs) {
905 @lines = grep(!/${penguin_chiefs}/i, @lines);
908 s/.*:\s*(.+)\s*/$1/ for (@lines);
910 ## Reformat email addresses (with names) to avoid badly written signatures
912 foreach my $line (@lines) {
913 my ($name, $address) = parse_email
($line);
914 $line = format_email
($name, $address, 1);
917 return ($commits, @lines);
920 sub vcs_save_commits
{
925 @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
927 foreach my $line (@lines) {
928 if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) {
941 return @commits if (!(-f
$file));
943 if (@range && $VCS_cmds{"blame_range_cmd"} eq "") {
944 my @all_commits = ();
946 $cmd = $VCS_cmds{"blame_file_cmd"};
947 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
948 @all_commits = vcs_save_commits
($cmd);
950 foreach my $file_range_diff (@range) {
951 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
954 my $diff_length = $3;
955 next if ("$file" ne "$diff_file");
956 for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) {
957 push(@commits, $all_commits[$i]);
961 foreach my $file_range_diff (@range) {
962 next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
965 my $diff_length = $3;
966 next if ("$file" ne "$diff_file");
967 $cmd = $VCS_cmds{"blame_range_cmd"};
968 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
969 push(@commits, vcs_save_commits
($cmd));
972 $cmd = $VCS_cmds{"blame_file_cmd"};
973 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
974 @commits = vcs_save_commits
($cmd);
980 my $printed_novcs = 0;
982 %VCS_cmds = %VCS_cmds_git;
983 return 1 if eval $VCS_cmds{"available"};
984 %VCS_cmds = %VCS_cmds_hg;
985 return 1 if eval $VCS_cmds{"available"};
987 if (!$printed_novcs) {
988 warn("$P: No supported VCS found. Add --nogit to options?\n");
989 warn("Using a git repository produces better results.\n");
990 warn("Try Linus Torvalds' latest git repository using:\n");
991 warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n");
998 my ($role, $divisor, @lines) = @_;
1003 return if (@lines <= 0);
1005 if ($divisor <= 0) {
1006 warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n");
1010 if ($email_remove_duplicates) {
1011 @lines = mailmap
(@lines);
1014 @lines = sort(@lines);
1017 $hash{$_}++ for @lines;
1020 foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
1021 my $sign_offs = $hash{$line};
1022 my $percent = $sign_offs * 100 / $divisor;
1024 $percent = 100 if ($percent > 100);
1026 last if ($sign_offs < $email_git_min_signatures ||
1027 $count > $email_git_max_maintainers ||
1028 $percent < $email_git_min_percent);
1029 push_email_address
($line, '');
1030 if ($output_rolestats) {
1031 my $fmt_percent = sprintf("%.0f", $percent);
1032 add_role
($line, "$role:$sign_offs/$divisor=$fmt_percent%");
1034 add_role
($line, $role);
1039 sub vcs_file_signoffs
{
1045 return if (!vcs_exists
());
1047 my $cmd = $VCS_cmds{"find_signers_cmd"};
1048 $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
1050 ($commits, @signers) = vcs_find_signers
($cmd);
1051 vcs_assign
("commit_signer", $commits, @signers);
1054 sub vcs_file_blame
{
1061 return if (!vcs_exists
());
1063 @commits = vcs_blame
($file);
1064 @commits = uniq
(@commits);
1065 $total_commits = @commits;
1067 foreach my $commit (@commits) {
1069 my @commit_signers = ();
1071 my $cmd = $VCS_cmds{"find_commit_signers_cmd"};
1072 $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1074 ($commit_count, @commit_signers) = vcs_find_signers
($cmd);
1075 push(@signers, @commit_signers);
1078 if ($from_filename) {
1079 vcs_assign
("commits", $total_commits, @signers);
1081 vcs_assign
("modified commits", $total_commits, @signers);
1089 @parms = grep(!$saw{$_}++, @parms);
1097 @parms = sort @parms;
1098 @parms = grep(!$saw{$_}++, @parms);
1107 my ($address, $role) = @
$_;
1108 if (!$saw{$address}) {
1109 if ($output_roles) {
1110 push(@lines, "$address ($role)");
1112 push(@lines, $address);
1124 if ($output_multiline) {
1125 foreach my $line (@parms) {
1129 print(join($output_separator, @parms));
1137 # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
1138 # comment. We must allow for rfc822_lwsp (or comments) after each of these.
1139 # This regexp will only work on addresses which have had comments stripped
1140 # and replaced with rfc822_lwsp.
1142 my $specials = '()<>@,;:\\\\".\\[\\]';
1143 my $controls = '\\000-\\037\\177';
1145 my $dtext = "[^\\[\\]\\r\\\\]";
1146 my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
1148 my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
1150 # Use zero-width assertion to spot the limit of an atom. A simple
1151 # $rfc822_lwsp* causes the regexp engine to hang occasionally.
1152 my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
1153 my $word = "(?:$atom|$quoted_string)";
1154 my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
1156 my $sub_domain = "(?:$atom|$domain_literal)";
1157 my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
1159 my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
1161 my $phrase = "$word*";
1162 my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
1163 my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
1164 my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
1166 my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
1167 my $address = "(?:$mailbox|$group)";
1169 return "$rfc822_lwsp*$address";
1172 sub rfc822_strip_comments
{
1174 # Recursively remove comments, and replace with a single space. The simpler
1175 # regexps in the Email Addressing FAQ are imperfect - they will miss escaped
1176 # chars in atoms, for example.
1178 while ($s =~ s
/^((?
:[^"\\]|\\.)*
1179 (?:"(?
:[^"\\]|\\.)*"(?
:[^"\\]|\\.)*)*)
1180 \((?:[^()\\]|\\.)*\)/$1 /osx) {}
1184 # valid: returns true if the parameter is an RFC822 valid address
1186 sub rfc822_valid ($) {
1187 my $s = rfc822_strip_comments(shift);
1190 $rfc822re = make_rfc822re();
1193 return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
1196 # validlist: In scalar context, returns true if the parameter is an RFC822
1197 # valid list of addresses.
1199 # In list context, returns an empty list on failure (an invalid
1200 # address was found); otherwise a list whose first element is the
1201 # number of addresses found and whose remaining elements are the
1202 # addresses. This is needed to disambiguate failure (invalid)
1203 # from success with no addresses found, because an empty string is
1206 sub rfc822_validlist ($) {
1207 my $s = rfc822_strip_comments(shift);
1210 $rfc822re = make_rfc822re();
1212 # * null list items are valid according to the RFC
1213 # * the '1' business is to aid in distinguishing failure from no results
1216 if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
1217 $s =~ m/^$rfc822_char*$/) {
1218 while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
1221 return wantarray ? (scalar(@r), @r) : 1;
1223 return wantarray ? () : 0;