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