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 | # |
| 8 | # usage: perl scripts/get_maintainers.pl [OPTIONS] <patch> |
| 9 | # perl scripts/get_maintainers.pl [OPTIONS] -f <file> |
| 10 | # |
| 11 | # Licensed under the terms of the GNU GPL License version 2 |
| 12 | |
| 13 | use strict; |
| 14 | |
| 15 | my $P = $0; |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame^] | 16 | my $V = '0.19'; |
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; |
| 26 | my $email_git = 1; |
| 27 | my $email_git_penguin_chiefs = 0; |
| 28 | my $email_git_min_signatures = 1; |
| 29 | my $email_git_max_maintainers = 5; |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 30 | my $email_git_min_percent = 5; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 31 | my $email_git_since = "1-year-ago"; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 32 | my $email_git_blame = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 33 | my $output_multiline = 1; |
| 34 | my $output_separator = ", "; |
| 35 | my $scm = 0; |
| 36 | my $web = 0; |
| 37 | my $subsystem = 0; |
| 38 | my $status = 0; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 39 | my $from_filename = 0; |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame^] | 40 | my $pattern_depth = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 41 | my $version = 0; |
| 42 | my $help = 0; |
| 43 | |
| 44 | my $exit = 0; |
| 45 | |
| 46 | my @penguin_chief = (); |
| 47 | push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org"); |
| 48 | #Andrew wants in on most everything - 2009/01/14 |
| 49 | #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org"); |
| 50 | |
| 51 | my @penguin_chief_names = (); |
| 52 | foreach my $chief (@penguin_chief) { |
| 53 | if ($chief =~ m/^(.*):(.*)/) { |
| 54 | my $chief_name = $1; |
| 55 | my $chief_addr = $2; |
| 56 | push(@penguin_chief_names, $chief_name); |
| 57 | } |
| 58 | } |
| 59 | my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)"; |
| 60 | |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 61 | # rfc822 email address - preloaded methods go here. |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 62 | my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; |
Joe Perches | df4cc03 | 2009-06-16 15:34:04 -0700 | [diff] [blame] | 63 | my $rfc822_char = '[\\000-\\377]'; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 64 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 65 | if (!GetOptions( |
| 66 | 'email!' => \$email, |
| 67 | 'git!' => \$email_git, |
| 68 | 'git-chief-penguins!' => \$email_git_penguin_chiefs, |
| 69 | 'git-min-signatures=i' => \$email_git_min_signatures, |
| 70 | 'git-max-maintainers=i' => \$email_git_max_maintainers, |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 71 | 'git-min-percent=i' => \$email_git_min_percent, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 72 | 'git-since=s' => \$email_git_since, |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 73 | 'git-blame!' => \$email_git_blame, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 74 | 'm!' => \$email_maintainer, |
| 75 | 'n!' => \$email_usename, |
| 76 | 'l!' => \$email_list, |
| 77 | 's!' => \$email_subscriber_list, |
| 78 | 'multiline!' => \$output_multiline, |
| 79 | 'separator=s' => \$output_separator, |
| 80 | 'subsystem!' => \$subsystem, |
| 81 | 'status!' => \$status, |
| 82 | 'scm!' => \$scm, |
| 83 | 'web!' => \$web, |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame^] | 84 | 'pattern-depth=i' => \$pattern_depth, |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 85 | 'f|file' => \$from_filename, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 86 | 'v|version' => \$version, |
| 87 | 'h|help' => \$help, |
| 88 | )) { |
| 89 | usage(); |
| 90 | die "$P: invalid argument\n"; |
| 91 | } |
| 92 | |
| 93 | if ($help != 0) { |
| 94 | usage(); |
| 95 | exit 0; |
| 96 | } |
| 97 | |
| 98 | if ($version != 0) { |
| 99 | print("${P} ${V}\n"); |
| 100 | exit 0; |
| 101 | } |
| 102 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 103 | if ($#ARGV < 0) { |
| 104 | usage(); |
| 105 | die "$P: argument missing: patchfile or -f file please\n"; |
| 106 | } |
| 107 | |
| 108 | my $selections = $email + $scm + $status + $subsystem + $web; |
| 109 | if ($selections == 0) { |
| 110 | usage(); |
| 111 | die "$P: Missing required option: email, scm, status, subsystem or web\n"; |
| 112 | } |
| 113 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 114 | if ($email && |
| 115 | ($email_maintainer + $email_list + $email_subscriber_list + |
| 116 | $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 117 | usage(); |
| 118 | die "$P: Please select at least 1 email option\n"; |
| 119 | } |
| 120 | |
| 121 | if (!top_of_kernel_tree($lk_path)) { |
| 122 | die "$P: The current directory does not appear to be " |
| 123 | . "a linux kernel source tree.\n"; |
| 124 | } |
| 125 | |
| 126 | ## Read MAINTAINERS for type/value pairs |
| 127 | |
| 128 | my @typevalue = (); |
| 129 | open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n"; |
| 130 | while (<MAINT>) { |
| 131 | my $line = $_; |
| 132 | |
| 133 | if ($line =~ m/^(\C):\s*(.*)/) { |
| 134 | my $type = $1; |
| 135 | my $value = $2; |
| 136 | |
| 137 | ##Filename pattern matching |
| 138 | if ($type eq "F" || $type eq "X") { |
| 139 | $value =~ s@\.@\\\.@g; ##Convert . to \. |
| 140 | $value =~ s/\*/\.\*/g; ##Convert * to .* |
| 141 | $value =~ s/\?/\./g; ##Convert ? to . |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 142 | ##if pattern is a directory and it lacks a trailing slash, add one |
| 143 | if ((-d $value)) { |
| 144 | $value =~ s@([^/])$@$1/@; |
| 145 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 146 | } |
| 147 | push(@typevalue, "$type:$value"); |
| 148 | } elsif (!/^(\s)*$/) { |
| 149 | $line =~ s/\n$//g; |
| 150 | push(@typevalue, $line); |
| 151 | } |
| 152 | } |
| 153 | close(MAINT); |
| 154 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 155 | ## 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] | 156 | |
| 157 | my @files = (); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 158 | my @range = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 159 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 160 | foreach my $file (@ARGV) { |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 161 | ##if $file is a directory and it lacks a trailing slash, add one |
| 162 | if ((-d $file)) { |
| 163 | $file =~ s@([^/])$@$1/@; |
| 164 | } elsif (!(-f $file)) { |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 165 | die "$P: file '${file}' not found\n"; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 166 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 167 | if ($from_filename) { |
| 168 | push(@files, $file); |
| 169 | } else { |
| 170 | my $file_cnt = @files; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 171 | my $lastfile; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 172 | open(PATCH, "<$file") or die "$P: Can't open ${file}\n"; |
| 173 | while (<PATCH>) { |
| 174 | if (m/^\+\+\+\s+(\S+)/) { |
| 175 | my $filename = $1; |
| 176 | $filename =~ s@^[^/]*/@@; |
| 177 | $filename =~ s@\n@@; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 178 | $lastfile = $filename; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 179 | push(@files, $filename); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 180 | } elsif (m/^\@\@ -(\d+),(\d+)/) { |
| 181 | if ($email_git_blame) { |
| 182 | push(@range, "$lastfile:$1:$2"); |
| 183 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 184 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 185 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 186 | close(PATCH); |
| 187 | if ($file_cnt == @files) { |
Joe Perches | 7f29fd27 | 2009-06-16 15:34:04 -0700 | [diff] [blame] | 188 | warn "$P: file '${file}' doesn't appear to be a patch. " |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 189 | . "Add -f to options?\n"; |
| 190 | } |
| 191 | @files = sort_and_uniq(@files); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 192 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | my @email_to = (); |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 196 | my @list_to = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 197 | my @scm = (); |
| 198 | my @web = (); |
| 199 | my @subsystem = (); |
| 200 | my @status = (); |
| 201 | |
| 202 | # Find responsible parties |
| 203 | |
| 204 | foreach my $file (@files) { |
| 205 | |
| 206 | #Do not match excluded file patterns |
| 207 | |
| 208 | my $exclude = 0; |
| 209 | foreach my $line (@typevalue) { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 210 | if ($line =~ m/^(\C):\s*(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 211 | my $type = $1; |
| 212 | my $value = $2; |
| 213 | if ($type eq 'X') { |
| 214 | if (file_match_pattern($file, $value)) { |
| 215 | $exclude = 1; |
Joe Perches | 1d606b4 | 2009-09-21 17:04:14 -0700 | [diff] [blame] | 216 | last; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | if (!$exclude) { |
| 223 | my $tvi = 0; |
Joe Perches | 1d606b4 | 2009-09-21 17:04:14 -0700 | [diff] [blame] | 224 | my %hash; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 225 | foreach my $line (@typevalue) { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 226 | if ($line =~ m/^(\C):\s*(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 227 | my $type = $1; |
| 228 | my $value = $2; |
| 229 | if ($type eq 'F') { |
| 230 | if (file_match_pattern($file, $value)) { |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame^] | 231 | my $value_pd = ($value =~ tr@/@@); |
| 232 | my $file_pd = ($file =~ tr@/@@); |
| 233 | $value_pd++ if (substr($value,-1,1) ne "/"); |
| 234 | if ($pattern_depth == 0 || |
| 235 | (($file_pd - $value_pd) < $pattern_depth)) { |
| 236 | $hash{$tvi} = $value_pd; |
| 237 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | } |
| 241 | $tvi++; |
| 242 | } |
Joe Perches | 1d606b4 | 2009-09-21 17:04:14 -0700 | [diff] [blame] | 243 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
| 244 | add_categories($line); |
| 245 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 248 | if ($email && $email_git) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 249 | recent_git_signoffs($file); |
| 250 | } |
| 251 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 252 | if ($email && $email_git_blame) { |
| 253 | git_assign_blame($file); |
| 254 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 257 | if ($email) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 258 | foreach my $chief (@penguin_chief) { |
| 259 | if ($chief =~ m/^(.*):(.*)/) { |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 260 | my $email_address; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 261 | if ($email_usename) { |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 262 | $email_address = format_email($1, $2); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 263 | } else { |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 264 | $email_address = $2; |
| 265 | } |
| 266 | if ($email_git_penguin_chiefs) { |
| 267 | push(@email_to, $email_address); |
| 268 | } else { |
| 269 | @email_to = grep(!/${email_address}/, @email_to); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 275 | if ($email || $email_list) { |
| 276 | my @to = (); |
| 277 | if ($email) { |
| 278 | @to = (@to, @email_to); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 279 | } |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 280 | if ($email_list) { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 281 | @to = (@to, @list_to); |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 282 | } |
| 283 | output(uniq(@to)); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | if ($scm) { |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 287 | @scm = sort_and_uniq(@scm); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 288 | output(@scm); |
| 289 | } |
| 290 | |
| 291 | if ($status) { |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 292 | @status = sort_and_uniq(@status); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 293 | output(@status); |
| 294 | } |
| 295 | |
| 296 | if ($subsystem) { |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 297 | @subsystem = sort_and_uniq(@subsystem); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 298 | output(@subsystem); |
| 299 | } |
| 300 | |
| 301 | if ($web) { |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 302 | @web = sort_and_uniq(@web); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 303 | output(@web); |
| 304 | } |
| 305 | |
| 306 | exit($exit); |
| 307 | |
| 308 | sub file_match_pattern { |
| 309 | my ($file, $pattern) = @_; |
| 310 | if (substr($pattern, -1) eq "/") { |
| 311 | if ($file =~ m@^$pattern@) { |
| 312 | return 1; |
| 313 | } |
| 314 | } else { |
| 315 | if ($file =~ m@^$pattern@) { |
| 316 | my $s1 = ($file =~ tr@/@@); |
| 317 | my $s2 = ($pattern =~ tr@/@@); |
| 318 | if ($s1 == $s2) { |
| 319 | return 1; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | sub usage { |
| 327 | print <<EOT; |
| 328 | usage: $P [options] patchfile |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 329 | $P [options] -f file|directory |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 330 | version: $V |
| 331 | |
| 332 | MAINTAINER field selection options: |
| 333 | --email => print email address(es) if any |
| 334 | --git => include recent git \*-by: signers |
| 335 | --git-chief-penguins => include ${penguin_chiefs} |
| 336 | --git-min-signatures => number of signatures required (default: 1) |
| 337 | --git-max-maintainers => maximum maintainers to add (default: 5) |
Joe Perches | 3d202ae | 2009-07-29 15:04:29 -0700 | [diff] [blame] | 338 | --git-min-percent => minimum percentage of commits required (default: 5) |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 339 | --git-since => git history to use (default: 1-year-ago) |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 340 | --git-blame => use git blame to find modified commits for patch or file |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 341 | --m => include maintainer(s) if any |
| 342 | --n => include name 'Full Name <addr\@domain.tld>' |
| 343 | --l => include list(s) if any |
| 344 | --s => include subscriber only list(s) if any |
| 345 | --scm => print SCM tree(s) if any |
| 346 | --status => print status if any |
| 347 | --subsystem => print subsystem name if any |
| 348 | --web => print website(s) if any |
| 349 | |
| 350 | Output type options: |
| 351 | --separator [, ] => separator for multiple entries on 1 line |
| 352 | --multiline => print 1 entry per line |
| 353 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 354 | Other options: |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame^] | 355 | --pattern-depth => Number of pattern directory traversals (default: 0 (all)) |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 356 | --version => show version |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 357 | --help => show this help information |
| 358 | |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame^] | 359 | Default options: |
| 360 | [--email --git --m --n --l --multiline --pattern-depth=0] |
| 361 | |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 362 | Notes: |
| 363 | Using "-f directory" may give unexpected results: |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 364 | Used with "--git", git signators for _all_ files in and below |
| 365 | directory are examined as git recurses directories. |
| 366 | Any specified X: (exclude) pattern matches are _not_ ignored. |
| 367 | Used with "--nogit", directory is used as a pattern match, |
| 368 | no individual file within the directory or subdirectory |
| 369 | is matched. |
| 370 | Used with "--git-blame", does not iterate all files in directory |
| 371 | Using "--git-blame" is slow and may add old committers and authors |
| 372 | that are no longer active maintainers to the output. |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 373 | EOT |
| 374 | } |
| 375 | |
| 376 | sub top_of_kernel_tree { |
| 377 | my ($lk_path) = @_; |
| 378 | |
| 379 | if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") { |
| 380 | $lk_path .= "/"; |
| 381 | } |
| 382 | if ( (-f "${lk_path}COPYING") |
| 383 | && (-f "${lk_path}CREDITS") |
| 384 | && (-f "${lk_path}Kbuild") |
| 385 | && (-f "${lk_path}MAINTAINERS") |
| 386 | && (-f "${lk_path}Makefile") |
| 387 | && (-f "${lk_path}README") |
| 388 | && (-d "${lk_path}Documentation") |
| 389 | && (-d "${lk_path}arch") |
| 390 | && (-d "${lk_path}include") |
| 391 | && (-d "${lk_path}drivers") |
| 392 | && (-d "${lk_path}fs") |
| 393 | && (-d "${lk_path}init") |
| 394 | && (-d "${lk_path}ipc") |
| 395 | && (-d "${lk_path}kernel") |
| 396 | && (-d "${lk_path}lib") |
| 397 | && (-d "${lk_path}scripts")) { |
| 398 | return 1; |
| 399 | } |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | sub format_email { |
| 404 | my ($name, $email) = @_; |
| 405 | |
| 406 | $name =~ s/^\s+|\s+$//g; |
Joe Perches | d789504 | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 407 | $name =~ s/^\"|\"$//g; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 408 | $email =~ s/^\s+|\s+$//g; |
| 409 | |
| 410 | my $formatted_email = ""; |
| 411 | |
| 412 | if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars |
| 413 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes |
| 414 | $formatted_email = "\"${name}\"\ \<${email}\>"; |
| 415 | } else { |
| 416 | $formatted_email = "${name} \<${email}\>"; |
| 417 | } |
| 418 | return $formatted_email; |
| 419 | } |
| 420 | |
| 421 | sub add_categories { |
| 422 | my ($index) = @_; |
| 423 | |
| 424 | $index = $index - 1; |
| 425 | while ($index >= 0) { |
| 426 | my $tv = $typevalue[$index]; |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 427 | if ($tv =~ m/^(\C):\s*(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 428 | my $ptype = $1; |
| 429 | my $pvalue = $2; |
| 430 | if ($ptype eq "L") { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 431 | my $list_address = $pvalue; |
| 432 | my $list_additional = ""; |
| 433 | if ($list_address =~ m/([^\s]+)\s+(.*)$/) { |
| 434 | $list_address = $1; |
| 435 | $list_additional = $2; |
| 436 | } |
Joe Perches | bdf7c68 | 2009-06-16 15:33:59 -0700 | [diff] [blame] | 437 | if ($list_additional =~ m/subscribers-only/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 438 | if ($email_subscriber_list) { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 439 | push(@list_to, $list_address); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 440 | } |
| 441 | } else { |
| 442 | if ($email_list) { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 443 | push(@list_to, $list_address); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | } elsif ($ptype eq "M") { |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 447 | my $p_used = 0; |
| 448 | if ($index >= 0) { |
| 449 | my $tv = $typevalue[$index - 1]; |
| 450 | if ($tv =~ m/^(\C):\s*(.*)/) { |
| 451 | if ($1 eq "P") { |
| 452 | if ($email_usename) { |
| 453 | push_email_address(format_email($2, $pvalue)); |
| 454 | $p_used = 1; |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | if (!$p_used) { |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 460 | push_email_addresses($pvalue); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 461 | } |
| 462 | } elsif ($ptype eq "T") { |
| 463 | push(@scm, $pvalue); |
| 464 | } elsif ($ptype eq "W") { |
| 465 | push(@web, $pvalue); |
| 466 | } elsif ($ptype eq "S") { |
| 467 | push(@status, $pvalue); |
| 468 | } |
| 469 | |
| 470 | $index--; |
| 471 | } else { |
| 472 | push(@subsystem,$tv); |
| 473 | $index = -1; |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 478 | sub push_email_address { |
| 479 | my ($email_address) = @_; |
| 480 | |
| 481 | my $email_name = ""; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 482 | |
Joe Perches | 0a79c49 | 2009-06-16 15:34:03 -0700 | [diff] [blame] | 483 | if ($email_maintainer) { |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 484 | if ($email_address =~ m/([^<]+)<(.*\@.*)>$/) { |
| 485 | $email_name = $1; |
| 486 | $email_address = $2; |
| 487 | if ($email_usename) { |
| 488 | push(@email_to, format_email($email_name, $email_address)); |
| 489 | } else { |
| 490 | push(@email_to, $email_address); |
| 491 | } |
| 492 | } elsif ($email_address =~ m/<(.+)>/) { |
| 493 | $email_address = $1; |
| 494 | push(@email_to, $email_address); |
Joe Perches | 0a79c49 | 2009-06-16 15:34:03 -0700 | [diff] [blame] | 495 | } else { |
| 496 | push(@email_to, $email_address); |
| 497 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | sub push_email_addresses { |
| 502 | my ($address) = @_; |
| 503 | |
| 504 | my @address_list = (); |
| 505 | |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 506 | if (rfc822_valid($address)) { |
| 507 | push_email_address($address); |
| 508 | } elsif (@address_list = rfc822_validlist($address)) { |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 509 | my $array_count = shift(@address_list); |
| 510 | while (my $entry = shift(@address_list)) { |
| 511 | push_email_address($entry); |
| 512 | } |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 513 | } else { |
| 514 | warn("Invalid MAINTAINERS address: '" . $address . "'\n"); |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 515 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 518 | sub which { |
| 519 | my ($bin) = @_; |
| 520 | |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 521 | foreach my $path (split(/:/, $ENV{PATH})) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 522 | if (-e "$path/$bin") { |
| 523 | return "$path/$bin"; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | return ""; |
| 528 | } |
| 529 | |
| 530 | sub recent_git_signoffs { |
| 531 | my ($file) = @_; |
| 532 | |
| 533 | my $sign_offs = ""; |
| 534 | my $cmd = ""; |
| 535 | my $output = ""; |
| 536 | my $count = 0; |
| 537 | my @lines = (); |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 538 | my $total_sign_offs; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 539 | |
| 540 | if (which("git") eq "") { |
Joe Perches | de2fc49 | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 541 | warn("$P: git not found. Add --nogit to options?\n"); |
| 542 | return; |
| 543 | } |
| 544 | if (!(-d ".git")) { |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 545 | warn("$P: .git directory not found. Use a git repository for better results.\n"); |
| 546 | warn("$P: perhaps 'git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git'\n"); |
Joe Perches | de2fc49 | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 547 | return; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | $cmd = "git log --since=${email_git_since} -- ${file}"; |
Joe Perches | de2fc49 | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 551 | $cmd .= " | grep -Ei \"^[-_ a-z]+by:.*\\\@.*\$\""; |
| 552 | if (!$email_git_penguin_chiefs) { |
| 553 | $cmd .= " | grep -Ev \"${penguin_chiefs}\""; |
| 554 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 555 | $cmd .= " | cut -f2- -d\":\""; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 556 | $cmd .= " | sort | uniq -c | sort -rn"; |
| 557 | |
| 558 | $output = `${cmd}`; |
| 559 | $output =~ s/^\s*//gm; |
| 560 | |
| 561 | @lines = split("\n", $output); |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 562 | |
| 563 | $total_sign_offs = 0; |
| 564 | foreach my $line (@lines) { |
| 565 | if ($line =~ m/([0-9]+)\s+(.*)/) { |
| 566 | $total_sign_offs += $1; |
| 567 | } else { |
| 568 | die("$P: Unexpected git output: ${line}\n"); |
| 569 | } |
| 570 | } |
| 571 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 572 | foreach my $line (@lines) { |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 573 | if ($line =~ m/([0-9]+)\s+(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 574 | my $sign_offs = $1; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 575 | $line = $2; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 576 | $count++; |
| 577 | if ($sign_offs < $email_git_min_signatures || |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 578 | $count > $email_git_max_maintainers || |
| 579 | $sign_offs * 100 / $total_sign_offs < $email_git_min_percent) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 580 | last; |
| 581 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 582 | } |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 583 | push_email_address($line); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | sub save_commits { |
| 588 | my ($cmd, @commits) = @_; |
| 589 | my $output; |
| 590 | my @lines = (); |
| 591 | |
| 592 | $output = `${cmd}`; |
| 593 | |
| 594 | @lines = split("\n", $output); |
| 595 | foreach my $line (@lines) { |
| 596 | if ($line =~ m/^(\w+) /) { |
| 597 | push (@commits, $1); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 598 | } |
| 599 | } |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 600 | return @commits; |
| 601 | } |
| 602 | |
| 603 | sub git_assign_blame { |
| 604 | my ($file) = @_; |
| 605 | |
| 606 | my @lines = (); |
| 607 | my @commits = (); |
| 608 | my $cmd; |
| 609 | my $output; |
| 610 | my %hash; |
| 611 | my $total_sign_offs; |
| 612 | my $count; |
| 613 | |
| 614 | if (@range) { |
| 615 | foreach my $file_range_diff (@range) { |
| 616 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
| 617 | my $diff_file = $1; |
| 618 | my $diff_start = $2; |
| 619 | my $diff_length = $3; |
| 620 | next if (!("$file" eq "$diff_file")); |
| 621 | $cmd = "git blame -l -L $diff_start,+$diff_length $file\n"; |
| 622 | @commits = save_commits($cmd, @commits); |
| 623 | } |
| 624 | } else { |
| 625 | if (-f $file) { |
| 626 | $cmd = "git blame -l $file\n"; |
| 627 | @commits = save_commits($cmd, @commits); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | $total_sign_offs = 0; |
| 632 | @commits = uniq(@commits); |
| 633 | foreach my $commit (@commits) { |
| 634 | $cmd = "git log -1 ${commit}"; |
| 635 | $cmd .= " | grep -Ei \"^[-_ a-z]+by:.*\\\@.*\$\""; |
| 636 | if (!$email_git_penguin_chiefs) { |
| 637 | $cmd .= " | grep -Ev \"${penguin_chiefs}\""; |
| 638 | } |
| 639 | $cmd .= " | cut -f2- -d\":\""; |
| 640 | |
| 641 | $output = `${cmd}`; |
| 642 | $output =~ s/^\s*//gm; |
| 643 | @lines = split("\n", $output); |
| 644 | $hash{$_}++ for @lines; |
| 645 | $total_sign_offs += @lines; |
| 646 | } |
| 647 | |
| 648 | $count = 0; |
| 649 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
| 650 | my $sign_offs = $hash{$line}; |
| 651 | $count++; |
| 652 | last if ($sign_offs < $email_git_min_signatures || |
| 653 | $count > $email_git_max_maintainers || |
| 654 | $sign_offs * 100 / $total_sign_offs < $email_git_min_percent); |
| 655 | push_email_address($line); |
| 656 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | sub uniq { |
| 660 | my @parms = @_; |
| 661 | |
| 662 | my %saw; |
| 663 | @parms = grep(!$saw{$_}++, @parms); |
| 664 | return @parms; |
| 665 | } |
| 666 | |
| 667 | sub sort_and_uniq { |
| 668 | my @parms = @_; |
| 669 | |
| 670 | my %saw; |
| 671 | @parms = sort @parms; |
| 672 | @parms = grep(!$saw{$_}++, @parms); |
| 673 | return @parms; |
| 674 | } |
| 675 | |
| 676 | sub output { |
| 677 | my @parms = @_; |
| 678 | |
| 679 | if ($output_multiline) { |
| 680 | foreach my $line (@parms) { |
| 681 | print("${line}\n"); |
| 682 | } |
| 683 | } else { |
| 684 | print(join($output_separator, @parms)); |
| 685 | print("\n"); |
| 686 | } |
| 687 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 688 | |
| 689 | my $rfc822re; |
| 690 | |
| 691 | sub make_rfc822re { |
| 692 | # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and |
| 693 | # comment. We must allow for rfc822_lwsp (or comments) after each of these. |
| 694 | # This regexp will only work on addresses which have had comments stripped |
| 695 | # and replaced with rfc822_lwsp. |
| 696 | |
| 697 | my $specials = '()<>@,;:\\\\".\\[\\]'; |
| 698 | my $controls = '\\000-\\037\\177'; |
| 699 | |
| 700 | my $dtext = "[^\\[\\]\\r\\\\]"; |
| 701 | my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*"; |
| 702 | |
| 703 | my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*"; |
| 704 | |
| 705 | # Use zero-width assertion to spot the limit of an atom. A simple |
| 706 | # $rfc822_lwsp* causes the regexp engine to hang occasionally. |
| 707 | my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))"; |
| 708 | my $word = "(?:$atom|$quoted_string)"; |
| 709 | my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*"; |
| 710 | |
| 711 | my $sub_domain = "(?:$atom|$domain_literal)"; |
| 712 | my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*"; |
| 713 | |
| 714 | my $addr_spec = "$localpart\@$rfc822_lwsp*$domain"; |
| 715 | |
| 716 | my $phrase = "$word*"; |
| 717 | my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)"; |
| 718 | my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*"; |
| 719 | my $mailbox = "(?:$addr_spec|$phrase$route_addr)"; |
| 720 | |
| 721 | my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*"; |
| 722 | my $address = "(?:$mailbox|$group)"; |
| 723 | |
| 724 | return "$rfc822_lwsp*$address"; |
| 725 | } |
| 726 | |
| 727 | sub rfc822_strip_comments { |
| 728 | my $s = shift; |
| 729 | # Recursively remove comments, and replace with a single space. The simpler |
| 730 | # regexps in the Email Addressing FAQ are imperfect - they will miss escaped |
| 731 | # chars in atoms, for example. |
| 732 | |
| 733 | while ($s =~ s/^((?:[^"\\]|\\.)* |
| 734 | (?:"(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*)*) |
| 735 | \((?:[^()\\]|\\.)*\)/$1 /osx) {} |
| 736 | return $s; |
| 737 | } |
| 738 | |
| 739 | # valid: returns true if the parameter is an RFC822 valid address |
| 740 | # |
| 741 | sub rfc822_valid ($) { |
| 742 | my $s = rfc822_strip_comments(shift); |
| 743 | |
| 744 | if (!$rfc822re) { |
| 745 | $rfc822re = make_rfc822re(); |
| 746 | } |
| 747 | |
| 748 | return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/; |
| 749 | } |
| 750 | |
| 751 | # validlist: In scalar context, returns true if the parameter is an RFC822 |
| 752 | # valid list of addresses. |
| 753 | # |
| 754 | # In list context, returns an empty list on failure (an invalid |
| 755 | # address was found); otherwise a list whose first element is the |
| 756 | # number of addresses found and whose remaining elements are the |
| 757 | # addresses. This is needed to disambiguate failure (invalid) |
| 758 | # from success with no addresses found, because an empty string is |
| 759 | # a valid list. |
| 760 | |
| 761 | sub rfc822_validlist ($) { |
| 762 | my $s = rfc822_strip_comments(shift); |
| 763 | |
| 764 | if (!$rfc822re) { |
| 765 | $rfc822re = make_rfc822re(); |
| 766 | } |
| 767 | # * null list items are valid according to the RFC |
| 768 | # * the '1' business is to aid in distinguishing failure from no results |
| 769 | |
| 770 | my @r; |
| 771 | if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so && |
| 772 | $s =~ m/^$rfc822_char*$/) { |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 773 | while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) { |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 774 | push @r, $1; |
| 775 | } |
| 776 | return wantarray ? (scalar(@r), @r) : 1; |
| 777 | } |
| 778 | else { |
| 779 | return wantarray ? () : 0; |
| 780 | } |
| 781 | } |