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