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