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 | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 16 | my $V = '0.23'; |
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; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 26 | my $email_git_penguin_chiefs = 0; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 27 | my $email_git = 1; |
| 28 | my $email_git_blame = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 29 | my $email_git_min_signatures = 1; |
| 30 | my $email_git_max_maintainers = 5; |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 31 | my $email_git_min_percent = 5; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 32 | my $email_git_since = "1-year-ago"; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 33 | my $email_hg_since = "-365"; |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 34 | my $email_remove_duplicates = 1; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 35 | my $output_multiline = 1; |
| 36 | my $output_separator = ", "; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 37 | my $output_roles = 0; |
| 38 | my $output_rolestats = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 39 | my $scm = 0; |
| 40 | my $web = 0; |
| 41 | my $subsystem = 0; |
| 42 | my $status = 0; |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 43 | my $keywords = 1; |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 44 | my $sections = 0; |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 45 | my $file_emails = 0; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 46 | my $from_filename = 0; |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 47 | my $pattern_depth = 0; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 48 | my $version = 0; |
| 49 | my $help = 0; |
| 50 | |
| 51 | my $exit = 0; |
| 52 | |
| 53 | my @penguin_chief = (); |
| 54 | push(@penguin_chief,"Linus Torvalds:torvalds\@linux-foundation.org"); |
| 55 | #Andrew wants in on most everything - 2009/01/14 |
| 56 | #push(@penguin_chief,"Andrew Morton:akpm\@linux-foundation.org"); |
| 57 | |
| 58 | my @penguin_chief_names = (); |
| 59 | foreach my $chief (@penguin_chief) { |
| 60 | if ($chief =~ m/^(.*):(.*)/) { |
| 61 | my $chief_name = $1; |
| 62 | my $chief_addr = $2; |
| 63 | push(@penguin_chief_names, $chief_name); |
| 64 | } |
| 65 | } |
| 66 | my $penguin_chiefs = "\(" . join("|",@penguin_chief_names) . "\)"; |
| 67 | |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 68 | # rfc822 email address - preloaded methods go here. |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 69 | my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; |
Joe Perches | df4cc03 | 2009-06-16 15:34:04 -0700 | [diff] [blame] | 70 | my $rfc822_char = '[\\000-\\377]'; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 71 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 72 | # VCS command support: class-like functions and strings |
| 73 | |
| 74 | my %VCS_cmds; |
| 75 | |
| 76 | my %VCS_cmds_git = ( |
| 77 | "execute_cmd" => \&git_execute_cmd, |
| 78 | "available" => '(which("git") ne "") && (-d ".git")', |
Richard Kennedy | 99cf611 | 2010-02-02 13:44:07 -0800 | [diff] [blame] | 79 | "find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file", |
| 80 | "find_commit_signers_cmd" => "git log --no-color -1 \$commit", |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 81 | "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file", |
| 82 | "blame_file_cmd" => "git blame -l \$file", |
| 83 | "commit_pattern" => "^commit [0-9a-f]{40,40}", |
| 84 | "blame_commit_pattern" => "^([0-9a-f]+) " |
| 85 | ); |
| 86 | |
| 87 | my %VCS_cmds_hg = ( |
| 88 | "execute_cmd" => \&hg_execute_cmd, |
| 89 | "available" => '(which("hg") ne "") && (-d ".hg")', |
| 90 | "find_signers_cmd" => |
| 91 | "hg log --date=\$email_hg_since" . |
| 92 | " --template='commit {node}\\n{desc}\\n' -- \$file", |
| 93 | "find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit", |
| 94 | "blame_range_cmd" => "", # not supported |
| 95 | "blame_file_cmd" => "hg blame -c \$file", |
| 96 | "commit_pattern" => "^commit [0-9a-f]{40,40}", |
| 97 | "blame_commit_pattern" => "^([0-9a-f]+):" |
| 98 | ); |
| 99 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 100 | if (!GetOptions( |
| 101 | 'email!' => \$email, |
| 102 | 'git!' => \$email_git, |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 103 | 'git-blame!' => \$email_git_blame, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 104 | 'git-chief-penguins!' => \$email_git_penguin_chiefs, |
| 105 | 'git-min-signatures=i' => \$email_git_min_signatures, |
| 106 | 'git-max-maintainers=i' => \$email_git_max_maintainers, |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 107 | 'git-min-percent=i' => \$email_git_min_percent, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 108 | 'git-since=s' => \$email_git_since, |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 109 | 'hg-since=s' => \$email_hg_since, |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 110 | 'remove-duplicates!' => \$email_remove_duplicates, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 111 | 'm!' => \$email_maintainer, |
| 112 | 'n!' => \$email_usename, |
| 113 | 'l!' => \$email_list, |
| 114 | 's!' => \$email_subscriber_list, |
| 115 | 'multiline!' => \$output_multiline, |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 116 | 'roles!' => \$output_roles, |
| 117 | 'rolestats!' => \$output_rolestats, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 118 | 'separator=s' => \$output_separator, |
| 119 | 'subsystem!' => \$subsystem, |
| 120 | 'status!' => \$status, |
| 121 | 'scm!' => \$scm, |
| 122 | 'web!' => \$web, |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 123 | 'pattern-depth=i' => \$pattern_depth, |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 124 | 'k|keywords!' => \$keywords, |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 125 | 'sections!' => \$sections, |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 126 | 'fe|file-emails!' => \$file_emails, |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 127 | 'f|file' => \$from_filename, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 128 | 'v|version' => \$version, |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame^] | 129 | 'h|help|usage' => \$help, |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 130 | )) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 131 | die "$P: invalid argument - use --help if necessary\n"; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | if ($help != 0) { |
| 135 | usage(); |
| 136 | exit 0; |
| 137 | } |
| 138 | |
| 139 | if ($version != 0) { |
| 140 | print("${P} ${V}\n"); |
| 141 | exit 0; |
| 142 | } |
| 143 | |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame^] | 144 | if (-t STDIN && !@ARGV) { |
| 145 | # We're talking to a terminal, but have no command line arguments. |
| 146 | die "$P: missing patchfile or -f file - use --help if necessary\n"; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Joe Perches | 4249831 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 149 | if ($output_separator ne ", ") { |
| 150 | $output_multiline = 0; |
| 151 | } |
| 152 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 153 | if ($output_rolestats) { |
| 154 | $output_roles = 1; |
| 155 | } |
| 156 | |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 157 | if ($sections) { |
| 158 | $email = 0; |
| 159 | $email_list = 0; |
| 160 | $scm = 0; |
| 161 | $status = 0; |
| 162 | $subsystem = 0; |
| 163 | $web = 0; |
| 164 | $keywords = 0; |
| 165 | } else { |
| 166 | my $selections = $email + $scm + $status + $subsystem + $web; |
| 167 | if ($selections == 0) { |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 168 | die "$P: Missing required option: email, scm, status, subsystem or web\n"; |
| 169 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 172 | if ($email && |
| 173 | ($email_maintainer + $email_list + $email_subscriber_list + |
| 174 | $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 175 | die "$P: Please select at least 1 email option\n"; |
| 176 | } |
| 177 | |
| 178 | if (!top_of_kernel_tree($lk_path)) { |
| 179 | die "$P: The current directory does not appear to be " |
| 180 | . "a linux kernel source tree.\n"; |
| 181 | } |
| 182 | |
| 183 | ## Read MAINTAINERS for type/value pairs |
| 184 | |
| 185 | my @typevalue = (); |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 186 | my %keyword_hash; |
| 187 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 188 | open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n"; |
| 189 | while (<MAINT>) { |
| 190 | my $line = $_; |
| 191 | |
| 192 | if ($line =~ m/^(\C):\s*(.*)/) { |
| 193 | my $type = $1; |
| 194 | my $value = $2; |
| 195 | |
| 196 | ##Filename pattern matching |
| 197 | if ($type eq "F" || $type eq "X") { |
| 198 | $value =~ s@\.@\\\.@g; ##Convert . to \. |
| 199 | $value =~ s/\*/\.\*/g; ##Convert * to .* |
| 200 | $value =~ s/\?/\./g; ##Convert ? to . |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 201 | ##if pattern is a directory and it lacks a trailing slash, add one |
| 202 | if ((-d $value)) { |
| 203 | $value =~ s@([^/])$@$1/@; |
| 204 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 205 | } elsif ($type eq "K") { |
| 206 | $keyword_hash{@typevalue} = $value; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 207 | } |
| 208 | push(@typevalue, "$type:$value"); |
| 209 | } elsif (!/^(\s)*$/) { |
| 210 | $line =~ s/\n$//g; |
| 211 | push(@typevalue, $line); |
| 212 | } |
| 213 | } |
| 214 | close(MAINT); |
| 215 | |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 216 | my %mailmap; |
| 217 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 218 | if ($email_remove_duplicates) { |
| 219 | open(MAILMAP, "<${lk_path}.mailmap") || warn "$P: Can't open .mailmap\n"; |
| 220 | while (<MAILMAP>) { |
| 221 | my $line = $_; |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 222 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 223 | next if ($line =~ m/^\s*#/); |
| 224 | next if ($line =~ m/^\s*$/); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 225 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 226 | my ($name, $address) = parse_email($line); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 227 | $line = format_email($name, $address, $email_usename); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 228 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 229 | next if ($line =~ m/^\s*$/); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 230 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 231 | if (exists($mailmap{$name})) { |
| 232 | my $obj = $mailmap{$name}; |
| 233 | push(@$obj, $address); |
| 234 | } else { |
| 235 | my @arr = ($address); |
| 236 | $mailmap{$name} = \@arr; |
| 237 | } |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 238 | } |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 239 | close(MAILMAP); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 242 | ## 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] | 243 | |
| 244 | my @files = (); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 245 | my @range = (); |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 246 | my @keyword_tvi = (); |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 247 | my @file_emails = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 248 | |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame^] | 249 | if (!@ARGV) { |
| 250 | push(@ARGV, "&STDIN"); |
| 251 | } |
| 252 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 253 | foreach my $file (@ARGV) { |
Joe Perches | 64f77f3 | 2010-03-05 13:43:04 -0800 | [diff] [blame^] | 254 | if ($file ne "&STDIN") { |
| 255 | ##if $file is a directory and it lacks a trailing slash, add one |
| 256 | if ((-d $file)) { |
| 257 | $file =~ s@([^/])$@$1/@; |
| 258 | } elsif (!(-f $file)) { |
| 259 | die "$P: file '${file}' not found\n"; |
| 260 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 261 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 262 | if ($from_filename) { |
| 263 | push(@files, $file); |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 264 | if (-f $file && ($keywords || $file_emails)) { |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 265 | open(FILE, "<$file") or die "$P: Can't open ${file}\n"; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 266 | my $text = do { local($/) ; <FILE> }; |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 267 | close(FILE); |
| 268 | if ($keywords) { |
| 269 | foreach my $line (keys %keyword_hash) { |
| 270 | if ($text =~ m/$keyword_hash{$line}/x) { |
| 271 | push(@keyword_tvi, $line); |
| 272 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 273 | } |
| 274 | } |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 275 | if ($file_emails) { |
| 276 | my @poss_addr = $text =~ m$[A-Za-zÀ-ÿ\"\' \,\.\+-]*\s*[\,]*\s*[\(\<\{]{0,1}[A-Za-z0-9_\.\+-]+\@[A-Za-z0-9\.-]+\.[A-Za-z0-9]+[\)\>\}]{0,1}$g; |
| 277 | push(@file_emails, clean_file_emails(@poss_addr)); |
| 278 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 279 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 280 | } else { |
| 281 | my $file_cnt = @files; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 282 | my $lastfile; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 283 | open(PATCH, "<$file") or die "$P: Can't open ${file}\n"; |
| 284 | while (<PATCH>) { |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 285 | my $patch_line = $_; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 286 | if (m/^\+\+\+\s+(\S+)/) { |
| 287 | my $filename = $1; |
| 288 | $filename =~ s@^[^/]*/@@; |
| 289 | $filename =~ s@\n@@; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 290 | $lastfile = $filename; |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 291 | push(@files, $filename); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 292 | } elsif (m/^\@\@ -(\d+),(\d+)/) { |
| 293 | if ($email_git_blame) { |
| 294 | push(@range, "$lastfile:$1:$2"); |
| 295 | } |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 296 | } elsif ($keywords) { |
| 297 | foreach my $line (keys %keyword_hash) { |
| 298 | if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) { |
| 299 | push(@keyword_tvi, $line); |
| 300 | } |
| 301 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 302 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 303 | } |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 304 | close(PATCH); |
| 305 | if ($file_cnt == @files) { |
Joe Perches | 7f29fd27 | 2009-06-16 15:34:04 -0700 | [diff] [blame] | 306 | warn "$P: file '${file}' doesn't appear to be a patch. " |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 307 | . "Add -f to options?\n"; |
| 308 | } |
| 309 | @files = sort_and_uniq(@files); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 310 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 311 | } |
| 312 | |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 313 | @file_emails = uniq(@file_emails); |
| 314 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 315 | my @email_to = (); |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 316 | my @list_to = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 317 | my @scm = (); |
| 318 | my @web = (); |
| 319 | my @subsystem = (); |
| 320 | my @status = (); |
| 321 | |
| 322 | # Find responsible parties |
| 323 | |
| 324 | foreach my $file (@files) { |
| 325 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 326 | my %hash; |
| 327 | my $tvi = find_first_section(); |
| 328 | while ($tvi < @typevalue) { |
| 329 | my $start = find_starting_index($tvi); |
| 330 | my $end = find_ending_index($tvi); |
| 331 | my $exclude = 0; |
| 332 | my $i; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 333 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 334 | #Do not match excluded file patterns |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 335 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 336 | for ($i = $start; $i < $end; $i++) { |
| 337 | my $line = $typevalue[$i]; |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 338 | if ($line =~ m/^(\C):\s*(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 339 | my $type = $1; |
| 340 | my $value = $2; |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 341 | if ($type eq 'X') { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 342 | if (file_match_pattern($file, $value)) { |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 343 | $exclude = 1; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | if (!$exclude) { |
| 350 | for ($i = $start; $i < $end; $i++) { |
| 351 | my $line = $typevalue[$i]; |
| 352 | if ($line =~ m/^(\C):\s*(.*)/) { |
| 353 | my $type = $1; |
| 354 | my $value = $2; |
| 355 | if ($type eq 'F') { |
| 356 | if (file_match_pattern($file, $value)) { |
| 357 | my $value_pd = ($value =~ tr@/@@); |
| 358 | my $file_pd = ($file =~ tr@/@@); |
| 359 | $value_pd++ if (substr($value,-1,1) ne "/"); |
| 360 | if ($pattern_depth == 0 || |
| 361 | (($file_pd - $value_pd) < $pattern_depth)) { |
| 362 | $hash{$tvi} = $value_pd; |
| 363 | } |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 364 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 368 | } |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 369 | |
| 370 | $tvi += ($end - $start); |
| 371 | |
| 372 | } |
| 373 | |
| 374 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
| 375 | add_categories($line); |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 376 | if ($sections) { |
| 377 | my $i; |
| 378 | my $start = find_starting_index($line); |
| 379 | my $end = find_ending_index($line); |
| 380 | for ($i = $start; $i < $end; $i++) { |
| 381 | my $line = $typevalue[$i]; |
| 382 | if ($line =~ /^[FX]:/) { ##Restore file patterns |
| 383 | $line =~ s/([^\\])\.([^\*])/$1\?$2/g; |
| 384 | $line =~ s/([^\\])\.$/$1\?/g; ##Convert . back to ? |
| 385 | $line =~ s/\\\./\./g; ##Convert \. to . |
| 386 | $line =~ s/\.\*/\*/g; ##Convert .* to * |
| 387 | } |
Joe Perches | f11e9a1 | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 388 | $line =~ s/^([A-Z]):/$1:\t/g; |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 389 | print("$line\n"); |
| 390 | } |
Joe Perches | f11e9a1 | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 391 | print("\n"); |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 392 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Joe Perches | 4a7fdb5 | 2009-04-10 12:28:57 -0700 | [diff] [blame] | 395 | if ($email && $email_git) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 396 | vcs_file_signoffs($file); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 399 | if ($email && $email_git_blame) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 400 | vcs_file_blame($file); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 401 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 404 | if ($keywords) { |
| 405 | @keyword_tvi = sort_and_uniq(@keyword_tvi); |
| 406 | foreach my $line (@keyword_tvi) { |
| 407 | add_categories($line); |
| 408 | } |
| 409 | } |
| 410 | |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 411 | if ($email) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 412 | foreach my $chief (@penguin_chief) { |
| 413 | if ($chief =~ m/^(.*):(.*)/) { |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 414 | my $email_address; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 415 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 416 | $email_address = format_email($1, $2, $email_usename); |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 417 | if ($email_git_penguin_chiefs) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 418 | push(@email_to, [$email_address, 'chief penguin']); |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 419 | } else { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 420 | @email_to = grep($_->[0] !~ /${email_address}/, @email_to); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | } |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 424 | |
| 425 | foreach my $email (@file_emails) { |
| 426 | my ($name, $address) = parse_email($email); |
| 427 | |
| 428 | my $tmp_email = format_email($name, $address, $email_usename); |
| 429 | push_email_address($tmp_email, ''); |
| 430 | add_role($tmp_email, 'in file'); |
| 431 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 434 | if ($email || $email_list) { |
| 435 | my @to = (); |
| 436 | if ($email) { |
| 437 | @to = (@to, @email_to); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 438 | } |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 439 | if ($email_list) { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 440 | @to = (@to, @list_to); |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 441 | } |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 442 | output(merge_email(@to)); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | if ($scm) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 446 | @scm = uniq(@scm); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 447 | output(@scm); |
| 448 | } |
| 449 | |
| 450 | if ($status) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 451 | @status = uniq(@status); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 452 | output(@status); |
| 453 | } |
| 454 | |
| 455 | if ($subsystem) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 456 | @subsystem = uniq(@subsystem); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 457 | output(@subsystem); |
| 458 | } |
| 459 | |
| 460 | if ($web) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 461 | @web = uniq(@web); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 462 | output(@web); |
| 463 | } |
| 464 | |
| 465 | exit($exit); |
| 466 | |
| 467 | sub file_match_pattern { |
| 468 | my ($file, $pattern) = @_; |
| 469 | if (substr($pattern, -1) eq "/") { |
| 470 | if ($file =~ m@^$pattern@) { |
| 471 | return 1; |
| 472 | } |
| 473 | } else { |
| 474 | if ($file =~ m@^$pattern@) { |
| 475 | my $s1 = ($file =~ tr@/@@); |
| 476 | my $s2 = ($pattern =~ tr@/@@); |
| 477 | if ($s1 == $s2) { |
| 478 | return 1; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | sub usage { |
| 486 | print <<EOT; |
| 487 | usage: $P [options] patchfile |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 488 | $P [options] -f file|directory |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 489 | version: $V |
| 490 | |
| 491 | MAINTAINER field selection options: |
| 492 | --email => print email address(es) if any |
| 493 | --git => include recent git \*-by: signers |
| 494 | --git-chief-penguins => include ${penguin_chiefs} |
| 495 | --git-min-signatures => number of signatures required (default: 1) |
| 496 | --git-max-maintainers => maximum maintainers to add (default: 5) |
Joe Perches | 3d202ae | 2009-07-29 15:04:29 -0700 | [diff] [blame] | 497 | --git-min-percent => minimum percentage of commits required (default: 5) |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 498 | --git-blame => use git blame to find modified commits for patch or file |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 499 | --git-since => git history to use (default: 1-year-ago) |
| 500 | --hg-since => hg history to use (default: -365) |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 501 | --m => include maintainer(s) if any |
| 502 | --n => include name 'Full Name <addr\@domain.tld>' |
| 503 | --l => include list(s) if any |
| 504 | --s => include subscriber only list(s) if any |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 505 | --remove-duplicates => minimize duplicate email names/addresses |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 506 | --roles => show roles (status:subsystem, git-signer, list, etc...) |
| 507 | --rolestats => show roles and statistics (commits/total_commits, %) |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 508 | --file-emails => add email addresses found in -f file (default: 0 (off)) |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 509 | --scm => print SCM tree(s) if any |
| 510 | --status => print status if any |
| 511 | --subsystem => print subsystem name if any |
| 512 | --web => print website(s) if any |
| 513 | |
| 514 | Output type options: |
| 515 | --separator [, ] => separator for multiple entries on 1 line |
Joe Perches | 4249831 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 516 | using --separator also sets --nomultiline if --separator is not [, ] |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 517 | --multiline => print 1 entry per line |
| 518 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 519 | Other options: |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 520 | --pattern-depth => Number of pattern directory traversals (default: 0 (all)) |
Joe Perches | dcf36a9 | 2009-10-26 16:49:47 -0700 | [diff] [blame] | 521 | --keywords => scan patch for keywords (default: 1 (on)) |
Joe Perches | 4b76c9d | 2010-03-05 13:43:03 -0800 | [diff] [blame] | 522 | --sections => print the entire subsystem sections with pattern matches |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 523 | --version => show version |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 524 | --help => show this help information |
| 525 | |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 526 | Default options: |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 527 | [--email --git --m --n --l --multiline --pattern-depth=0 --remove-duplicates] |
Joe Perches | 3fb5565 | 2009-09-21 17:04:17 -0700 | [diff] [blame] | 528 | |
Joe Perches | 870020f | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 529 | Notes: |
| 530 | Using "-f directory" may give unexpected results: |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 531 | Used with "--git", git signators for _all_ files in and below |
| 532 | directory are examined as git recurses directories. |
| 533 | Any specified X: (exclude) pattern matches are _not_ ignored. |
| 534 | Used with "--nogit", directory is used as a pattern match, |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 535 | no individual file within the directory or subdirectory |
| 536 | is matched. |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 537 | Used with "--git-blame", does not iterate all files in directory |
| 538 | Using "--git-blame" is slow and may add old committers and authors |
| 539 | that are no longer active maintainers to the output. |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 540 | Using "--roles" or "--rolestats" with git send-email --cc-cmd or any |
| 541 | other automated tools that expect only ["name"] <email address> |
| 542 | may not work because of additional output after <email address>. |
| 543 | Using "--rolestats" and "--git-blame" shows the #/total=% commits, |
| 544 | not the percentage of the entire file authored. # of commits is |
| 545 | not a good measure of amount of code authored. 1 major commit may |
| 546 | contain a thousand lines, 5 trivial commits may modify a single line. |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 547 | If git is not installed, but mercurial (hg) is installed and an .hg |
| 548 | repository exists, the following options apply to mercurial: |
| 549 | --git, |
| 550 | --git-min-signatures, --git-max-maintainers, --git-min-percent, and |
| 551 | --git-blame |
| 552 | Use --hg-since not --git-since to control date selection |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 553 | EOT |
| 554 | } |
| 555 | |
| 556 | sub top_of_kernel_tree { |
| 557 | my ($lk_path) = @_; |
| 558 | |
| 559 | if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") { |
| 560 | $lk_path .= "/"; |
| 561 | } |
| 562 | if ( (-f "${lk_path}COPYING") |
| 563 | && (-f "${lk_path}CREDITS") |
| 564 | && (-f "${lk_path}Kbuild") |
| 565 | && (-f "${lk_path}MAINTAINERS") |
| 566 | && (-f "${lk_path}Makefile") |
| 567 | && (-f "${lk_path}README") |
| 568 | && (-d "${lk_path}Documentation") |
| 569 | && (-d "${lk_path}arch") |
| 570 | && (-d "${lk_path}include") |
| 571 | && (-d "${lk_path}drivers") |
| 572 | && (-d "${lk_path}fs") |
| 573 | && (-d "${lk_path}init") |
| 574 | && (-d "${lk_path}ipc") |
| 575 | && (-d "${lk_path}kernel") |
| 576 | && (-d "${lk_path}lib") |
| 577 | && (-d "${lk_path}scripts")) { |
| 578 | return 1; |
| 579 | } |
| 580 | return 0; |
| 581 | } |
| 582 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 583 | sub parse_email { |
| 584 | my ($formatted_email) = @_; |
| 585 | |
| 586 | my $name = ""; |
| 587 | my $address = ""; |
| 588 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 589 | if ($formatted_email =~ /^([^<]+)<(.+\@.*)>.*$/) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 590 | $name = $1; |
| 591 | $address = $2; |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 592 | } elsif ($formatted_email =~ /^\s*<(.+\@\S*)>.*$/) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 593 | $address = $1; |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 594 | } elsif ($formatted_email =~ /^(.+\@\S*).*$/) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 595 | $address = $1; |
| 596 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 597 | |
| 598 | $name =~ s/^\s+|\s+$//g; |
Joe Perches | d789504 | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 599 | $name =~ s/^\"|\"$//g; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 600 | $address =~ s/^\s+|\s+$//g; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 601 | |
| 602 | if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars |
| 603 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 604 | $name = "\"$name\""; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 605 | } |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 606 | |
| 607 | return ($name, $address); |
| 608 | } |
| 609 | |
| 610 | sub format_email { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 611 | my ($name, $address, $usename) = @_; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 612 | |
| 613 | my $formatted_email; |
| 614 | |
| 615 | $name =~ s/^\s+|\s+$//g; |
| 616 | $name =~ s/^\"|\"$//g; |
| 617 | $address =~ s/^\s+|\s+$//g; |
| 618 | |
| 619 | if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars |
| 620 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes |
| 621 | $name = "\"$name\""; |
| 622 | } |
| 623 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 624 | if ($usename) { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 625 | if ("$name" eq "") { |
| 626 | $formatted_email = "$address"; |
| 627 | } else { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 628 | $formatted_email = "$name <$address>"; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 629 | } |
| 630 | } else { |
| 631 | $formatted_email = $address; |
| 632 | } |
| 633 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 634 | return $formatted_email; |
| 635 | } |
| 636 | |
Joe Perches | 272a897 | 2010-01-08 14:42:48 -0800 | [diff] [blame] | 637 | sub find_first_section { |
| 638 | my $index = 0; |
| 639 | |
| 640 | while ($index < @typevalue) { |
| 641 | my $tv = $typevalue[$index]; |
| 642 | if (($tv =~ m/^(\C):\s*(.*)/)) { |
| 643 | last; |
| 644 | } |
| 645 | $index++; |
| 646 | } |
| 647 | |
| 648 | return $index; |
| 649 | } |
| 650 | |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 651 | sub find_starting_index { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 652 | my ($index) = @_; |
| 653 | |
| 654 | while ($index > 0) { |
| 655 | my $tv = $typevalue[$index]; |
| 656 | if (!($tv =~ m/^(\C):\s*(.*)/)) { |
| 657 | last; |
| 658 | } |
| 659 | $index--; |
| 660 | } |
| 661 | |
| 662 | return $index; |
| 663 | } |
| 664 | |
| 665 | sub find_ending_index { |
| 666 | my ($index) = @_; |
| 667 | |
| 668 | while ($index < @typevalue) { |
| 669 | my $tv = $typevalue[$index]; |
| 670 | if (!($tv =~ m/^(\C):\s*(.*)/)) { |
| 671 | last; |
| 672 | } |
| 673 | $index++; |
| 674 | } |
| 675 | |
| 676 | return $index; |
| 677 | } |
| 678 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 679 | sub get_maintainer_role { |
| 680 | my ($index) = @_; |
| 681 | |
| 682 | my $i; |
| 683 | my $start = find_starting_index($index); |
| 684 | my $end = find_ending_index($index); |
| 685 | |
| 686 | my $role; |
| 687 | my $subsystem = $typevalue[$start]; |
| 688 | if (length($subsystem) > 20) { |
| 689 | $subsystem = substr($subsystem, 0, 17); |
| 690 | $subsystem =~ s/\s*$//; |
| 691 | $subsystem = $subsystem . "..."; |
| 692 | } |
| 693 | |
| 694 | for ($i = $start + 1; $i < $end; $i++) { |
| 695 | my $tv = $typevalue[$i]; |
| 696 | if ($tv =~ m/^(\C):\s*(.*)/) { |
| 697 | my $ptype = $1; |
| 698 | my $pvalue = $2; |
| 699 | if ($ptype eq "S") { |
| 700 | $role = $pvalue; |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | $role = lc($role); |
| 706 | if ($role eq "supported") { |
| 707 | $role = "supporter"; |
| 708 | } elsif ($role eq "maintained") { |
| 709 | $role = "maintainer"; |
| 710 | } elsif ($role eq "odd fixes") { |
| 711 | $role = "odd fixer"; |
| 712 | } elsif ($role eq "orphan") { |
| 713 | $role = "orphan minder"; |
| 714 | } elsif ($role eq "obsolete") { |
| 715 | $role = "obsolete minder"; |
| 716 | } elsif ($role eq "buried alive in reporters") { |
| 717 | $role = "chief penguin"; |
| 718 | } |
| 719 | |
| 720 | return $role . ":" . $subsystem; |
| 721 | } |
| 722 | |
| 723 | sub get_list_role { |
| 724 | my ($index) = @_; |
| 725 | |
| 726 | my $i; |
| 727 | my $start = find_starting_index($index); |
| 728 | my $end = find_ending_index($index); |
| 729 | |
| 730 | my $subsystem = $typevalue[$start]; |
| 731 | if (length($subsystem) > 20) { |
| 732 | $subsystem = substr($subsystem, 0, 17); |
| 733 | $subsystem =~ s/\s*$//; |
| 734 | $subsystem = $subsystem . "..."; |
| 735 | } |
| 736 | |
| 737 | if ($subsystem eq "THE REST") { |
| 738 | $subsystem = ""; |
| 739 | } |
| 740 | |
| 741 | return $subsystem; |
| 742 | } |
| 743 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 744 | sub add_categories { |
| 745 | my ($index) = @_; |
| 746 | |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 747 | my $i; |
| 748 | my $start = find_starting_index($index); |
| 749 | my $end = find_ending_index($index); |
| 750 | |
| 751 | push(@subsystem, $typevalue[$start]); |
| 752 | |
| 753 | for ($i = $start + 1; $i < $end; $i++) { |
| 754 | my $tv = $typevalue[$i]; |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 755 | if ($tv =~ m/^(\C):\s*(.*)/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 756 | my $ptype = $1; |
| 757 | my $pvalue = $2; |
| 758 | if ($ptype eq "L") { |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 759 | my $list_address = $pvalue; |
| 760 | my $list_additional = ""; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 761 | my $list_role = get_list_role($i); |
| 762 | |
| 763 | if ($list_role ne "") { |
| 764 | $list_role = ":" . $list_role; |
| 765 | } |
Joe Perches | 290603c | 2009-06-16 15:33:58 -0700 | [diff] [blame] | 766 | if ($list_address =~ m/([^\s]+)\s+(.*)$/) { |
| 767 | $list_address = $1; |
| 768 | $list_additional = $2; |
| 769 | } |
Joe Perches | bdf7c68 | 2009-06-16 15:33:59 -0700 | [diff] [blame] | 770 | if ($list_additional =~ m/subscribers-only/) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 771 | if ($email_subscriber_list) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 772 | push(@list_to, [$list_address, "subscriber list${list_role}"]); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 773 | } |
| 774 | } else { |
| 775 | if ($email_list) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 776 | push(@list_to, [$list_address, "open list${list_role}"]); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | } elsif ($ptype eq "M") { |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 780 | my ($name, $address) = parse_email($pvalue); |
| 781 | if ($name eq "") { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 782 | if ($i > 0) { |
| 783 | my $tv = $typevalue[$i - 1]; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 784 | if ($tv =~ m/^(\C):\s*(.*)/) { |
| 785 | if ($1 eq "P") { |
| 786 | $name = $2; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 787 | $pvalue = format_email($name, $address, $email_usename); |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | } |
| 791 | } |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 792 | if ($email_maintainer) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 793 | my $role = get_maintainer_role($i); |
| 794 | push_email_addresses($pvalue, $role); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 795 | } |
| 796 | } elsif ($ptype eq "T") { |
| 797 | push(@scm, $pvalue); |
| 798 | } elsif ($ptype eq "W") { |
| 799 | push(@web, $pvalue); |
| 800 | } elsif ($ptype eq "S") { |
| 801 | push(@status, $pvalue); |
| 802 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | } |
| 806 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 807 | my %email_hash_name; |
| 808 | my %email_hash_address; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 809 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 810 | sub email_inuse { |
| 811 | my ($name, $address) = @_; |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 812 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 813 | return 1 if (($name eq "") && ($address eq "")); |
| 814 | return 1 if (($name ne "") && exists($email_hash_name{$name})); |
| 815 | return 1 if (($address ne "") && exists($email_hash_address{$address})); |
| 816 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 817 | return 0; |
| 818 | } |
| 819 | |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 820 | sub push_email_address { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 821 | my ($line, $role) = @_; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 822 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 823 | my ($name, $address) = parse_email($line); |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 824 | |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 825 | if ($address eq "") { |
| 826 | return 0; |
| 827 | } |
| 828 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 829 | if (!$email_remove_duplicates) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 830 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 831 | } elsif (!email_inuse($name, $address)) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 832 | push(@email_to, [format_email($name, $address, $email_usename), $role]); |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 833 | $email_hash_name{$name}++; |
| 834 | $email_hash_address{$address}++; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 835 | } |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 836 | |
| 837 | return 1; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | sub push_email_addresses { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 841 | my ($address, $role) = @_; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 842 | |
| 843 | my @address_list = (); |
| 844 | |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 845 | if (rfc822_valid($address)) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 846 | push_email_address($address, $role); |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 847 | } elsif (@address_list = rfc822_validlist($address)) { |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 848 | my $array_count = shift(@address_list); |
| 849 | while (my $entry = shift(@address_list)) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 850 | push_email_address($entry, $role); |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 851 | } |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 852 | } else { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 853 | if (!push_email_address($address, $role)) { |
Joe Perches | b781655 | 2009-09-21 17:04:24 -0700 | [diff] [blame] | 854 | warn("Invalid MAINTAINERS address: '" . $address . "'\n"); |
| 855 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 856 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 859 | sub add_role { |
| 860 | my ($line, $role) = @_; |
| 861 | |
| 862 | my ($name, $address) = parse_email($line); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 863 | my $email = format_email($name, $address, $email_usename); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 864 | |
| 865 | foreach my $entry (@email_to) { |
| 866 | if ($email_remove_duplicates) { |
| 867 | my ($entry_name, $entry_address) = parse_email($entry->[0]); |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 868 | if (($name eq $entry_name || $address eq $entry_address) |
| 869 | && ($role eq "" || !($entry->[1] =~ m/$role/)) |
| 870 | ) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 871 | if ($entry->[1] eq "") { |
| 872 | $entry->[1] = "$role"; |
| 873 | } else { |
| 874 | $entry->[1] = "$entry->[1],$role"; |
| 875 | } |
| 876 | } |
| 877 | } else { |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 878 | if ($email eq $entry->[0] |
| 879 | && ($role eq "" || !($entry->[1] =~ m/$role/)) |
| 880 | ) { |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 881 | if ($entry->[1] eq "") { |
| 882 | $entry->[1] = "$role"; |
| 883 | } else { |
| 884 | $entry->[1] = "$entry->[1],$role"; |
| 885 | } |
| 886 | } |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 891 | sub which { |
| 892 | my ($bin) = @_; |
| 893 | |
Joe Perches | f5f5078d | 2009-06-16 15:34:00 -0700 | [diff] [blame] | 894 | foreach my $path (split(/:/, $ENV{PATH})) { |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 895 | if (-e "$path/$bin") { |
| 896 | return "$path/$bin"; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | return ""; |
| 901 | } |
| 902 | |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 903 | sub mailmap { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 904 | my (@lines) = @_; |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 905 | my %hash; |
| 906 | |
| 907 | foreach my $line (@lines) { |
| 908 | my ($name, $address) = parse_email($line); |
| 909 | if (!exists($hash{$name})) { |
| 910 | $hash{$name} = $address; |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 911 | } elsif ($address ne $hash{$name}) { |
| 912 | $address = $hash{$name}; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 913 | $line = format_email($name, $address, $email_usename); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 914 | } |
| 915 | if (exists($mailmap{$name})) { |
| 916 | my $obj = $mailmap{$name}; |
| 917 | foreach my $map_address (@$obj) { |
| 918 | if (($map_address eq $address) && |
| 919 | ($map_address ne $hash{$name})) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 920 | $line = format_email($name, $hash{$name}, $email_usename); |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | return @lines; |
| 927 | } |
| 928 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 929 | sub git_execute_cmd { |
| 930 | my ($cmd) = @_; |
| 931 | my @lines = (); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 932 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 933 | my $output = `$cmd`; |
| 934 | $output =~ s/^\s*//gm; |
| 935 | @lines = split("\n", $output); |
| 936 | |
| 937 | return @lines; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 940 | sub hg_execute_cmd { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 941 | my ($cmd) = @_; |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 942 | my @lines = (); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 943 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 944 | my $output = `$cmd`; |
| 945 | @lines = split("\n", $output); |
| 946 | |
| 947 | return @lines; |
| 948 | } |
| 949 | |
| 950 | sub vcs_find_signers { |
| 951 | my ($cmd) = @_; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 952 | my @lines = (); |
| 953 | my $commits; |
| 954 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 955 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 956 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 957 | my $pattern = $VCS_cmds{"commit_pattern"}; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 958 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 959 | $commits = grep(/$pattern/, @lines); # of commits |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 960 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 961 | @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines); |
| 962 | if (!$email_git_penguin_chiefs) { |
| 963 | @lines = grep(!/${penguin_chiefs}/i, @lines); |
| 964 | } |
| 965 | # cut -f2- -d":" |
| 966 | s/.*:\s*(.+)\s*/$1/ for (@lines); |
| 967 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 968 | ## Reformat email addresses (with names) to avoid badly written signatures |
| 969 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 970 | foreach my $line (@lines) { |
| 971 | my ($name, $address) = parse_email($line); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 972 | $line = format_email($name, $address, 1); |
| 973 | } |
| 974 | |
| 975 | return ($commits, @lines); |
| 976 | } |
| 977 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 978 | sub vcs_save_commits { |
| 979 | my ($cmd) = @_; |
| 980 | my @lines = (); |
| 981 | my @commits = (); |
| 982 | |
| 983 | @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); |
| 984 | |
| 985 | foreach my $line (@lines) { |
| 986 | if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) { |
| 987 | push(@commits, $1); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | return @commits; |
| 992 | } |
| 993 | |
| 994 | sub vcs_blame { |
| 995 | my ($file) = @_; |
| 996 | my $cmd; |
| 997 | my @commits = (); |
| 998 | |
| 999 | return @commits if (!(-f $file)); |
| 1000 | |
| 1001 | if (@range && $VCS_cmds{"blame_range_cmd"} eq "") { |
| 1002 | my @all_commits = (); |
| 1003 | |
| 1004 | $cmd = $VCS_cmds{"blame_file_cmd"}; |
| 1005 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1006 | @all_commits = vcs_save_commits($cmd); |
| 1007 | |
| 1008 | foreach my $file_range_diff (@range) { |
| 1009 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
| 1010 | my $diff_file = $1; |
| 1011 | my $diff_start = $2; |
| 1012 | my $diff_length = $3; |
| 1013 | next if ("$file" ne "$diff_file"); |
| 1014 | for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) { |
| 1015 | push(@commits, $all_commits[$i]); |
| 1016 | } |
| 1017 | } |
| 1018 | } elsif (@range) { |
| 1019 | foreach my $file_range_diff (@range) { |
| 1020 | next if (!($file_range_diff =~ m/(.+):(.+):(.+)/)); |
| 1021 | my $diff_file = $1; |
| 1022 | my $diff_start = $2; |
| 1023 | my $diff_length = $3; |
| 1024 | next if ("$file" ne "$diff_file"); |
| 1025 | $cmd = $VCS_cmds{"blame_range_cmd"}; |
| 1026 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1027 | push(@commits, vcs_save_commits($cmd)); |
| 1028 | } |
| 1029 | } else { |
| 1030 | $cmd = $VCS_cmds{"blame_file_cmd"}; |
| 1031 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1032 | @commits = vcs_save_commits($cmd); |
| 1033 | } |
| 1034 | |
| 1035 | return @commits; |
| 1036 | } |
| 1037 | |
| 1038 | my $printed_novcs = 0; |
| 1039 | sub vcs_exists { |
| 1040 | %VCS_cmds = %VCS_cmds_git; |
| 1041 | return 1 if eval $VCS_cmds{"available"}; |
| 1042 | %VCS_cmds = %VCS_cmds_hg; |
| 1043 | return 1 if eval $VCS_cmds{"available"}; |
| 1044 | %VCS_cmds = (); |
| 1045 | if (!$printed_novcs) { |
| 1046 | warn("$P: No supported VCS found. Add --nogit to options?\n"); |
| 1047 | warn("Using a git repository produces better results.\n"); |
| 1048 | warn("Try Linus Torvalds' latest git repository using:\n"); |
| 1049 | warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n"); |
| 1050 | $printed_novcs = 1; |
| 1051 | } |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
| 1055 | sub vcs_assign { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1056 | my ($role, $divisor, @lines) = @_; |
| 1057 | |
| 1058 | my %hash; |
| 1059 | my $count = 0; |
| 1060 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1061 | return if (@lines <= 0); |
| 1062 | |
| 1063 | if ($divisor <= 0) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1064 | warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n"); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1065 | $divisor = 1; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1066 | } |
Joe Perches | 8cbb3a7 | 2009-09-21 17:04:21 -0700 | [diff] [blame] | 1067 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 1068 | if ($email_remove_duplicates) { |
| 1069 | @lines = mailmap(@lines); |
| 1070 | } |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 1071 | |
Joe Perches | 0e70e83 | 2009-09-21 17:04:20 -0700 | [diff] [blame] | 1072 | @lines = sort(@lines); |
Joe Perches | afa81ee | 2009-07-29 15:04:28 -0700 | [diff] [blame] | 1073 | |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 1074 | # uniq -c |
| 1075 | $hash{$_}++ for @lines; |
| 1076 | |
| 1077 | # sort -rn |
| 1078 | foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) { |
| 1079 | my $sign_offs = $hash{$line}; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1080 | my $percent = $sign_offs * 100 / $divisor; |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1081 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1082 | $percent = 100 if ($percent > 100); |
Joe Perches | 11ecf53 | 2009-09-21 17:04:22 -0700 | [diff] [blame] | 1083 | $count++; |
| 1084 | last if ($sign_offs < $email_git_min_signatures || |
| 1085 | $count > $email_git_max_maintainers || |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1086 | $percent < $email_git_min_percent); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1087 | push_email_address($line, ''); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1088 | if ($output_rolestats) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1089 | my $fmt_percent = sprintf("%.0f", $percent); |
| 1090 | add_role($line, "$role:$sign_offs/$divisor=$fmt_percent%"); |
| 1091 | } else { |
| 1092 | add_role($line, $role); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1093 | } |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1094 | } |
| 1095 | } |
| 1096 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1097 | sub vcs_file_signoffs { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1098 | my ($file) = @_; |
| 1099 | |
| 1100 | my @signers = (); |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1101 | my $commits; |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1102 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1103 | return if (!vcs_exists()); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1104 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1105 | my $cmd = $VCS_cmds{"find_signers_cmd"}; |
| 1106 | $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd |
| 1107 | |
| 1108 | ($commits, @signers) = vcs_find_signers($cmd); |
| 1109 | vcs_assign("commit_signer", $commits, @signers); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1112 | sub vcs_file_blame { |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1113 | my ($file) = @_; |
| 1114 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1115 | my @signers = (); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1116 | my @commits = (); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1117 | my $total_commits; |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1118 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1119 | return if (!vcs_exists()); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1120 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1121 | @commits = vcs_blame($file); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1122 | @commits = uniq(@commits); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1123 | $total_commits = @commits; |
| 1124 | |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1125 | foreach my $commit (@commits) { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1126 | my $commit_count; |
| 1127 | my @commit_signers = (); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1128 | |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1129 | my $cmd = $VCS_cmds{"find_commit_signers_cmd"}; |
| 1130 | $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd |
| 1131 | |
| 1132 | ($commit_count, @commit_signers) = vcs_find_signers($cmd); |
| 1133 | push(@signers, @commit_signers); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1136 | if ($from_filename) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1137 | vcs_assign("commits", $total_commits, @signers); |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1138 | } else { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1139 | vcs_assign("modified commits", $total_commits, @signers); |
Joe Perches | f549266 | 2009-09-21 17:04:13 -0700 | [diff] [blame] | 1140 | } |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | sub uniq { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1144 | my (@parms) = @_; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1145 | |
| 1146 | my %saw; |
| 1147 | @parms = grep(!$saw{$_}++, @parms); |
| 1148 | return @parms; |
| 1149 | } |
| 1150 | |
| 1151 | sub sort_and_uniq { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1152 | my (@parms) = @_; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1153 | |
| 1154 | my %saw; |
| 1155 | @parms = sort @parms; |
| 1156 | @parms = grep(!$saw{$_}++, @parms); |
| 1157 | return @parms; |
| 1158 | } |
| 1159 | |
Joe Perches | 03372db | 2010-03-05 13:43:00 -0800 | [diff] [blame] | 1160 | sub clean_file_emails { |
| 1161 | my (@file_emails) = @_; |
| 1162 | my @fmt_emails = (); |
| 1163 | |
| 1164 | foreach my $email (@file_emails) { |
| 1165 | $email =~ s/[\(\<\{]{0,1}([A-Za-z0-9_\.\+-]+\@[A-Za-z0-9\.-]+)[\)\>\}]{0,1}/\<$1\>/g; |
| 1166 | my ($name, $address) = parse_email($email); |
| 1167 | if ($name eq '"[,\.]"') { |
| 1168 | $name = ""; |
| 1169 | } |
| 1170 | |
| 1171 | my @nw = split(/[^A-Za-zÀ-ÿ\'\,\.\+-]/, $name); |
| 1172 | if (@nw > 2) { |
| 1173 | my $first = $nw[@nw - 3]; |
| 1174 | my $middle = $nw[@nw - 2]; |
| 1175 | my $last = $nw[@nw - 1]; |
| 1176 | |
| 1177 | if (((length($first) == 1 && $first =~ m/[A-Za-z]/) || |
| 1178 | (length($first) == 2 && substr($first, -1) eq ".")) || |
| 1179 | (length($middle) == 1 || |
| 1180 | (length($middle) == 2 && substr($middle, -1) eq "."))) { |
| 1181 | $name = "$first $middle $last"; |
| 1182 | } else { |
| 1183 | $name = "$middle $last"; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | if (substr($name, -1) =~ /[,\.]/) { |
| 1188 | $name = substr($name, 0, length($name) - 1); |
| 1189 | } elsif (substr($name, -2) =~ /[,\.]"/) { |
| 1190 | $name = substr($name, 0, length($name) - 2) . '"'; |
| 1191 | } |
| 1192 | |
| 1193 | if (substr($name, 0, 1) =~ /[,\.]/) { |
| 1194 | $name = substr($name, 1, length($name) - 1); |
| 1195 | } elsif (substr($name, 0, 2) =~ /"[,\.]/) { |
| 1196 | $name = '"' . substr($name, 2, length($name) - 2); |
| 1197 | } |
| 1198 | |
| 1199 | my $fmt_email = format_email($name, $address, $email_usename); |
| 1200 | push(@fmt_emails, $fmt_email); |
| 1201 | } |
| 1202 | return @fmt_emails; |
| 1203 | } |
| 1204 | |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1205 | sub merge_email { |
| 1206 | my @lines; |
| 1207 | my %saw; |
| 1208 | |
| 1209 | for (@_) { |
| 1210 | my ($address, $role) = @$_; |
| 1211 | if (!$saw{$address}) { |
| 1212 | if ($output_roles) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1213 | push(@lines, "$address ($role)"); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1214 | } else { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1215 | push(@lines, $address); |
Joe Perches | 3c7385b | 2009-12-14 18:00:46 -0800 | [diff] [blame] | 1216 | } |
| 1217 | $saw{$address} = 1; |
| 1218 | } |
| 1219 | } |
| 1220 | |
| 1221 | return @lines; |
| 1222 | } |
| 1223 | |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1224 | sub output { |
Joe Perches | a8af243 | 2009-12-14 18:00:49 -0800 | [diff] [blame] | 1225 | my (@parms) = @_; |
Joe Perches | cb7301c | 2009-04-07 20:40:12 -0700 | [diff] [blame] | 1226 | |
| 1227 | if ($output_multiline) { |
| 1228 | foreach my $line (@parms) { |
| 1229 | print("${line}\n"); |
| 1230 | } |
| 1231 | } else { |
| 1232 | print(join($output_separator, @parms)); |
| 1233 | print("\n"); |
| 1234 | } |
| 1235 | } |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1236 | |
| 1237 | my $rfc822re; |
| 1238 | |
| 1239 | sub make_rfc822re { |
| 1240 | # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and |
| 1241 | # comment. We must allow for rfc822_lwsp (or comments) after each of these. |
| 1242 | # This regexp will only work on addresses which have had comments stripped |
| 1243 | # and replaced with rfc822_lwsp. |
| 1244 | |
| 1245 | my $specials = '()<>@,;:\\\\".\\[\\]'; |
| 1246 | my $controls = '\\000-\\037\\177'; |
| 1247 | |
| 1248 | my $dtext = "[^\\[\\]\\r\\\\]"; |
| 1249 | my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*"; |
| 1250 | |
| 1251 | my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*"; |
| 1252 | |
| 1253 | # Use zero-width assertion to spot the limit of an atom. A simple |
| 1254 | # $rfc822_lwsp* causes the regexp engine to hang occasionally. |
| 1255 | my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))"; |
| 1256 | my $word = "(?:$atom|$quoted_string)"; |
| 1257 | my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*"; |
| 1258 | |
| 1259 | my $sub_domain = "(?:$atom|$domain_literal)"; |
| 1260 | my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*"; |
| 1261 | |
| 1262 | my $addr_spec = "$localpart\@$rfc822_lwsp*$domain"; |
| 1263 | |
| 1264 | my $phrase = "$word*"; |
| 1265 | my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)"; |
| 1266 | my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*"; |
| 1267 | my $mailbox = "(?:$addr_spec|$phrase$route_addr)"; |
| 1268 | |
| 1269 | my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*"; |
| 1270 | my $address = "(?:$mailbox|$group)"; |
| 1271 | |
| 1272 | return "$rfc822_lwsp*$address"; |
| 1273 | } |
| 1274 | |
| 1275 | sub rfc822_strip_comments { |
| 1276 | my $s = shift; |
| 1277 | # Recursively remove comments, and replace with a single space. The simpler |
| 1278 | # regexps in the Email Addressing FAQ are imperfect - they will miss escaped |
| 1279 | # chars in atoms, for example. |
| 1280 | |
| 1281 | while ($s =~ s/^((?:[^"\\]|\\.)* |
| 1282 | (?:"(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*)*) |
| 1283 | \((?:[^()\\]|\\.)*\)/$1 /osx) {} |
| 1284 | return $s; |
| 1285 | } |
| 1286 | |
| 1287 | # valid: returns true if the parameter is an RFC822 valid address |
| 1288 | # |
| 1289 | sub rfc822_valid ($) { |
| 1290 | my $s = rfc822_strip_comments(shift); |
| 1291 | |
| 1292 | if (!$rfc822re) { |
| 1293 | $rfc822re = make_rfc822re(); |
| 1294 | } |
| 1295 | |
| 1296 | return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/; |
| 1297 | } |
| 1298 | |
| 1299 | # validlist: In scalar context, returns true if the parameter is an RFC822 |
| 1300 | # valid list of addresses. |
| 1301 | # |
| 1302 | # In list context, returns an empty list on failure (an invalid |
| 1303 | # address was found); otherwise a list whose first element is the |
| 1304 | # number of addresses found and whose remaining elements are the |
| 1305 | # addresses. This is needed to disambiguate failure (invalid) |
| 1306 | # from success with no addresses found, because an empty string is |
| 1307 | # a valid list. |
| 1308 | |
| 1309 | sub rfc822_validlist ($) { |
| 1310 | my $s = rfc822_strip_comments(shift); |
| 1311 | |
| 1312 | if (!$rfc822re) { |
| 1313 | $rfc822re = make_rfc822re(); |
| 1314 | } |
| 1315 | # * null list items are valid according to the RFC |
| 1316 | # * the '1' business is to aid in distinguishing failure from no results |
| 1317 | |
| 1318 | my @r; |
| 1319 | if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so && |
| 1320 | $s =~ m/^$rfc822_char*$/) { |
Joe Perches | 5f2441e | 2009-06-16 15:34:02 -0700 | [diff] [blame] | 1321 | while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) { |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1322 | push(@r, $1); |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1323 | } |
| 1324 | return wantarray ? (scalar(@r), @r) : 1; |
| 1325 | } |
Joe Perches | 60db31a | 2009-12-14 18:00:50 -0800 | [diff] [blame] | 1326 | return wantarray ? () : 0; |
Joe Perches | 1b5e1cf | 2009-06-16 15:34:01 -0700 | [diff] [blame] | 1327 | } |