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