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