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