Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | # (c) 2007, Joe Perches <joe@perches.com> |
| 3 | # created from checkpatch.pl |
| 4 | # |
| 5 | # Print selected MAINTAINERS information for |
| 6 | # the files modified in a patch or for a file |
| 7 | # |
Roel Kluin | 3bd7bf5 | 2009-11-11 14:26:13 -0800 | [diff] [blame] | 8 | # usage: perl scripts/get_maintainer.pl [OPTIONS] <patch> |
| 9 | # perl scripts/get_maintainer.pl [OPTIONS] -f <file> |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 10 | # |
| 11 | # Licensed under the terms of the GNU GPL License version 2 |
| 12 | |
| 13 | use strict; |
| 14 | |
| 15 | my $P = $0; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 16 | my $V = '0.23'; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 17 | |
| 18 | use Getopt::Long qw(:config no_auto_abbrev); |
| 19 | |
| 20 | my $lk_path = "./"; |
| 21 | my $email = 1; |
| 22 | my $email_usename = 1; |
| 23 | my $email_maintainer = 1; |
| 24 | my $email_list = 1; |
| 25 | my $email_subscriber_list = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 26 | my $email_git_penguin_chiefs = 0; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 27 | my $email_git = 1; |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 28 | my $email_git_all_signature_types = 1; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 29 | my $email_git_blame = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 30 | my $email_git_min_signatures = 1; |
| 31 | my $email_git_max_maintainers = 5; |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 32 | my $email_git_min_percent = 5; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 33 | my $email_git_since = "1-year-ago"; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 34 | my $email_hg_since = "-365"; |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 35 | my $email_remove_duplicates = 1; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 36 | my $output_multiline = 1; |
| 37 | my $output_separator = ", "; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 38 | my $output_roles = 0; |
| 39 | my $output_rolestats = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 40 | my $scm = 0; |
| 41 | my $web = 0; |
| 42 | my $subsystem = 0; |
| 43 | my $status = 0; |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 44 | my $keywords = 1; |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 45 | my $sections = 0; |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 46 | my $file_emails = 0; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 47 | my $from_filename = 0; |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 48 | my $pattern_depth = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 49 | my $version = 0; |
| 50 | my $help = 0; |
| 51 | |
| 52 | my $exit = 0; |
| 53 | |
| 54 | my @penguin_chief = (); |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 55 | push(@penguin_chief, "Linus Torvalds:torvalds\@linux-foundation.org"); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 56 | #Andrew wants in on most everything - 2009/01/14 |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 57 | #push(@penguin_chief, "Andrew Morton:akpm\@linux-foundation.org"); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 58 | |
| 59 | my @penguin_chief_names = (); |
| 60 | foreach my $chief (@penguin_chief) { |
| 61 | if ($chief =~ m/^(.*):(.*)/) { |
| 62 | my $chief_name = $1; |
| 63 | my $chief_addr = $2; |
| 64 | push(@penguin_chief_names, $chief_name); |
| 65 | } |
| 66 | } |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 67 | my $penguin_chiefs = "\(" . join("|", @penguin_chief_names) . "\)"; |
| 68 | |
| 69 | # Signature types of people who are either |
| 70 | # a) responsible for the code in question, or |
| 71 | # b) familiar enough with it to give relevant feedback |
| 72 | my @signature_tags = (); |
| 73 | push(@signature_tags, "Signed-off-by:"); |
| 74 | push(@signature_tags, "Reviewed-by:"); |
| 75 | push(@signature_tags, "Acked-by:"); |
| 76 | my $signaturePattern = "\(" . join("|", @signature_tags) . "\)"; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 77 | |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 78 | # rfc822 email address - preloaded methods go here. |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 79 | my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; |
Joe Perches | df4cc03 | 2009-06-16 15:34:04 -0700 | [diff] [blame] | 80 | my $rfc822_char = '[\\000-\\377]'; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 81 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 82 | # VCS command support: class-like functions and strings |
| 83 | |
| 84 | my %VCS_cmds; |
| 85 | |
| 86 | my %VCS_cmds_git = ( |
| 87 | "execute_cmd" => \&git_execute_cmd, |
| 88 | "available" => '(which("git") ne "") && (-d ".git")', |
Richard Kennedy | 99cf611 | 2010-02-02 13:44:07 -0800 | [diff] [blame] | 89 | "find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file", |
| 90 | "find_commit_signers_cmd" => "git log --no-color -1 \$commit", |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 91 | "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file", |
| 92 | "blame_file_cmd" => "git blame -l \$file", |
| 93 | "commit_pattern" => "^commit [0-9a-f]{40,40}", |
| 94 | "blame_commit_pattern" => "^([0-9a-f]+) " |
| 95 | ); |
| 96 | |
| 97 | my %VCS_cmds_hg = ( |
| 98 | "execute_cmd" => \&hg_execute_cmd, |
| 99 | "available" => '(which("hg") ne "") && (-d ".hg")', |
| 100 | "find_signers_cmd" => |
| 101 | "hg log --date=\$email_hg_since" . |
| 102 | " --template='commit {node}\\n{desc}\\n' -- \$file", |
| 103 | "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit", |
| 104 | "blame_range_cmd" => "", # not supported |
| 105 | "blame_file_cmd" => "hg blame -c \$file", |
| 106 | "commit_pattern" => "^commit [0-9a-f]{40,40}", |
| 107 | "blame_commit_pattern" => "^([0-9a-f]+):" |
| 108 | ); |
| 109 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 110 | if (!GetOptions( |
| 111 | 'email!' => \$email, |
| 112 | 'git!' => \$email_git, |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 113 | 'git-all-signature-types!' => \$email_git_all_signature_types, |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 114 | 'git-blame!' => \$email_git_blame, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 115 | 'git-chief-penguins!' => \$email_git_penguin_chiefs, |
| 116 | 'git-min-signatures=i' => \$email_git_min_signatures, |
| 117 | 'git-max-maintainers=i' => \$email_git_max_maintainers, |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 118 | 'git-min-percent=i' => \$email_git_min_percent, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 119 | 'git-since=s' => \$email_git_since, |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 120 | 'hg-since=s' => \$email_hg_since, |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 121 | 'remove-duplicates!' => \$email_remove_duplicates, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 122 | 'm!' => \$email_maintainer, |
| 123 | 'n!' => \$email_usename, |
| 124 | 'l!' => \$email_list, |
| 125 | 's!' => \$email_subscriber_list, |
| 126 | 'multiline!' => \$output_multiline, |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 127 | 'roles!' => \$output_roles, |
| 128 | 'rolestats!' => \$output_rolestats, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 129 | 'separator=s' => \$output_separator, |
| 130 | 'subsystem!' => \$subsystem, |
| 131 | 'status!' => \$status, |
| 132 | 'scm!' => \$scm, |
| 133 | 'web!' => \$web, |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 134 | 'pattern-depth=i' => \$pattern_depth, |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 135 | 'k|keywords!' => \$keywords, |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 136 | 'sections!' => \$sections, |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 137 | 'fe|file-emails!' => \$file_emails, |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 138 | 'f|file' => \$from_filename, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 139 | 'v|version' => \$version, |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame] | 140 | 'h|help|usage' => \$help, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 141 | )) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 142 | die "$P: invalid argument - use --help if necessary\n"; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | if ($help != 0) { |
| 146 | usage(); |
| 147 | exit 0; |
| 148 | } |
| 149 | |
| 150 | if ($version != 0) { |
| 151 | print("${P} ${V}\n"); |
| 152 | exit 0; |
| 153 | } |
| 154 | |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame] | 155 | if (-t STDIN && !@ARGV) { |
| 156 | # We're talking to a terminal, but have no command line arguments. |
| 157 | die "$P: missing patchfile or -f file - use --help if necessary\n"; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Joe Perches | 4249831 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 160 | if ($output_separator ne ", ") { |
| 161 | $output_multiline = 0; |
| 162 | } |
| 163 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 164 | if ($output_rolestats) { |
| 165 | $output_roles = 1; |
| 166 | } |
| 167 | |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 168 | if ($sections) { |
| 169 | $email = 0; |
| 170 | $email_list = 0; |
| 171 | $scm = 0; |
| 172 | $status = 0; |
| 173 | $subsystem = 0; |
| 174 | $web = 0; |
| 175 | $keywords = 0; |
| 176 | } else { |
| 177 | my $selections = $email + $scm + $status + $subsystem + $web; |
| 178 | if ($selections == 0) { |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 179 | die "$P: Missing required option: email, scm, status, subsystem or web\n"; |
| 180 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 183 | if ($email && |
| 184 | ($email_maintainer + $email_list + $email_subscriber_list + |
| 185 | $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 186 | die "$P: Please select at least 1 email option\n"; |
| 187 | } |
| 188 | |
| 189 | if (!top_of_kernel_tree($lk_path)) { |
| 190 | die "$P: The current directory does not appear to be " |
| 191 | . "a linux kernel source tree.\n"; |
| 192 | } |
| 193 | |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 194 | if ($email_git_all_signature_types) { |
| 195 | $signaturePattern = "(.+?)[Bb][Yy]:"; |
| 196 | } |
| 197 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 198 | ## Read MAINTAINERS for type/value pairs |
| 199 | |
| 200 | my @typevalue = (); |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 201 | my %keyword_hash; |
| 202 | |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 203 | open (my $maint, '<', "${lk_path}MAINTAINERS") |
| 204 | or die "$P: Can't open MAINTAINERS: $!\n"; |
| 205 | while (<$maint>) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 206 | my $line = $_; |
| 207 | |
| 208 | if ($line =~ m/^(\C):\s*(.*)/) { |
| 209 | my $type = $1; |
| 210 | my $value = $2; |
| 211 | |
| 212 | ##Filename pattern matching |
| 213 | if ($type eq "F" || $type eq "X") { |
| 214 | $value =~ s@\.@\\\.@g; ##Convert . to \. |
| 215 | $value =~ s/\*/\.\*/g; ##Convert * to .* |
| 216 | $value =~ s/\?/\./g; ##Convert ? to . |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 217 | ##if pattern is a directory and it lacks a trailing slash, add one |
| 218 | if ((-d $value)) { |
| 219 | $value =~ s@([^/])$@$1/@; |
| 220 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 221 | } elsif ($type eq "K") { |
| 222 | $keyword_hash{@typevalue} = $value; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 223 | } |
| 224 | push(@typevalue, "$type:$value"); |
| 225 | } elsif (!/^(\s)*$/) { |
| 226 | $line =~ s/\n$//g; |
| 227 | push(@typevalue, $line); |
| 228 | } |
| 229 | } |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 230 | close($maint); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 231 | |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 232 | my %mailmap; |
| 233 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 234 | if ($email_remove_duplicates) { |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 235 | open(my $mailmap, '<', "${lk_path}.mailmap") |
| 236 | or warn "$P: Can't open .mailmap: $!\n"; |
| 237 | while (<$mailmap>) { |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 238 | my $line = $_; |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 239 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 240 | next if ($line =~ m/^\s*#/); |
| 241 | next if ($line =~ m/^\s*$/); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 242 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 243 | my ($name, $address) = parse_email($line); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 244 | $line = format_email($name, $address, $email_usename); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 245 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 246 | next if ($line =~ m/^\s*$/); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 247 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 248 | if (exists($mailmap{$name})) { |
| 249 | my $obj = $mailmap{$name}; |
| 250 | push(@$obj, $address); |
| 251 | } else { |
| 252 | my @arr = ($address); |
| 253 | $mailmap{$name} = \@arr; |
| 254 | } |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 255 | } |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 256 | close($mailmap); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 259 | ## use the filenames on the command line or find the filenames in the patchfiles |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 260 | |
| 261 | my @files = (); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 262 | my @range = (); |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 263 | my @keyword_tvi = (); |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 264 | my @file_emails = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 265 | |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame] | 266 | if (!@ARGV) { |
| 267 | push(@ARGV, "&STDIN"); |
| 268 | } |
| 269 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 270 | foreach my $file (@ARGV) { |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame] | 271 | if ($file ne "&STDIN") { |
| 272 | ##if $file is a directory and it lacks a trailing slash, add one |
| 273 | if ((-d $file)) { |
| 274 | $file =~ s@([^/])$@$1/@; |
| 275 | } elsif (!(-f $file)) { |
| 276 | die "$P: file '${file}' not found\n"; |
| 277 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 278 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 279 | if ($from_filename) { |
| 280 | push(@files, $file); |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 281 | if (-f $file && ($keywords || $file_emails)) { |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 282 | open(my $f, '<', $file) |
| 283 | or die "$P: Can't open $file: $!\n"; |
| 284 | my $text = do { local($/) ; <$f> }; |
| 285 | close($f); |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 286 | if ($keywords) { |
| 287 | foreach my $line (keys %keyword_hash) { |
| 288 | if ($text =~ m/$keyword_hash{$line}/x) { |
| 289 | push(@keyword_tvi, $line); |
| 290 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 291 | } |
| 292 | } |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 293 | if ($file_emails) { |
| 294 | 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; |
| 295 | push(@file_emails, clean_file_emails(@poss_addr)); |
| 296 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 297 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 298 | } else { |
| 299 | my $file_cnt = @files; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 300 | my $lastfile; |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 301 | |
Wolfram Sang | 3a4df13 | 2010-03-23 13:35:18 -0700 | [diff] [blame] | 302 | open(my $patch, "< $file") |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 303 | or die "$P: Can't open $file: $!\n"; |
| 304 | while (<$patch>) { |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 305 | my $patch_line = $_; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 306 | if (m/^\+\+\+\s+(\S+)/) { |
| 307 | my $filename = $1; |
| 308 | $filename =~ s@^[^/]*/@@; |
| 309 | $filename =~ s@\n@@; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 310 | $lastfile = $filename; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 311 | push(@files, $filename); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 312 | } elsif (m/^\@\@ -(\d+),(\d+)/) { |
| 313 | if ($email_git_blame) { |
| 314 | push(@range, "$lastfile:$1:$2"); |
| 315 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 316 | } elsif ($keywords) { |
| 317 | foreach my $line (keys %keyword_hash) { |
| 318 | if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) { |
| 319 | push(@keyword_tvi, $line); |
| 320 | } |
| 321 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 322 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 323 | } |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 324 | close($patch); |
| 325 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 326 | if ($file_cnt == @files) { |
Joe Perches | 7f29fd27 | 2009-06-16 15:34:04 -0700 | [diff] [blame] | 327 | warn "$P: file '${file}' doesn't appear to be a patch. " |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 328 | . "Add -f to options?\n"; |
| 329 | } |
| 330 | @files = sort_and_uniq(@files); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 331 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 334 | @file_emails = uniq(@file_emails); |
| 335 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 336 | my @email_to = (); |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 337 | my @list_to = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 338 | my @scm = (); |
| 339 | my @web = (); |
| 340 | my @subsystem = (); |
| 341 | my @status = (); |
| 342 | |
| 343 | # Find responsible parties |
| 344 | |
| 345 | foreach my $file (@files) { |
| 346 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 347 | my %hash; |
| 348 | my $tvi = find_first_section(); |
| 349 | while ($tvi < @typevalue) { |
| 350 | my $start = find_starting_index($tvi); |
| 351 | my $end = find_ending_index($tvi); |
| 352 | my $exclude = 0; |
| 353 | my $i; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 354 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 355 | #Do not match excluded file patterns |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 356 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 357 | for ($i = $start; $i < $end; $i++) { |
| 358 | my $line = $typevalue[$i]; |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 359 | if ($line =~ m/^(\C):\s*(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 360 | my $type = $1; |
| 361 | my $value = $2; |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 362 | if ($type eq 'X') { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 363 | if (file_match_pattern($file, $value)) { |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 364 | $exclude = 1; |
Joe Perches | 3c840c1 | 2010-03-05 13:43:07 -0800 | [diff] [blame] | 365 | last; |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (!$exclude) { |
| 372 | for ($i = $start; $i < $end; $i++) { |
| 373 | my $line = $typevalue[$i]; |
| 374 | if ($line =~ m/^(\C):\s*(.*)/) { |
| 375 | my $type = $1; |
| 376 | my $value = $2; |
| 377 | if ($type eq 'F') { |
| 378 | if (file_match_pattern($file, $value)) { |
| 379 | my $value_pd = ($value =~ tr@/@@); |
| 380 | my $file_pd = ($file =~ tr@/@@); |
| 381 | $value_pd++ if (substr($value,-1,1) ne "/"); |
| 382 | if ($pattern_depth == 0 || |
| 383 | (($file_pd - $value_pd) < $pattern_depth)) { |
| 384 | $hash{$tvi} = $value_pd; |
| 385 | } |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 386 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 390 | } |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 391 | |
Joe Perches | 3c840c1 | 2010-03-05 13:43:07 -0800 | [diff] [blame] | 392 | $tvi = $end + 1; |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
| 396 | add_categories($line); |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 397 | if ($sections) { |
| 398 | my $i; |
| 399 | my $start = find_starting_index($line); |
| 400 | my $end = find_ending_index($line); |
| 401 | for ($i = $start; $i < $end; $i++) { |
| 402 | my $line = $typevalue[$i]; |
| 403 | if ($line =~ /^[FX]:/) { ##Restore file patterns |
| 404 | $line =~ s/([^\\])\.([^\*])/$1\?$2/g; |
| 405 | $line =~ s/([^\\])\.$/$1\?/g; ##Convert . back to ? |
| 406 | $line =~ s/\\\./\./g; ##Convert \. to . |
| 407 | $line =~ s/\.\*/\*/g; ##Convert .* to * |
| 408 | } |
Joe Perches | f11e9a1 | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 409 | $line =~ s/^([A-Z]):/$1:\t/g; |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 410 | print("$line\n"); |
| 411 | } |
Joe Perches | f11e9a1 | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 412 | print("\n"); |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 413 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 416 | if ($email && $email_git) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 417 | vcs_file_signoffs($file); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 420 | if ($email && $email_git_blame) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 421 | vcs_file_blame($file); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 422 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 425 | if ($keywords) { |
| 426 | @keyword_tvi = sort_and_uniq(@keyword_tvi); |
| 427 | foreach my $line (@keyword_tvi) { |
| 428 | add_categories($line); |
| 429 | } |
| 430 | } |
| 431 | |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 432 | if ($email) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 433 | foreach my $chief (@penguin_chief) { |
| 434 | if ($chief =~ m/^(.*):(.*)/) { |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 435 | my $email_address; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 436 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 437 | $email_address = format_email($1, $2, $email_usename); |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 438 | if ($email_git_penguin_chiefs) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 439 | push(@email_to, [$email_address, 'chief penguin']); |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 440 | } else { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 441 | @email_to = grep($_->[0] !~ /${email_address}/, @email_to); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | } |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 445 | |
| 446 | foreach my $email (@file_emails) { |
| 447 | my ($name, $address) = parse_email($email); |
| 448 | |
| 449 | my $tmp_email = format_email($name, $address, $email_usename); |
| 450 | push_email_address($tmp_email, ''); |
| 451 | add_role($tmp_email, 'in file'); |
| 452 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 455 | if ($email || $email_list) { |
| 456 | my @to = (); |
| 457 | if ($email) { |
| 458 | @to = (@to, @email_to); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 459 | } |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 460 | if ($email_list) { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 461 | @to = (@to, @list_to); |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 462 | } |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 463 | output(merge_email(@to)); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | if ($scm) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 467 | @scm = uniq(@scm); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 468 | output(@scm); |
| 469 | } |
| 470 | |
| 471 | if ($status) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 472 | @status = uniq(@status); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 473 | output(@status); |
| 474 | } |
| 475 | |
| 476 | if ($subsystem) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 477 | @subsystem = uniq(@subsystem); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 478 | output(@subsystem); |
| 479 | } |
| 480 | |
| 481 | if ($web) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 482 | @web = uniq(@web); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 483 | output(@web); |
| 484 | } |
| 485 | |
| 486 | exit($exit); |
| 487 | |
| 488 | sub file_match_pattern { |
| 489 | my ($file, $pattern) = @_; |
| 490 | if (substr($pattern, -1) eq "/") { |
| 491 | if ($file =~ m@^$pattern@) { |
| 492 | return 1; |
| 493 | } |
| 494 | } else { |
| 495 | if ($file =~ m@^$pattern@) { |
| 496 | my $s1 = ($file =~ tr@/@@); |
| 497 | my $s2 = ($pattern =~ tr@/@@); |
| 498 | if ($s1 == $s2) { |
| 499 | return 1; |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | sub usage { |
| 507 | print <<EOT; |
| 508 | usage: $P [options] patchfile |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 509 | $P [options] -f file|directory |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 510 | version: $V |
| 511 | |
| 512 | MAINTAINER field selection options: |
| 513 | --email => print email address(es) if any |
| 514 | --git => include recent git \*-by: signers |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 515 | --git-all-signature-types => include signers regardless of signature type |
| 516 | or use only ${signaturePattern} signers (default: $email_git_all_signature_types) |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 517 | --git-chief-penguins => include ${penguin_chiefs} |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 518 | --git-min-signatures => number of signatures required (default: $email_git_min_signatures) |
| 519 | --git-max-maintainers => maximum maintainers to add (default: $email_git_max_maintainers) |
| 520 | --git-min-percent => minimum percentage of commits required (default: $email_git_min_percent) |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 521 | --git-blame => use git blame to find modified commits for patch or file |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 522 | --git-since => git history to use (default: $email_git_since) |
| 523 | --hg-since => hg history to use (default: $email_hg_since) |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 524 | --m => include maintainer(s) if any |
| 525 | --n => include name 'Full Name <addr\@domain.tld>' |
| 526 | --l => include list(s) if any |
| 527 | --s => include subscriber only list(s) if any |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 528 | --remove-duplicates => minimize duplicate email names/addresses |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 529 | --roles => show roles (status:subsystem, git-signer, list, etc...) |
| 530 | --rolestats => show roles and statistics (commits/total_commits, %) |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 531 | --file-emails => add email addresses found in -f file (default: 0 (off)) |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 532 | --scm => print SCM tree(s) if any |
| 533 | --status => print status if any |
| 534 | --subsystem => print subsystem name if any |
| 535 | --web => print website(s) if any |
| 536 | |
| 537 | Output type options: |
| 538 | --separator [, ] => separator for multiple entries on 1 line |
Joe Perches | 4249831 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 539 | using --separator also sets --nomultiline if --separator is not [, ] |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 540 | --multiline => print 1 entry per line |
| 541 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 542 | Other options: |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 543 | --pattern-depth => Number of pattern directory traversals (default: 0 (all)) |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 544 | --keywords => scan patch for keywords (default: 1 (on)) |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 545 | --sections => print the entire subsystem sections with pattern matches |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 546 | --version => show version |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 547 | --help => show this help information |
| 548 | |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 549 | Default options: |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 550 | [--email --git --m --n --l --multiline --pattern-depth=0 --remove-duplicates] |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 551 | |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 552 | Notes: |
| 553 | Using "-f directory" may give unexpected results: |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 554 | Used with "--git", git signators for _all_ files in and below |
| 555 | directory are examined as git recurses directories. |
| 556 | Any specified X: (exclude) pattern matches are _not_ ignored. |
| 557 | Used with "--nogit", directory is used as a pattern match, |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 558 | no individual file within the directory or subdirectory |
| 559 | is matched. |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 560 | Used with "--git-blame", does not iterate all files in directory |
| 561 | Using "--git-blame" is slow and may add old committers and authors |
| 562 | that are no longer active maintainers to the output. |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 563 | Using "--roles" or "--rolestats" with git send-email --cc-cmd or any |
| 564 | other automated tools that expect only ["name"] <email address> |
| 565 | may not work because of additional output after <email address>. |
| 566 | Using "--rolestats" and "--git-blame" shows the #/total=% commits, |
| 567 | not the percentage of the entire file authored. # of commits is |
| 568 | not a good measure of amount of code authored. 1 major commit may |
| 569 | contain a thousand lines, 5 trivial commits may modify a single line. |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 570 | If git is not installed, but mercurial (hg) is installed and an .hg |
| 571 | repository exists, the following options apply to mercurial: |
| 572 | --git, |
| 573 | --git-min-signatures, --git-max-maintainers, --git-min-percent, and |
| 574 | --git-blame |
| 575 | Use --hg-since not --git-since to control date selection |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 576 | EOT |
| 577 | } |
| 578 | |
| 579 | sub top_of_kernel_tree { |
| 580 | my ($lk_path) = @_; |
| 581 | |
| 582 | if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") { |
| 583 | $lk_path .= "/"; |
| 584 | } |
| 585 | if ( (-f "${lk_path}COPYING") |
| 586 | && (-f "${lk_path}CREDITS") |
| 587 | && (-f "${lk_path}Kbuild") |
| 588 | && (-f "${lk_path}MAINTAINERS") |
| 589 | && (-f "${lk_path}Makefile") |
| 590 | && (-f "${lk_path}README") |
| 591 | && (-d "${lk_path}Documentation") |
| 592 | && (-d "${lk_path}arch") |
| 593 | && (-d "${lk_path}include") |
| 594 | && (-d "${lk_path}drivers") |
| 595 | && (-d "${lk_path}fs") |
| 596 | && (-d "${lk_path}init") |
| 597 | && (-d "${lk_path}ipc") |
| 598 | && (-d "${lk_path}kernel") |
| 599 | && (-d "${lk_path}lib") |
| 600 | && (-d "${lk_path}scripts")) { |
| 601 | return 1; |
| 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 606 | sub parse_email { |
| 607 | my ($formatted_email) = @_; |
| 608 | |
| 609 | my $name = ""; |
| 610 | my $address = ""; |
| 611 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 612 | if ($formatted_email =~ /^([^<]+)<(.+\@.*)>.*$/) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 613 | $name = $1; |
| 614 | $address = $2; |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 615 | } elsif ($formatted_email =~ /^\s*<(.+\@\S*)>.*$/) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 616 | $address = $1; |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 617 | } elsif ($formatted_email =~ /^(.+\@\S*).*$/) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 618 | $address = $1; |
| 619 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 620 | |
| 621 | $name =~ s/^\s+|\s+$//g; |
Joe Perches | d789504 | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 622 | $name =~ s/^\"|\"$//g; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 623 | $address =~ s/^\s+|\s+$//g; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 624 | |
Stephen Hemminger | a63ceb4 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 625 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 626 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 627 | $name = "\"$name\""; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 628 | } |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 629 | |
| 630 | return ($name, $address); |
| 631 | } |
| 632 | |
| 633 | sub format_email { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 634 | my ($name, $address, $usename) = @_; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 635 | |
| 636 | my $formatted_email; |
| 637 | |
| 638 | $name =~ s/^\s+|\s+$//g; |
| 639 | $name =~ s/^\"|\"$//g; |
| 640 | $address =~ s/^\s+|\s+$//g; |
| 641 | |
Stephen Hemminger | a63ceb4 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 642 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 643 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes |
| 644 | $name = "\"$name\""; |
| 645 | } |
| 646 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 647 | if ($usename) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 648 | if ("$name" eq "") { |
| 649 | $formatted_email = "$address"; |
| 650 | } else { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 651 | $formatted_email = "$name <$address>"; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 652 | } |
| 653 | } else { |
| 654 | $formatted_email = $address; |
| 655 | } |
| 656 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 657 | return $formatted_email; |
| 658 | } |
| 659 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 660 | sub find_first_section { |
| 661 | my $index = 0; |
| 662 | |
| 663 | while ($index < @typevalue) { |
| 664 | my $tv = $typevalue[$index]; |
| 665 | if (($tv =~ m/^(\C):\s*(.*)/)) { |
| 666 | last; |
| 667 | } |
| 668 | $index++; |
| 669 | } |
| 670 | |
| 671 | return $index; |
| 672 | } |
| 673 | |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 674 | sub find_starting_index { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 675 | my ($index) = @_; |
| 676 | |
| 677 | while ($index > 0) { |
| 678 | my $tv = $typevalue[$index]; |
| 679 | if (!($tv =~ m/^(\C):\s*(.*)/)) { |
| 680 | last; |
| 681 | } |
| 682 | $index--; |
| 683 | } |
| 684 | |
| 685 | return $index; |
| 686 | } |
| 687 | |
| 688 | sub find_ending_index { |
| 689 | my ($index) = @_; |
| 690 | |
| 691 | while ($index < @typevalue) { |
| 692 | my $tv = $typevalue[$index]; |
| 693 | if (!($tv =~ m/^(\C):\s*(.*)/)) { |
| 694 | last; |
| 695 | } |
| 696 | $index++; |
| 697 | } |
| 698 | |
| 699 | return $index; |
| 700 | } |
| 701 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 702 | sub get_maintainer_role { |
| 703 | my ($index) = @_; |
| 704 | |
| 705 | my $i; |
| 706 | my $start = find_starting_index($index); |
| 707 | my $end = find_ending_index($index); |
| 708 | |
| 709 | my $role; |
| 710 | my $subsystem = $typevalue[$start]; |
| 711 | if (length($subsystem) > 20) { |
| 712 | $subsystem = substr($subsystem, 0, 17); |
| 713 | $subsystem =~ s/\s*$//; |
| 714 | $subsystem = $subsystem . "..."; |
| 715 | } |
| 716 | |
| 717 | for ($i = $start + 1; $i < $end; $i++) { |
| 718 | my $tv = $typevalue[$i]; |
| 719 | if ($tv =~ m/^(\C):\s*(.*)/) { |
| 720 | my $ptype = $1; |
| 721 | my $pvalue = $2; |
| 722 | if ($ptype eq "S") { |
| 723 | $role = $pvalue; |
| 724 | } |
| 725 | } |
| 726 | } |
| 727 | |
| 728 | $role = lc($role); |
| 729 | if ($role eq "supported") { |
| 730 | $role = "supporter"; |
| 731 | } elsif ($role eq "maintained") { |
| 732 | $role = "maintainer"; |
| 733 | } elsif ($role eq "odd fixes") { |
| 734 | $role = "odd fixer"; |
| 735 | } elsif ($role eq "orphan") { |
| 736 | $role = "orphan minder"; |
| 737 | } elsif ($role eq "obsolete") { |
| 738 | $role = "obsolete minder"; |
| 739 | } elsif ($role eq "buried alive in reporters") { |
| 740 | $role = "chief penguin"; |
| 741 | } |
| 742 | |
| 743 | return $role . ":" . $subsystem; |
| 744 | } |
| 745 | |
| 746 | sub get_list_role { |
| 747 | my ($index) = @_; |
| 748 | |
| 749 | my $i; |
| 750 | my $start = find_starting_index($index); |
| 751 | my $end = find_ending_index($index); |
| 752 | |
| 753 | my $subsystem = $typevalue[$start]; |
| 754 | if (length($subsystem) > 20) { |
| 755 | $subsystem = substr($subsystem, 0, 17); |
| 756 | $subsystem =~ s/\s*$//; |
| 757 | $subsystem = $subsystem . "..."; |
| 758 | } |
| 759 | |
| 760 | if ($subsystem eq "THE REST") { |
| 761 | $subsystem = ""; |
| 762 | } |
| 763 | |
| 764 | return $subsystem; |
| 765 | } |
| 766 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 767 | sub add_categories { |
| 768 | my ($index) = @_; |
| 769 | |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 770 | my $i; |
| 771 | my $start = find_starting_index($index); |
| 772 | my $end = find_ending_index($index); |
| 773 | |
| 774 | push(@subsystem, $typevalue[$start]); |
| 775 | |
| 776 | for ($i = $start + 1; $i < $end; $i++) { |
| 777 | my $tv = $typevalue[$i]; |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 778 | if ($tv =~ m/^(\C):\s*(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 779 | my $ptype = $1; |
| 780 | my $pvalue = $2; |
| 781 | if ($ptype eq "L") { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 782 | my $list_address = $pvalue; |
| 783 | my $list_additional = ""; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 784 | my $list_role = get_list_role($i); |
| 785 | |
| 786 | if ($list_role ne "") { |
| 787 | $list_role = ":" . $list_role; |
| 788 | } |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 789 | if ($list_address =~ m/([^\s]+)\s+(.*)$/) { |
| 790 | $list_address = $1; |
| 791 | $list_additional = $2; |
| 792 | } |
Joe Perches | bdf7c68 | 2009-06-16 15:33:59 -0700 | [diff] [blame] | 793 | if ($list_additional =~ m/subscribers-only/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 794 | if ($email_subscriber_list) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 795 | push(@list_to, [$list_address, "subscriber list${list_role}"]); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 796 | } |
| 797 | } else { |
| 798 | if ($email_list) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 799 | push(@list_to, [$list_address, "open list${list_role}"]); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | } elsif ($ptype eq "M") { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 803 | my ($name, $address) = parse_email($pvalue); |
| 804 | if ($name eq "") { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 805 | if ($i > 0) { |
| 806 | my $tv = $typevalue[$i - 1]; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 807 | if ($tv =~ m/^(\C):\s*(.*)/) { |
| 808 | if ($1 eq "P") { |
| 809 | $name = $2; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 810 | $pvalue = format_email($name, $address, $email_usename); |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | } |
| 814 | } |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 815 | if ($email_maintainer) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 816 | my $role = get_maintainer_role($i); |
| 817 | push_email_addresses($pvalue, $role); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 818 | } |
| 819 | } elsif ($ptype eq "T") { |
| 820 | push(@scm, $pvalue); |
| 821 | } elsif ($ptype eq "W") { |
| 822 | push(@web, $pvalue); |
| 823 | } elsif ($ptype eq "S") { |
| 824 | push(@status, $pvalue); |
| 825 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 830 | my %email_hash_name; |
| 831 | my %email_hash_address; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 832 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 833 | sub email_inuse { |
| 834 | my ($name, $address) = @_; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 835 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 836 | return 1 if (($name eq "") && ($address eq "")); |
| 837 | return 1 if (($name ne "") && exists($email_hash_name{$name})); |
| 838 | return 1 if (($address ne "") && exists($email_hash_address{$address})); |
| 839 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 843 | sub push_email_address { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 844 | my ($line, $role) = @_; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 845 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 846 | my ($name, $address) = parse_email($line); |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 847 | |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 848 | if ($address eq "") { |
| 849 | return 0; |
| 850 | } |
| 851 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 852 | if (!$email_remove_duplicates) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 853 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 854 | } elsif (!email_inuse($name, $address)) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 855 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 856 | $email_hash_name{$name}++; |
| 857 | $email_hash_address{$address}++; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 858 | } |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 859 | |
| 860 | return 1; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | sub push_email_addresses { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 864 | my ($address, $role) = @_; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 865 | |
| 866 | my @address_list = (); |
| 867 | |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 868 | if (rfc822_valid($address)) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 869 | push_email_address($address, $role); |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 870 | } elsif (@address_list = rfc822_validlist($address)) { |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 871 | my $array_count = shift(@address_list); |
| 872 | while (my $entry = shift(@address_list)) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 873 | push_email_address($entry, $role); |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 874 | } |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 875 | } else { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 876 | if (!push_email_address($address, $role)) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 877 | warn("Invalid MAINTAINERS address: '" . $address . "'\n"); |
| 878 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 879 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 882 | sub add_role { |
| 883 | my ($line, $role) = @_; |
| 884 | |
| 885 | my ($name, $address) = parse_email($line); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 886 | my $email = format_email($name, $address, $email_usename); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 887 | |
| 888 | foreach my $entry (@email_to) { |
| 889 | if ($email_remove_duplicates) { |
| 890 | my ($entry_name, $entry_address) = parse_email($entry->[0]); |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 891 | if (($name eq $entry_name || $address eq $entry_address) |
| 892 | && ($role eq "" || !($entry->[1] =~ m/$role/)) |
| 893 | ) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 894 | if ($entry->[1] eq "") { |
| 895 | $entry->[1] = "$role"; |
| 896 | } else { |
| 897 | $entry->[1] = "$entry->[1],$role"; |
| 898 | } |
| 899 | } |
| 900 | } else { |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 901 | if ($email eq $entry->[0] |
| 902 | && ($role eq "" || !($entry->[1] =~ m/$role/)) |
| 903 | ) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 904 | if ($entry->[1] eq "") { |
| 905 | $entry->[1] = "$role"; |
| 906 | } else { |
| 907 | $entry->[1] = "$entry->[1],$role"; |
| 908 | } |
| 909 | } |
| 910 | } |
| 911 | } |
| 912 | } |
| 913 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 914 | sub which { |
| 915 | my ($bin) = @_; |
| 916 | |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 917 | foreach my $path (split(/:/, $ENV{PATH})) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 918 | if (-e "$path/$bin") { |
| 919 | return "$path/$bin"; |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | return ""; |
| 924 | } |
| 925 | |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 926 | sub mailmap { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 927 | my (@lines) = @_; |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 928 | my %hash; |
| 929 | |
| 930 | foreach my $line (@lines) { |
| 931 | my ($name, $address) = parse_email($line); |
| 932 | if (!exists($hash{$name})) { |
| 933 | $hash{$name} = $address; |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 934 | } elsif ($address ne $hash{$name}) { |
| 935 | $address = $hash{$name}; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 936 | $line = format_email($name, $address, $email_usename); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 937 | } |
| 938 | if (exists($mailmap{$name})) { |
| 939 | my $obj = $mailmap{$name}; |
| 940 | foreach my $map_address (@$obj) { |
| 941 | if (($map_address eq $address) && |
| 942 | ($map_address ne $hash{$name})) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 943 | $line = format_email($name, $hash{$name}, $email_usename); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 944 | } |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | return @lines; |
| 950 | } |
| 951 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 952 | sub git_execute_cmd { |
| 953 | my ($cmd) = @_; |
| 954 | my @lines = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 955 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 956 | my $output = `$cmd`; |
| 957 | $output =~ s/^\s*//gm; |
| 958 | @lines = split("\n", $output); |
| 959 | |
| 960 | return @lines; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 961 | } |
| 962 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 963 | sub hg_execute_cmd { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 964 | my ($cmd) = @_; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 965 | my @lines = (); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 966 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 967 | my $output = `$cmd`; |
| 968 | @lines = split("\n", $output); |
| 969 | |
| 970 | return @lines; |
| 971 | } |
| 972 | |
| 973 | sub vcs_find_signers { |
| 974 | my ($cmd) = @_; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 975 | my @lines = (); |
| 976 | my $commits; |
| 977 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 978 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 979 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 980 | my $pattern = $VCS_cmds{"commit_pattern"}; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 981 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 982 | $commits = grep(/$pattern/, @lines); # of commits |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 983 | |
Joe Perches | e4d26b0 | 2010-05-24 14:33:17 -0700 | [diff] [blame^] | 984 | @lines = grep(/^[ \t]*${signaturePattern}.*\@.*$/, @lines); |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 985 | if (!$email_git_penguin_chiefs) { |
| 986 | @lines = grep(!/${penguin_chiefs}/i, @lines); |
| 987 | } |
| 988 | # cut -f2- -d":" |
| 989 | s/.*:\s*(.+)\s*/$1/ for (@lines); |
| 990 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 991 | ## Reformat email addresses (with names) to avoid badly written signatures |
| 992 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 993 | foreach my $line (@lines) { |
| 994 | my ($name, $address) = parse_email($line); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 995 | $line = format_email($name, $address, 1); |
| 996 | } |
| 997 | |
| 998 | return ($commits, @lines); |
| 999 | } |
| 1000 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1001 | sub vcs_save_commits { |
| 1002 | my ($cmd) = @_; |
| 1003 | my @lines = (); |
| 1004 | my @commits = (); |
| 1005 | |
| 1006 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); |
| 1007 | |
| 1008 | foreach my $line (@lines) { |
| 1009 | if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) { |
| 1010 | push(@commits, $1); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | return @commits; |
| 1015 | } |
| 1016 | |
| 1017 | sub vcs_blame { |
| 1018 | my ($file) = @_; |
| 1019 | my $cmd; |
| 1020 | my @commits = (); |
| 1021 | |
| 1022 | return @commits if (!(-f $file)); |
| 1023 | |
| 1024 | if (@range && $VCS_cmds{"blame_range_cmd"} eq "") { |
| 1025 | my @all_commits = (); |
| 1026 | |
| 1027 | $cmd = $VCS_cmds{"blame_file_cmd"}; |
| 1028 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1029 | @all_commits = vcs_save_commits($cmd); |
| 1030 | |
| 1031 | foreach my $file_range_diff (@range) { |
| 1032 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
| 1033 | my $diff_file = $1; |
| 1034 | my $diff_start = $2; |
| 1035 | my $diff_length = $3; |
| 1036 | next if ("$file" ne "$diff_file"); |
| 1037 | for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) { |
| 1038 | push(@commits, $all_commits[$i]); |
| 1039 | } |
| 1040 | } |
| 1041 | } elsif (@range) { |
| 1042 | foreach my $file_range_diff (@range) { |
| 1043 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
| 1044 | my $diff_file = $1; |
| 1045 | my $diff_start = $2; |
| 1046 | my $diff_length = $3; |
| 1047 | next if ("$file" ne "$diff_file"); |
| 1048 | $cmd = $VCS_cmds{"blame_range_cmd"}; |
| 1049 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1050 | push(@commits, vcs_save_commits($cmd)); |
| 1051 | } |
| 1052 | } else { |
| 1053 | $cmd = $VCS_cmds{"blame_file_cmd"}; |
| 1054 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1055 | @commits = vcs_save_commits($cmd); |
| 1056 | } |
| 1057 | |
| 1058 | return @commits; |
| 1059 | } |
| 1060 | |
| 1061 | my $printed_novcs = 0; |
| 1062 | sub vcs_exists { |
| 1063 | %VCS_cmds = %VCS_cmds_git; |
| 1064 | return 1 if eval $VCS_cmds{"available"}; |
| 1065 | %VCS_cmds = %VCS_cmds_hg; |
| 1066 | return 1 if eval $VCS_cmds{"available"}; |
| 1067 | %VCS_cmds = (); |
| 1068 | if (!$printed_novcs) { |
| 1069 | warn("$P: No supported VCS found. Add --nogit to options?\n"); |
| 1070 | warn("Using a git repository produces better results.\n"); |
| 1071 | warn("Try Linus Torvalds' latest git repository using:\n"); |
| 1072 | warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"); |
| 1073 | $printed_novcs = 1; |
| 1074 | } |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | sub vcs_assign { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1079 | my ($role, $divisor, @lines) = @_; |
| 1080 | |
| 1081 | my %hash; |
| 1082 | my $count = 0; |
| 1083 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1084 | return if (@lines <= 0); |
| 1085 | |
| 1086 | if ($divisor <= 0) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1087 | warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n"); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1088 | $divisor = 1; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1089 | } |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 1090 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 1091 | if ($email_remove_duplicates) { |
| 1092 | @lines = mailmap(@lines); |
| 1093 | } |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 1094 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 1095 | @lines = sort(@lines); |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 1096 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 1097 | # uniq -c |
| 1098 | $hash{$_}++ for @lines; |
| 1099 | |
| 1100 | # sort -rn |
| 1101 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
| 1102 | my $sign_offs = $hash{$line}; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1103 | my $percent = $sign_offs * 100 / $divisor; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1104 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1105 | $percent = 100 if ($percent > 100); |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 1106 | $count++; |
| 1107 | last if ($sign_offs < $email_git_min_signatures || |
| 1108 | $count > $email_git_max_maintainers || |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1109 | $percent < $email_git_min_percent); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1110 | push_email_address($line, ''); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1111 | if ($output_rolestats) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1112 | my $fmt_percent = sprintf("%.0f", $percent); |
| 1113 | add_role($line, "$role:$sign_offs/$divisor=$fmt_percent%"); |
| 1114 | } else { |
| 1115 | add_role($line, $role); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1116 | } |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1120 | sub vcs_file_signoffs { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1121 | my ($file) = @_; |
| 1122 | |
| 1123 | my @signers = (); |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1124 | my $commits; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1125 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1126 | return if (!vcs_exists()); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1127 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1128 | my $cmd = $VCS_cmds{"find_signers_cmd"}; |
| 1129 | $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd |
| 1130 | |
| 1131 | ($commits, @signers) = vcs_find_signers($cmd); |
| 1132 | vcs_assign("commit_signer", $commits, @signers); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1133 | } |
| 1134 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1135 | sub vcs_file_blame { |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1136 | my ($file) = @_; |
| 1137 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1138 | my @signers = (); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1139 | my @commits = (); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1140 | my $total_commits; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1141 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1142 | return if (!vcs_exists()); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1143 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1144 | @commits = vcs_blame($file); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1145 | @commits = uniq(@commits); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1146 | $total_commits = @commits; |
| 1147 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1148 | foreach my $commit (@commits) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1149 | my $commit_count; |
| 1150 | my @commit_signers = (); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1151 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1152 | my $cmd = $VCS_cmds{"find_commit_signers_cmd"}; |
| 1153 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1154 | |
| 1155 | ($commit_count, @commit_signers) = vcs_find_signers($cmd); |
| 1156 | push(@signers, @commit_signers); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1159 | if ($from_filename) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1160 | vcs_assign("commits", $total_commits, @signers); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1161 | } else { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1162 | vcs_assign("modified commits", $total_commits, @signers); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1163 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1164 | } |
| 1165 | |
| 1166 | sub uniq { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1167 | my (@parms) = @_; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1168 | |
| 1169 | my %saw; |
| 1170 | @parms = grep(!$saw{$_}++, @parms); |
| 1171 | return @parms; |
| 1172 | } |
| 1173 | |
| 1174 | sub sort_and_uniq { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1175 | my (@parms) = @_; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1176 | |
| 1177 | my %saw; |
| 1178 | @parms = sort @parms; |
| 1179 | @parms = grep(!$saw{$_}++, @parms); |
| 1180 | return @parms; |
| 1181 | } |
| 1182 | |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 1183 | sub clean_file_emails { |
| 1184 | my (@file_emails) = @_; |
| 1185 | my @fmt_emails = (); |
| 1186 | |
| 1187 | foreach my $email (@file_emails) { |
| 1188 | $email =~ s/[\(\<\{]{0,1}([A-Za-z0-9_\.\+-]+\@[A-Za-z0-9\.-]+)[\)\>\}]{0,1}/\<$1\>/g; |
| 1189 | my ($name, $address) = parse_email($email); |
| 1190 | if ($name eq '"[,\.]"') { |
| 1191 | $name = ""; |
| 1192 | } |
| 1193 | |
| 1194 | my @nw = split(/[^A-Za-zÀ-ÿ\'\,\.\+-]/, $name); |
| 1195 | if (@nw > 2) { |
| 1196 | my $first = $nw[@nw - 3]; |
| 1197 | my $middle = $nw[@nw - 2]; |
| 1198 | my $last = $nw[@nw - 1]; |
| 1199 | |
| 1200 | if (((length($first) == 1 && $first =~ m/[A-Za-z]/) || |
| 1201 | (length($first) == 2 && substr($first, -1) eq ".")) || |
| 1202 | (length($middle) == 1 || |
| 1203 | (length($middle) == 2 && substr($middle, -1) eq "."))) { |
| 1204 | $name = "$first $middle $last"; |
| 1205 | } else { |
| 1206 | $name = "$middle $last"; |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | if (substr($name, -1) =~ /[,\.]/) { |
| 1211 | $name = substr($name, 0, length($name) - 1); |
| 1212 | } elsif (substr($name, -2) =~ /[,\.]"/) { |
| 1213 | $name = substr($name, 0, length($name) - 2) . '"'; |
| 1214 | } |
| 1215 | |
| 1216 | if (substr($name, 0, 1) =~ /[,\.]/) { |
| 1217 | $name = substr($name, 1, length($name) - 1); |
| 1218 | } elsif (substr($name, 0, 2) =~ /"[,\.]/) { |
| 1219 | $name = '"' . substr($name, 2, length($name) - 2); |
| 1220 | } |
| 1221 | |
| 1222 | my $fmt_email = format_email($name, $address, $email_usename); |
| 1223 | push(@fmt_emails, $fmt_email); |
| 1224 | } |
| 1225 | return @fmt_emails; |
| 1226 | } |
| 1227 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1228 | sub merge_email { |
| 1229 | my @lines; |
| 1230 | my %saw; |
| 1231 | |
| 1232 | for (@_) { |
| 1233 | my ($address, $role) = @$_; |
| 1234 | if (!$saw{$address}) { |
| 1235 | if ($output_roles) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1236 | push(@lines, "$address ($role)"); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1237 | } else { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1238 | push(@lines, $address); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1239 | } |
| 1240 | $saw{$address} = 1; |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | return @lines; |
| 1245 | } |
| 1246 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1247 | sub output { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1248 | my (@parms) = @_; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1249 | |
| 1250 | if ($output_multiline) { |
| 1251 | foreach my $line (@parms) { |
| 1252 | print("${line}\n"); |
| 1253 | } |
| 1254 | } else { |
| 1255 | print(join($output_separator, @parms)); |
| 1256 | print("\n"); |
| 1257 | } |
| 1258 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1259 | |
| 1260 | my $rfc822re; |
| 1261 | |
| 1262 | sub make_rfc822re { |
| 1263 | # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and |
| 1264 | # comment. We must allow for rfc822_lwsp (or comments) after each of these. |
| 1265 | # This regexp will only work on addresses which have had comments stripped |
| 1266 | # and replaced with rfc822_lwsp. |
| 1267 | |
| 1268 | my $specials = '()<>@,;:\\\\".\\[\\]'; |
| 1269 | my $controls = '\\000-\\037\\177'; |
| 1270 | |
| 1271 | my $dtext = "[^\\[\\]\\r\\\\]"; |
| 1272 | my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*"; |
| 1273 | |
| 1274 | my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*"; |
| 1275 | |
| 1276 | # Use zero-width assertion to spot the limit of an atom. A simple |
| 1277 | # $rfc822_lwsp* causes the regexp engine to hang occasionally. |
| 1278 | my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))"; |
| 1279 | my $word = "(?:$atom|$quoted_string)"; |
| 1280 | my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*"; |
| 1281 | |
| 1282 | my $sub_domain = "(?:$atom|$domain_literal)"; |
| 1283 | my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*"; |
| 1284 | |
| 1285 | my $addr_spec = "$localpart\@$rfc822_lwsp*$domain"; |
| 1286 | |
| 1287 | my $phrase = "$word*"; |
| 1288 | my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)"; |
| 1289 | my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*"; |
| 1290 | my $mailbox = "(?:$addr_spec|$phrase$route_addr)"; |
| 1291 | |
| 1292 | my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*"; |
| 1293 | my $address = "(?:$mailbox|$group)"; |
| 1294 | |
| 1295 | return "$rfc822_lwsp*$address"; |
| 1296 | } |
| 1297 | |
| 1298 | sub rfc822_strip_comments { |
| 1299 | my $s = shift; |
| 1300 | # Recursively remove comments, and replace with a single space. The simpler |
| 1301 | # regexps in the Email Addressing FAQ are imperfect - they will miss escaped |
| 1302 | # chars in atoms, for example. |
| 1303 | |
| 1304 | while ($s =~ s/^((?:[^"\\]|\\.)* |
| 1305 | (?:"(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*)*) |
| 1306 | \((?:[^()\\]|\\.)*\)/$1 /osx) {} |
| 1307 | return $s; |
| 1308 | } |
| 1309 | |
| 1310 | # valid: returns true if the parameter is an RFC822 valid address |
| 1311 | # |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 1312 | sub rfc822_valid { |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1313 | my $s = rfc822_strip_comments(shift); |
| 1314 | |
| 1315 | if (!$rfc822re) { |
| 1316 | $rfc822re = make_rfc822re(); |
| 1317 | } |
| 1318 | |
| 1319 | return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/; |
| 1320 | } |
| 1321 | |
| 1322 | # validlist: In scalar context, returns true if the parameter is an RFC822 |
| 1323 | # valid list of addresses. |
| 1324 | # |
| 1325 | # In list context, returns an empty list on failure (an invalid |
| 1326 | # address was found); otherwise a list whose first element is the |
| 1327 | # number of addresses found and whose remaining elements are the |
| 1328 | # addresses. This is needed to disambiguate failure (invalid) |
| 1329 | # from success with no addresses found, because an empty string is |
| 1330 | # a valid list. |
| 1331 | |
Stephen Hemminger | 22dd5b0 | 2010-03-05 13:43:06 -0800 | [diff] [blame] | 1332 | sub rfc822_validlist { |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1333 | my $s = rfc822_strip_comments(shift); |
| 1334 | |
| 1335 | if (!$rfc822re) { |
| 1336 | $rfc822re = make_rfc822re(); |
| 1337 | } |
| 1338 | # * null list items are valid according to the RFC |
| 1339 | # * the '1' business is to aid in distinguishing failure from no results |
| 1340 | |
| 1341 | my @r; |
| 1342 | if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so && |
| 1343 | $s =~ m/^$rfc822_char*$/) { |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 1344 | while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1345 | push(@r, $1); |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1346 | } |
| 1347 | return wantarray ? (scalar(@r), @r) : 1; |
| 1348 | } |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1349 | return wantarray ? () : 0; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1350 | } |