Commit 4a7fdb5f51a4d9228b0ff93494b95f72be5e904a

Authored by Joe Perches
1 parent 69aefcead5

scripts/get_maintainer.pl - Allow multiple files on command line

Improve handling of "by:" signoffs
Sorting and frequency checks are done by name/email, not
by "by:" tag.

Signed-off-by: Joe Perches <joe@perches.com>

Showing 1 changed file with 41 additions and 44 deletions Side-by-side Diff

scripts/get_maintainer.pl
... ... @@ -13,7 +13,7 @@
13 13 use strict;
14 14  
15 15 my $P = $0;
16   -my $V = '0.14';
  16 +my $V = '0.15';
17 17  
18 18 use Getopt::Long qw(:config no_auto_abbrev);
19 19  
... ... @@ -34,7 +34,7 @@
34 34 my $web = 0;
35 35 my $subsystem = 0;
36 36 my $status = 0;
37   -my $onefile = 0;
  37 +my $from_filename = 0;
38 38 my $version = 0;
39 39 my $help = 0;
40 40  
... ... @@ -72,7 +72,7 @@
72 72 'status!' => \$status,
73 73 'scm!' => \$scm,
74 74 'web!' => \$web,
75   - 'f|file' => \$onefile,
  75 + 'f|file' => \$from_filename,
76 76 'v|version' => \$version,
77 77 'h|help' => \$help,
78 78 )) {
... ... @@ -90,8 +90,6 @@
90 90 exit 0;
91 91 }
92 92  
93   -my $infile = $ARGV[0];
94   -
95 93 if ($#ARGV < 0) {
96 94 usage();
97 95 die "$P: argument missing: patchfile or -f file please\n";
98 96  
99 97  
100 98  
101 99  
... ... @@ -139,32 +137,35 @@
139 137 }
140 138 close(MAINT);
141 139  
142   -## use the filename on the command line or find the filenames in the patchfile
  140 +## use the filenames on the command line or find the filenames in the patchfiles
143 141  
144 142 my @files = ();
145 143  
146   -if ($onefile) {
147   - if (!(-f $infile)) {
148   - die "$P: file '${infile}' not found\n";
  144 +foreach my $file (@ARGV) {
  145 + next if ((-d $file));
  146 + if (!(-f $file)) {
  147 + die "$P: file '${file}' not found\n";
149 148 }
150   - push(@files, $infile);
151   -} else {
152   - open(PATCH, "<$infile") or die "$P: Can't open ${infile}\n";
153   - while (<PATCH>) {
154   - if (m/^\+\+\+\s+(\S+)/) {
155   - my $file = $1;
156   - $file =~ s@^[^/]*/@@;
157   - $file =~ s@\n@@;
158   - push(@files, $file);
  149 + if ($from_filename) {
  150 + push(@files, $file);
  151 + } else {
  152 + my $file_cnt = @files;
  153 + open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
  154 + while (<PATCH>) {
  155 + if (m/^\+\+\+\s+(\S+)/) {
  156 + my $filename = $1;
  157 + $filename =~ s@^[^/]*/@@;
  158 + $filename =~ s@\n@@;
  159 + push(@files, $filename);
  160 + }
159 161 }
  162 + close(PATCH);
  163 + if ($file_cnt == @files) {
  164 + die "$P: file '${file}' doesn't appear to be a patch. "
  165 + . "Add -f to options?\n";
  166 + }
  167 + @files = sort_and_uniq(@files);
160 168 }
161   - close(PATCH);
162   - my $file_cnt = @files;
163   - if ($file_cnt == 0) {
164   - print STDERR "$P: file '${infile}' doesn't appear to be a patch. "
165   - . "Add -f to options?\n";
166   - }
167   - @files = sort_and_uniq(@files);
168 169 }
169 170  
170 171 my @email_to = ();
... ... @@ -208,7 +209,7 @@
208 209 }
209 210 }
210 211  
211   - if ($email_git) {
  212 + if ($email && $email_git) {
212 213 recent_git_signoffs($file);
213 214 }
214 215  
215 216  
216 217  
217 218  
... ... @@ -240,30 +241,22 @@
240 241 }
241 242  
242 243 if ($scm) {
243   - if (!$onefile) {
244   - @scm = sort_and_uniq(@scm);
245   - }
  244 + @scm = sort_and_uniq(@scm);
246 245 output(@scm);
247 246 }
248 247  
249 248 if ($status) {
250   - if (!$onefile) {
251   - @status = sort_and_uniq(@status);
252   - }
  249 + @status = sort_and_uniq(@status);
253 250 output(@status);
254 251 }
255 252  
256 253 if ($subsystem) {
257   - if (!$onefile) {
258   - @subsystem = sort_and_uniq(@subsystem);
259   - }
  254 + @subsystem = sort_and_uniq(@subsystem);
260 255 output(@subsystem);
261 256 }
262 257  
263 258 if ($web) {
264   - if (!$onefile) {
265   - @web = sort_and_uniq(@web);
266   - }
  259 + @web = sort_and_uniq(@web);
267 260 output(@web);
268 261 }
269 262  
270 263  
271 264  
... ... @@ -445,10 +438,12 @@
445 438 }
446 439  
447 440 $cmd = "git log --since=${email_git_since} -- ${file}";
448   - $cmd .= " | grep -P '^ [-A-Za-z]+by:.*\\\@'";
  441 + $cmd .= " | grep -Pi \"^[-_ a-z]+by:.*\\\@\"";
449 442 if (!$email_git_penguin_chiefs) {
450   - $cmd .= " | grep -E -v \"${penguin_chiefs}\"";
  443 + $cmd .= " | grep -Pv \"${penguin_chiefs}\"";
451 444 }
  445 + $cmd .= " | cut -f2- -d\":\"";
  446 + $cmd .= " | sed -e \"s/^\\s+//g\"";
452 447 $cmd .= " | sort | uniq -c | sort -rn";
453 448  
454 449 $output = `${cmd}`;
455 450  
... ... @@ -456,9 +451,9 @@
456 451  
457 452 @lines = split("\n", $output);
458 453 foreach my $line (@lines) {
459   - if ($line =~ m/([0-9]+)\s+([-A-Za-z]+by:)\s+(.*)/) {
  454 + if ($line =~ m/([0-9]+)\s+(.*)/) {
460 455 my $sign_offs = $1;
461   - $line = $3;
  456 + $line = $2;
462 457 $count++;
463 458 if ($sign_offs < $email_git_min_signatures ||
464 459 $count > $email_git_max_maintainers) {
465 460  
466 461  
467 462  
... ... @@ -467,17 +462,19 @@
467 462 } else {
468 463 die("$P: Unexpected git output: ${line}\n");
469 464 }
470   - if ($line =~ m/(.*) <(.*)>/) {
  465 + if ($line =~ m/(.+)<(.+)>/) {
471 466 my $git_name = $1;
472 467 my $git_addr = $2;
473 468 $git_name =~ tr/^\"//;
  469 + $git_name =~ tr/^\\s*//;
474 470 $git_name =~ tr/\"$//;
  471 + $git_name =~ tr/\\s*$//;
475 472 if ($email_usename) {
476 473 push(@email_to, format_email($git_name, $git_addr));
477 474 } else {
478 475 push(@email_to, $git_addr);
479 476 }
480   - } elsif ($line =~ m/<(.*)>/) {
  477 + } elsif ($line =~ m/<(.+)>/) {
481 478 my $git_addr = $1;
482 479 push(@email_to, $git_addr);
483 480 } else {