Fork of the vendor (Boundary Devices) u-boot for Reform 2, with minor tweaks. The goal is to migrate to mainstream u-boot or barebox ASAP. The main impediment so far is the 4GB RAM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2555 lines
65 KiB

  1. #!/usr/bin/env perl
  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_maintainer.pl [OPTIONS] <patch>
  9. # perl scripts/get_maintainer.pl [OPTIONS] -f <file>
  10. #
  11. # Licensed under the terms of the GNU GPL License version 2
  12. use warnings;
  13. use strict;
  14. my $P = $0;
  15. my $V = '0.26';
  16. use Getopt::Long qw(:config no_auto_abbrev);
  17. use Cwd;
  18. use File::Find;
  19. my $cur_path = fastgetcwd() . '/';
  20. my $lk_path = "./";
  21. my $email = 1;
  22. my $email_usename = 1;
  23. my $email_maintainer = 1;
  24. my $email_reviewer = 1;
  25. my $email_list = 1;
  26. my $email_subscriber_list = 0;
  27. my $email_git_penguin_chiefs = 0;
  28. my $email_git = 0;
  29. my $email_git_all_signature_types = 0;
  30. my $email_git_blame = 0;
  31. my $email_git_blame_signatures = 1;
  32. my $email_git_fallback = 1;
  33. my $email_git_min_signatures = 1;
  34. my $email_git_max_maintainers = 5;
  35. my $email_git_min_percent = 5;
  36. my $email_git_since = "1-year-ago";
  37. my $email_hg_since = "-365";
  38. my $interactive = 0;
  39. my $email_remove_duplicates = 1;
  40. my $email_use_mailmap = 1;
  41. my $output_multiline = 1;
  42. my $output_separator = ", ";
  43. my $output_roles = 0;
  44. my $output_rolestats = 1;
  45. my $output_section_maxlen = 50;
  46. my $scm = 0;
  47. my $web = 0;
  48. my $subsystem = 0;
  49. my $status = 0;
  50. my $letters = "";
  51. my $keywords = 1;
  52. my $sections = 0;
  53. my $file_emails = 0;
  54. my $from_filename = 0;
  55. my $pattern_depth = 0;
  56. my $self_test = undef;
  57. my $version = 0;
  58. my $help = 0;
  59. my $find_maintainer_files = 1;
  60. my $vcs_used = 0;
  61. my $exit = 0;
  62. my %commit_author_hash;
  63. my %commit_signer_hash;
  64. my @penguin_chief = ();
  65. push(@penguin_chief, "Tom Rini:trini\@konsulko.com");
  66. my @penguin_chief_names = ();
  67. foreach my $chief (@penguin_chief) {
  68. if ($chief =~ m/^(.*):(.*)/) {
  69. my $chief_name = $1;
  70. my $chief_addr = $2;
  71. push(@penguin_chief_names, $chief_name);
  72. }
  73. }
  74. my $penguin_chiefs = "\(" . join("|", @penguin_chief_names) . "\)";
  75. # Signature types of people who are either
  76. # a) responsible for the code in question, or
  77. # b) familiar enough with it to give relevant feedback
  78. my @signature_tags = ();
  79. push(@signature_tags, "Signed-off-by:");
  80. push(@signature_tags, "Reviewed-by:");
  81. push(@signature_tags, "Acked-by:");
  82. my $signature_pattern = "\(" . join("|", @signature_tags) . "\)";
  83. # rfc822 email address - preloaded methods go here.
  84. my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
  85. my $rfc822_char = '[\\000-\\377]';
  86. # VCS command support: class-like functions and strings
  87. my %VCS_cmds;
  88. my %VCS_cmds_git = (
  89. "execute_cmd" => \&git_execute_cmd,
  90. "available" => '(which("git") ne "") && (-e ".git")',
  91. "find_signers_cmd" =>
  92. "git log --no-color --follow --since=\$email_git_since " .
  93. '--numstat --no-merges ' .
  94. '--format="GitCommit: %H%n' .
  95. 'GitAuthor: %an <%ae>%n' .
  96. 'GitDate: %aD%n' .
  97. 'GitSubject: %s%n' .
  98. '%b%n"' .
  99. " -- \$file",
  100. "find_commit_signers_cmd" =>
  101. "git log --no-color " .
  102. '--numstat ' .
  103. '--format="GitCommit: %H%n' .
  104. 'GitAuthor: %an <%ae>%n' .
  105. 'GitDate: %aD%n' .
  106. 'GitSubject: %s%n' .
  107. '%b%n"' .
  108. " -1 \$commit",
  109. "find_commit_author_cmd" =>
  110. "git log --no-color " .
  111. '--numstat ' .
  112. '--format="GitCommit: %H%n' .
  113. 'GitAuthor: %an <%ae>%n' .
  114. 'GitDate: %aD%n' .
  115. 'GitSubject: %s%n"' .
  116. " -1 \$commit",
  117. "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
  118. "blame_file_cmd" => "git blame -l \$file",
  119. "commit_pattern" => "^GitCommit: ([0-9a-f]{40,40})",
  120. "blame_commit_pattern" => "^([0-9a-f]+) ",
  121. "author_pattern" => "^GitAuthor: (.*)",
  122. "subject_pattern" => "^GitSubject: (.*)",
  123. "stat_pattern" => "^(\\d+)\\t(\\d+)\\t\$file\$",
  124. "file_exists_cmd" => "git ls-files \$file",
  125. "list_files_cmd" => "git ls-files \$file",
  126. );
  127. my %VCS_cmds_hg = (
  128. "execute_cmd" => \&hg_execute_cmd,
  129. "available" => '(which("hg") ne "") && (-d ".hg")',
  130. "find_signers_cmd" =>
  131. "hg log --date=\$email_hg_since " .
  132. "--template='HgCommit: {node}\\n" .
  133. "HgAuthor: {author}\\n" .
  134. "HgSubject: {desc}\\n'" .
  135. " -- \$file",
  136. "find_commit_signers_cmd" =>
  137. "hg log " .
  138. "--template='HgSubject: {desc}\\n'" .
  139. " -r \$commit",
  140. "find_commit_author_cmd" =>
  141. "hg log " .
  142. "--template='HgCommit: {node}\\n" .
  143. "HgAuthor: {author}\\n" .
  144. "HgSubject: {desc|firstline}\\n'" .
  145. " -r \$commit",
  146. "blame_range_cmd" => "", # not supported
  147. "blame_file_cmd" => "hg blame -n \$file",
  148. "commit_pattern" => "^HgCommit: ([0-9a-f]{40,40})",
  149. "blame_commit_pattern" => "^([ 0-9a-f]+):",
  150. "author_pattern" => "^HgAuthor: (.*)",
  151. "subject_pattern" => "^HgSubject: (.*)",
  152. "stat_pattern" => "^(\\d+)\t(\\d+)\t\$file\$",
  153. "file_exists_cmd" => "hg files \$file",
  154. "list_files_cmd" => "hg manifest -R \$file",
  155. );
  156. my $conf = which_conf(".get_maintainer.conf");
  157. if (-f $conf) {
  158. my @conf_args;
  159. open(my $conffile, '<', "$conf")
  160. or warn "$P: Can't find a readable .get_maintainer.conf file $!\n";
  161. while (<$conffile>) {
  162. my $line = $_;
  163. $line =~ s/\s*\n?$//g;
  164. $line =~ s/^\s*//g;
  165. $line =~ s/\s+/ /g;
  166. next if ($line =~ m/^\s*#/);
  167. next if ($line =~ m/^\s*$/);
  168. my @words = split(" ", $line);
  169. foreach my $word (@words) {
  170. last if ($word =~ m/^#/);
  171. push (@conf_args, $word);
  172. }
  173. }
  174. close($conffile);
  175. unshift(@ARGV, @conf_args) if @conf_args;
  176. }
  177. my @ignore_emails = ();
  178. my $ignore_file = which_conf(".get_maintainer.ignore");
  179. if (-f $ignore_file) {
  180. open(my $ignore, '<', "$ignore_file")
  181. or warn "$P: Can't find a readable .get_maintainer.ignore file $!\n";
  182. while (<$ignore>) {
  183. my $line = $_;
  184. $line =~ s/\s*\n?$//;
  185. $line =~ s/^\s*//;
  186. $line =~ s/\s+$//;
  187. $line =~ s/#.*$//;
  188. next if ($line =~ m/^\s*$/);
  189. if (rfc822_valid($line)) {
  190. push(@ignore_emails, $line);
  191. }
  192. }
  193. close($ignore);
  194. }
  195. if ($#ARGV > 0) {
  196. foreach (@ARGV) {
  197. if ($_ =~ /^-{1,2}self-test(?:=|$)/) {
  198. die "$P: using --self-test does not allow any other option or argument\n";
  199. }
  200. }
  201. }
  202. if (!GetOptions(
  203. 'email!' => \$email,
  204. 'git!' => \$email_git,
  205. 'git-all-signature-types!' => \$email_git_all_signature_types,
  206. 'git-blame!' => \$email_git_blame,
  207. 'git-blame-signatures!' => \$email_git_blame_signatures,
  208. 'git-fallback!' => \$email_git_fallback,
  209. 'git-chief-penguins!' => \$email_git_penguin_chiefs,
  210. 'git-min-signatures=i' => \$email_git_min_signatures,
  211. 'git-max-maintainers=i' => \$email_git_max_maintainers,
  212. 'git-min-percent=i' => \$email_git_min_percent,
  213. 'git-since=s' => \$email_git_since,
  214. 'hg-since=s' => \$email_hg_since,
  215. 'i|interactive!' => \$interactive,
  216. 'remove-duplicates!' => \$email_remove_duplicates,
  217. 'mailmap!' => \$email_use_mailmap,
  218. 'm!' => \$email_maintainer,
  219. 'r!' => \$email_reviewer,
  220. 'n!' => \$email_usename,
  221. 'l!' => \$email_list,
  222. 's!' => \$email_subscriber_list,
  223. 'multiline!' => \$output_multiline,
  224. 'roles!' => \$output_roles,
  225. 'rolestats!' => \$output_rolestats,
  226. 'separator=s' => \$output_separator,
  227. 'subsystem!' => \$subsystem,
  228. 'status!' => \$status,
  229. 'scm!' => \$scm,
  230. 'web!' => \$web,
  231. 'letters=s' => \$letters,
  232. 'pattern-depth=i' => \$pattern_depth,
  233. 'k|keywords!' => \$keywords,
  234. 'sections!' => \$sections,
  235. 'fe|file-emails!' => \$file_emails,
  236. 'f|file' => \$from_filename,
  237. 'find-maintainer-files' => \$find_maintainer_files,
  238. 'self-test:s' => \$self_test,
  239. 'v|version' => \$version,
  240. 'h|help|usage' => \$help,
  241. )) {
  242. die "$P: invalid argument - use --help if necessary\n";
  243. }
  244. if ($help != 0) {
  245. usage();
  246. exit 0;
  247. }
  248. if ($version != 0) {
  249. print("${P} ${V}\n");
  250. exit 0;
  251. }
  252. if (defined $self_test) {
  253. read_all_maintainer_files();
  254. self_test();
  255. exit 0;
  256. }
  257. if (-t STDIN && !@ARGV) {
  258. # We're talking to a terminal, but have no command line arguments.
  259. die "$P: missing patchfile or -f file - use --help if necessary\n";
  260. }
  261. $output_multiline = 0 if ($output_separator ne ", ");
  262. $output_rolestats = 1 if ($interactive);
  263. $output_roles = 1 if ($output_rolestats);
  264. if ($sections || $letters ne "") {
  265. $sections = 1;
  266. $email = 0;
  267. $email_list = 0;
  268. $scm = 0;
  269. $status = 0;
  270. $subsystem = 0;
  271. $web = 0;
  272. $keywords = 0;
  273. $interactive = 0;
  274. } else {
  275. my $selections = $email + $scm + $status + $subsystem + $web;
  276. if ($selections == 0) {
  277. die "$P: Missing required option: email, scm, status, subsystem or web\n";
  278. }
  279. }
  280. if ($email &&
  281. ($email_maintainer + $email_reviewer +
  282. $email_list + $email_subscriber_list +
  283. $email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
  284. die "$P: Please select at least 1 email option\n";
  285. }
  286. if (!top_of_kernel_tree($lk_path)) {
  287. die "$P: The current directory does not appear to be "
  288. . "a U-Boot source tree.\n";
  289. }
  290. ## Read MAINTAINERS for type/value pairs
  291. my @typevalue = ();
  292. my %keyword_hash;
  293. my @mfiles = ();
  294. my @self_test_info = ();
  295. sub read_maintainer_file {
  296. my ($file) = @_;
  297. open (my $maint, '<', "$file")
  298. or die "$P: Can't open MAINTAINERS file '$file': $!\n";
  299. my $i = 1;
  300. while (<$maint>) {
  301. my $line = $_;
  302. chomp $line;
  303. if ($line =~ m/^([A-Z]):\s*(.*)/) {
  304. my $type = $1;
  305. my $value = $2;
  306. ##Filename pattern matching
  307. if ($type eq "F" || $type eq "X") {
  308. $value =~ s@\.@\\\.@g; ##Convert . to \.
  309. $value =~ s/\*/\.\*/g; ##Convert * to .*
  310. $value =~ s/\?/\./g; ##Convert ? to .
  311. ##if pattern is a directory and it lacks a trailing slash, add one
  312. if ((-d $value)) {
  313. $value =~ s@([^/])$@$1/@;
  314. }
  315. } elsif ($type eq "K") {
  316. $keyword_hash{@typevalue} = $value;
  317. }
  318. push(@typevalue, "$type:$value");
  319. } elsif (!(/^\s*$/ || /^\s*\#/)) {
  320. push(@typevalue, $line);
  321. }
  322. if (defined $self_test) {
  323. push(@self_test_info, {file=>$file, linenr=>$i, line=>$line});
  324. }
  325. $i++;
  326. }
  327. close($maint);
  328. }
  329. sub find_is_maintainer_file {
  330. my ($file) = $_;
  331. return if ($file !~ m@/MAINTAINERS$@);
  332. $file = $File::Find::name;
  333. return if (! -f $file);
  334. push(@mfiles, $file);
  335. }
  336. sub find_ignore_git {
  337. return grep { $_ !~ /^\.git$/; } @_;
  338. }
  339. read_all_maintainer_files();
  340. sub read_all_maintainer_files {
  341. if (-d "${lk_path}MAINTAINERS") {
  342. opendir(DIR, "${lk_path}MAINTAINERS") or die $!;
  343. my @files = readdir(DIR);
  344. closedir(DIR);
  345. foreach my $file (@files) {
  346. push(@mfiles, "${lk_path}MAINTAINERS/$file") if ($file !~ /^\./);
  347. }
  348. }
  349. if ($find_maintainer_files) {
  350. find( { wanted => \&find_is_maintainer_file,
  351. preprocess => \&find_ignore_git,
  352. no_chdir => 1,
  353. }, "${lk_path}");
  354. } else {
  355. push(@mfiles, "${lk_path}MAINTAINERS") if -f "${lk_path}MAINTAINERS";
  356. }
  357. foreach my $file (@mfiles) {
  358. read_maintainer_file("$file");
  359. }
  360. }
  361. #
  362. # Read mail address map
  363. #
  364. my $mailmap;
  365. read_mailmap();
  366. sub read_mailmap {
  367. $mailmap = {
  368. names => {},
  369. addresses => {}
  370. };
  371. return if (!$email_use_mailmap || !(-f "${lk_path}.mailmap"));
  372. open(my $mailmap_file, '<', "${lk_path}.mailmap")
  373. or warn "$P: Can't open .mailmap: $!\n";
  374. while (<$mailmap_file>) {
  375. s/#.*$//; #strip comments
  376. s/^\s+|\s+$//g; #trim
  377. next if (/^\s*$/); #skip empty lines
  378. #entries have one of the following formats:
  379. # name1 <mail1>
  380. # <mail1> <mail2>
  381. # name1 <mail1> <mail2>
  382. # name1 <mail1> name2 <mail2>
  383. # (see man git-shortlog)
  384. if (/^([^<]+)<([^>]+)>$/) {
  385. my $real_name = $1;
  386. my $address = $2;
  387. $real_name =~ s/\s+$//;
  388. ($real_name, $address) = parse_email("$real_name <$address>");
  389. $mailmap->{names}->{$address} = $real_name;
  390. } elsif (/^<([^>]+)>\s*<([^>]+)>$/) {
  391. my $real_address = $1;
  392. my $wrong_address = $2;
  393. $mailmap->{addresses}->{$wrong_address} = $real_address;
  394. } elsif (/^(.+)<([^>]+)>\s*<([^>]+)>$/) {
  395. my $real_name = $1;
  396. my $real_address = $2;
  397. my $wrong_address = $3;
  398. $real_name =~ s/\s+$//;
  399. ($real_name, $real_address) =
  400. parse_email("$real_name <$real_address>");
  401. $mailmap->{names}->{$wrong_address} = $real_name;
  402. $mailmap->{addresses}->{$wrong_address} = $real_address;
  403. } elsif (/^(.+)<([^>]+)>\s*(.+)\s*<([^>]+)>$/) {
  404. my $real_name = $1;
  405. my $real_address = $2;
  406. my $wrong_name = $3;
  407. my $wrong_address = $4;
  408. $real_name =~ s/\s+$//;
  409. ($real_name, $real_address) =
  410. parse_email("$real_name <$real_address>");
  411. $wrong_name =~ s/\s+$//;
  412. ($wrong_name, $wrong_address) =
  413. parse_email("$wrong_name <$wrong_address>");
  414. my $wrong_email = format_email($wrong_name, $wrong_address, 1);
  415. $mailmap->{names}->{$wrong_email} = $real_name;
  416. $mailmap->{addresses}->{$wrong_email} = $real_address;
  417. }
  418. }
  419. close($mailmap_file);
  420. }
  421. ## use the filenames on the command line or find the filenames in the patchfiles
  422. my @files = ();
  423. my @range = ();
  424. my @keyword_tvi = ();
  425. my @file_emails = ();
  426. if (!@ARGV) {
  427. push(@ARGV, "&STDIN");
  428. }
  429. foreach my $file (@ARGV) {
  430. if ($file ne "&STDIN") {
  431. ##if $file is a directory and it lacks a trailing slash, add one
  432. if ((-d $file)) {
  433. $file =~ s@([^/])$@$1/@;
  434. } elsif (!(-f $file)) {
  435. die "$P: file '${file}' not found\n";
  436. }
  437. }
  438. if ($from_filename || ($file ne "&STDIN" && vcs_file_exists($file))) {
  439. $file =~ s/^\Q${cur_path}\E//; #strip any absolute path
  440. $file =~ s/^\Q${lk_path}\E//; #or the path to the lk tree
  441. push(@files, $file);
  442. if ($file ne "MAINTAINERS" && -f $file && ($keywords || $file_emails)) {
  443. open(my $f, '<', $file)
  444. or die "$P: Can't open $file: $!\n";
  445. my $text = do { local($/) ; <$f> };
  446. close($f);
  447. if ($keywords) {
  448. foreach my $line (keys %keyword_hash) {
  449. if ($text =~ m/$keyword_hash{$line}/x) {
  450. push(@keyword_tvi, $line);
  451. }
  452. }
  453. }
  454. if ($file_emails) {
  455. 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;
  456. push(@file_emails, clean_file_emails(@poss_addr));
  457. }
  458. }
  459. } else {
  460. my $file_cnt = @files;
  461. my $lastfile;
  462. open(my $patch, "< $file")
  463. or die "$P: Can't open $file: $!\n";
  464. # We can check arbitrary information before the patch
  465. # like the commit message, mail headers, etc...
  466. # This allows us to match arbitrary keywords against any part
  467. # of a git format-patch generated file (subject tags, etc...)
  468. my $patch_prefix = ""; #Parsing the intro
  469. while (<$patch>) {
  470. my $patch_line = $_;
  471. if (m/^\+\+\+\s+(\S+)/ or m/^---\s+(\S+)/) {
  472. my $filename = $1;
  473. $filename =~ s@^[^/]*/@@;
  474. $filename =~ s@\n@@;
  475. $lastfile = $filename;
  476. push(@files, $filename);
  477. $patch_prefix = "^[+-].*"; #Now parsing the actual patch
  478. } elsif (m/^\@\@ -(\d+),(\d+)/) {
  479. if ($email_git_blame) {
  480. push(@range, "$lastfile:$1:$2");
  481. }
  482. } elsif ($keywords) {
  483. foreach my $line (keys %keyword_hash) {
  484. if ($patch_line =~ m/${patch_prefix}$keyword_hash{$line}/x) {
  485. push(@keyword_tvi, $line);
  486. }
  487. }
  488. }
  489. }
  490. close($patch);
  491. if ($file_cnt == @files) {
  492. warn "$P: file '${file}' doesn't appear to be a patch. "
  493. . "Add -f to options?\n";
  494. }
  495. @files = sort_and_uniq(@files);
  496. }
  497. }
  498. @file_emails = uniq(@file_emails);
  499. my %email_hash_name;
  500. my %email_hash_address;
  501. my @email_to = ();
  502. my %hash_list_to;
  503. my @list_to = ();
  504. my @scm = ();
  505. my @web = ();
  506. my @subsystem = ();
  507. my @status = ();
  508. my %deduplicate_name_hash = ();
  509. my %deduplicate_address_hash = ();
  510. my @maintainers = get_maintainers();
  511. if (@maintainers) {
  512. @maintainers = merge_email(@maintainers);
  513. output(@maintainers);
  514. }
  515. if ($scm) {
  516. @scm = uniq(@scm);
  517. output(@scm);
  518. }
  519. if ($status) {
  520. @status = uniq(@status);
  521. output(@status);
  522. }
  523. if ($subsystem) {
  524. @subsystem = uniq(@subsystem);
  525. output(@subsystem);
  526. }
  527. if ($web) {
  528. @web = uniq(@web);
  529. output(@web);
  530. }
  531. exit($exit);
  532. sub self_test {
  533. my @lsfiles = ();
  534. my @good_links = ();
  535. my @bad_links = ();
  536. my @section_headers = ();
  537. my $index = 0;
  538. @lsfiles = vcs_list_files($lk_path);
  539. for my $x (@self_test_info) {
  540. $index++;
  541. ## Section header duplication and missing section content
  542. if (($self_test eq "" || $self_test =~ /\bsections\b/) &&
  543. $x->{line} =~ /^\S[^:]/ &&
  544. defined $self_test_info[$index] &&
  545. $self_test_info[$index]->{line} =~ /^([A-Z]):\s*\S/) {
  546. my $has_S = 0;
  547. my $has_F = 0;
  548. my $has_ML = 0;
  549. my $status = "";
  550. if (grep(m@^\Q$x->{line}\E@, @section_headers)) {
  551. print("$x->{file}:$x->{linenr}: warning: duplicate section header\t$x->{line}\n");
  552. } else {
  553. push(@section_headers, $x->{line});
  554. }
  555. my $nextline = $index;
  556. while (defined $self_test_info[$nextline] &&
  557. $self_test_info[$nextline]->{line} =~ /^([A-Z]):\s*(\S.*)/) {
  558. my $type = $1;
  559. my $value = $2;
  560. if ($type eq "S") {
  561. $has_S = 1;
  562. $status = $value;
  563. } elsif ($type eq "F" || $type eq "N") {
  564. $has_F = 1;
  565. } elsif ($type eq "M" || $type eq "R" || $type eq "L") {
  566. $has_ML = 1;
  567. }
  568. $nextline++;
  569. }
  570. if (!$has_ML && $status !~ /orphan|obsolete/i) {
  571. print("$x->{file}:$x->{linenr}: warning: section without email address\t$x->{line}\n");
  572. }
  573. if (!$has_S) {
  574. print("$x->{file}:$x->{linenr}: warning: section without status \t$x->{line}\n");
  575. }
  576. if (!$has_F) {
  577. print("$x->{file}:$x->{linenr}: warning: section without file pattern\t$x->{line}\n");
  578. }
  579. }
  580. next if ($x->{line} !~ /^([A-Z]):\s*(.*)/);
  581. my $type = $1;
  582. my $value = $2;
  583. ## Filename pattern matching
  584. if (($type eq "F" || $type eq "X") &&
  585. ($self_test eq "" || $self_test =~ /\bpatterns\b/)) {
  586. $value =~ s@\.@\\\.@g; ##Convert . to \.
  587. $value =~ s/\*/\.\*/g; ##Convert * to .*
  588. $value =~ s/\?/\./g; ##Convert ? to .
  589. ##if pattern is a directory and it lacks a trailing slash, add one
  590. if ((-d $value)) {
  591. $value =~ s@([^/])$@$1/@;
  592. }
  593. if (!grep(m@^$value@, @lsfiles)) {
  594. print("$x->{file}:$x->{linenr}: warning: no file matches\t$x->{line}\n");
  595. }
  596. ## Link reachability
  597. } elsif (($type eq "W" || $type eq "Q" || $type eq "B") &&
  598. $value =~ /^https?:/ &&
  599. ($self_test eq "" || $self_test =~ /\blinks\b/)) {
  600. next if (grep(m@^\Q$value\E$@, @good_links));
  601. my $isbad = 0;
  602. if (grep(m@^\Q$value\E$@, @bad_links)) {
  603. $isbad = 1;
  604. } else {
  605. my $output = `wget --spider -q --no-check-certificate --timeout 10 --tries 1 $value`;
  606. if ($? == 0) {
  607. push(@good_links, $value);
  608. } else {
  609. push(@bad_links, $value);
  610. $isbad = 1;
  611. }
  612. }
  613. if ($isbad) {
  614. print("$x->{file}:$x->{linenr}: warning: possible bad link\t$x->{line}\n");
  615. }
  616. ## SCM reachability
  617. } elsif ($type eq "T" &&
  618. ($self_test eq "" || $self_test =~ /\bscm\b/)) {
  619. next if (grep(m@^\Q$value\E$@, @good_links));
  620. my $isbad = 0;
  621. if (grep(m@^\Q$value\E$@, @bad_links)) {
  622. $isbad = 1;
  623. } elsif ($value !~ /^(?:git|quilt|hg)\s+\S/) {
  624. print("$x->{file}:$x->{linenr}: warning: malformed entry\t$x->{line}\n");
  625. } elsif ($value =~ /^git\s+(\S+)(\s+([^\(]+\S+))?/) {
  626. my $url = $1;
  627. my $branch = "";
  628. $branch = $3 if $3;
  629. my $output = `git ls-remote --exit-code -h "$url" $branch > /dev/null 2>&1`;
  630. if ($? == 0) {
  631. push(@good_links, $value);
  632. } else {
  633. push(@bad_links, $value);
  634. $isbad = 1;
  635. }
  636. } elsif ($value =~ /^(?:quilt|hg)\s+(https?:\S+)/) {
  637. my $url = $1;
  638. my $output = `wget --spider -q --no-check-certificate --timeout 10 --tries 1 $url`;
  639. if ($? == 0) {
  640. push(@good_links, $value);
  641. } else {
  642. push(@bad_links, $value);
  643. $isbad = 1;
  644. }
  645. }
  646. if ($isbad) {
  647. print("$x->{file}:$x->{linenr}: warning: possible bad link\t$x->{line}\n");
  648. }
  649. }
  650. }
  651. }
  652. sub ignore_email_address {
  653. my ($address) = @_;
  654. foreach my $ignore (@ignore_emails) {
  655. return 1 if ($ignore eq $address);
  656. }
  657. return 0;
  658. }
  659. sub range_is_maintained {
  660. my ($start, $end) = @_;
  661. for (my $i = $start; $i < $end; $i++) {
  662. my $line = $typevalue[$i];
  663. if ($line =~ m/^([A-Z]):\s*(.*)/) {
  664. my $type = $1;
  665. my $value = $2;
  666. if ($type eq 'S') {
  667. if ($value =~ /(maintain|support)/i) {
  668. return 1;
  669. }
  670. }
  671. }
  672. }
  673. return 0;
  674. }
  675. sub range_has_maintainer {
  676. my ($start, $end) = @_;
  677. for (my $i = $start; $i < $end; $i++) {
  678. my $line = $typevalue[$i];
  679. if ($line =~ m/^([A-Z]):\s*(.*)/) {
  680. my $type = $1;
  681. my $value = $2;
  682. if ($type eq 'M') {
  683. return 1;
  684. }
  685. }
  686. }
  687. return 0;
  688. }
  689. sub get_maintainers {
  690. %email_hash_name = ();
  691. %email_hash_address = ();
  692. %commit_author_hash = ();
  693. %commit_signer_hash = ();
  694. @email_to = ();
  695. %hash_list_to = ();
  696. @list_to = ();
  697. @scm = ();
  698. @web = ();
  699. @subsystem = ();
  700. @status = ();
  701. %deduplicate_name_hash = ();
  702. %deduplicate_address_hash = ();
  703. if ($email_git_all_signature_types) {
  704. $signature_pattern = "(.+?)[Bb][Yy]:";
  705. } else {
  706. $signature_pattern = "\(" . join("|", @signature_tags) . "\)";
  707. }
  708. # Find responsible parties
  709. my %exact_pattern_match_hash = ();
  710. foreach my $file (@files) {
  711. my %hash;
  712. my $tvi = find_first_section();
  713. while ($tvi < @typevalue) {
  714. my $start = find_starting_index($tvi);
  715. my $end = find_ending_index($tvi);
  716. my $exclude = 0;
  717. my $i;
  718. #Do not match excluded file patterns
  719. for ($i = $start; $i < $end; $i++) {
  720. my $line = $typevalue[$i];
  721. if ($line =~ m/^([A-Z]):\s*(.*)/) {
  722. my $type = $1;
  723. my $value = $2;
  724. if ($type eq 'X') {
  725. if (file_match_pattern($file, $value)) {
  726. $exclude = 1;
  727. last;
  728. }
  729. }
  730. }
  731. }
  732. if (!$exclude) {
  733. for ($i = $start; $i < $end; $i++) {
  734. my $line = $typevalue[$i];
  735. if ($line =~ m/^([A-Z]):\s*(.*)/) {
  736. my $type = $1;
  737. my $value = $2;
  738. if ($type eq 'F') {
  739. if (file_match_pattern($file, $value)) {
  740. my $value_pd = ($value =~ tr@/@@);
  741. my $file_pd = ($file =~ tr@/@@);
  742. $value_pd++ if (substr($value,-1,1) ne "/");
  743. $value_pd = -1 if ($value =~ /^\.\*/);
  744. if ($value_pd >= $file_pd &&
  745. range_is_maintained($start, $end) &&
  746. range_has_maintainer($start, $end)) {
  747. $exact_pattern_match_hash{$file} = 1;
  748. }
  749. if ($pattern_depth == 0 ||
  750. (($file_pd - $value_pd) < $pattern_depth)) {
  751. $hash{$tvi} = $value_pd;
  752. }
  753. }
  754. } elsif ($type eq 'N') {
  755. if ($file =~ m/$value/x) {
  756. $hash{$tvi} = 0;
  757. }
  758. }
  759. }
  760. }
  761. }
  762. $tvi = $end + 1;
  763. }
  764. foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
  765. add_categories($line);
  766. if ($sections) {
  767. my $i;
  768. my $start = find_starting_index($line);
  769. my $end = find_ending_index($line);
  770. for ($i = $start; $i < $end; $i++) {
  771. my $line = $typevalue[$i];
  772. if ($line =~ /^[FX]:/) { ##Restore file patterns
  773. $line =~ s/([^\\])\.([^\*])/$1\?$2/g;
  774. $line =~ s/([^\\])\.$/$1\?/g; ##Convert . back to ?
  775. $line =~ s/\\\./\./g; ##Convert \. to .
  776. $line =~ s/\.\*/\*/g; ##Convert .* to *
  777. }
  778. my $count = $line =~ s/^([A-Z]):/$1:\t/g;
  779. if ($letters eq "" || (!$count || $letters =~ /$1/i)) {
  780. print("$line\n");
  781. }
  782. }
  783. print("\n");
  784. }
  785. }
  786. }
  787. if ($keywords) {
  788. @keyword_tvi = sort_and_uniq(@keyword_tvi);
  789. foreach my $line (@keyword_tvi) {
  790. add_categories($line);
  791. }
  792. }
  793. foreach my $email (@email_to, @list_to) {
  794. $email->[0] = deduplicate_email($email->[0]);
  795. }
  796. foreach my $file (@files) {
  797. if ($email &&
  798. ($email_git || ($email_git_fallback &&
  799. !$exact_pattern_match_hash{$file}))) {
  800. vcs_file_signoffs($file);
  801. }
  802. if ($email && $email_git_blame) {
  803. vcs_file_blame($file);
  804. }
  805. }
  806. if ($email) {
  807. foreach my $chief (@penguin_chief) {
  808. if ($chief =~ m/^(.*):(.*)/) {
  809. my $email_address;
  810. $email_address = format_email($1, $2, $email_usename);
  811. if ($email_git_penguin_chiefs) {
  812. push(@email_to, [$email_address, 'chief penguin']);
  813. } else {
  814. @email_to = grep($_->[0] !~ /${email_address}/, @email_to);
  815. }
  816. }
  817. }
  818. foreach my $email (@file_emails) {
  819. my ($name, $address) = parse_email($email);
  820. my $tmp_email = format_email($name, $address, $email_usename);
  821. push_email_address($tmp_email, '');
  822. add_role($tmp_email, 'in file');
  823. }
  824. }
  825. my @to = ();
  826. if ($email || $email_list) {
  827. if ($email) {
  828. @to = (@to, @email_to);
  829. }
  830. if ($email_list) {
  831. @to = (@to, @list_to);
  832. }
  833. }
  834. if ($interactive) {
  835. @to = interactive_get_maintainers(\@to);
  836. }
  837. return @to;
  838. }
  839. sub file_match_pattern {
  840. my ($file, $pattern) = @_;
  841. if (substr($pattern, -1) eq "/") {
  842. if ($file =~ m@^$pattern@) {
  843. return 1;
  844. }
  845. } else {
  846. if ($file =~ m@^$pattern@) {
  847. my $s1 = ($file =~ tr@/@@);
  848. my $s2 = ($pattern =~ tr@/@@);
  849. if ($s1 == $s2) {
  850. return 1;
  851. }
  852. }
  853. }
  854. return 0;
  855. }
  856. sub usage {
  857. print <<EOT;
  858. usage: $P [options] patchfile
  859. $P [options] -f file|directory
  860. version: $V
  861. MAINTAINER field selection options:
  862. --email => print email address(es) if any
  863. --git => include recent git \*-by: signers
  864. --git-all-signature-types => include signers regardless of signature type
  865. or use only ${signature_pattern} signers (default: $email_git_all_signature_types)
  866. --git-fallback => use git when no exact MAINTAINERS pattern (default: $email_git_fallback)
  867. --git-chief-penguins => include ${penguin_chiefs}
  868. --git-min-signatures => number of signatures required (default: $email_git_min_signatures)
  869. --git-max-maintainers => maximum maintainers to add (default: $email_git_max_maintainers)
  870. --git-min-percent => minimum percentage of commits required (default: $email_git_min_percent)
  871. --git-blame => use git blame to find modified commits for patch or file
  872. --git-blame-signatures => when used with --git-blame, also include all commit signers
  873. --git-since => git history to use (default: $email_git_since)
  874. --hg-since => hg history to use (default: $email_hg_since)
  875. --interactive => display a menu (mostly useful if used with the --git option)
  876. --m => include maintainer(s) if any
  877. --r => include reviewer(s) if any
  878. --n => include name 'Full Name <addr\@domain.tld>'
  879. --l => include list(s) if any
  880. --s => include subscriber only list(s) if any
  881. --remove-duplicates => minimize duplicate email names/addresses
  882. --roles => show roles (status:subsystem, git-signer, list, etc...)
  883. --rolestats => show roles and statistics (commits/total_commits, %)
  884. --file-emails => add email addresses found in -f file (default: 0 (off))
  885. --scm => print SCM tree(s) if any
  886. --status => print status if any
  887. --subsystem => print subsystem name if any
  888. --web => print website(s) if any
  889. Output type options:
  890. --separator [, ] => separator for multiple entries on 1 line
  891. using --separator also sets --nomultiline if --separator is not [, ]
  892. --multiline => print 1 entry per line
  893. Other options:
  894. --pattern-depth => Number of pattern directory traversals (default: 0 (all))
  895. --keywords => scan patch for keywords (default: $keywords)
  896. --sections => print all of the subsystem sections with pattern matches
  897. --letters => print all matching 'letter' types from all matching sections
  898. --mailmap => use .mailmap file (default: $email_use_mailmap)
  899. --self-test => show potential issues with MAINTAINERS file content
  900. --version => show version
  901. --help => show this help information
  902. Default options:
  903. [--email --nogit --git-fallback --m --r --n --l --multiline --pattern-depth=0
  904. --remove-duplicates --rolestats]
  905. Notes:
  906. Using "-f directory" may give unexpected results:
  907. Used with "--git", git signators for _all_ files in and below
  908. directory are examined as git recurses directories.
  909. Any specified X: (exclude) pattern matches are _not_ ignored.
  910. Used with "--nogit", directory is used as a pattern match,
  911. no individual file within the directory or subdirectory
  912. is matched.
  913. Used with "--git-blame", does not iterate all files in directory
  914. Using "--git-blame" is slow and may add old committers and authors
  915. that are no longer active maintainers to the output.
  916. Using "--roles" or "--rolestats" with git send-email --cc-cmd or any
  917. other automated tools that expect only ["name"] <email address>
  918. may not work because of additional output after <email address>.
  919. Using "--rolestats" and "--git-blame" shows the #/total=% commits,
  920. not the percentage of the entire file authored. # of commits is
  921. not a good measure of amount of code authored. 1 major commit may
  922. contain a thousand lines, 5 trivial commits may modify a single line.
  923. If git is not installed, but mercurial (hg) is installed and an .hg
  924. repository exists, the following options apply to mercurial:
  925. --git,
  926. --git-min-signatures, --git-max-maintainers, --git-min-percent, and
  927. --git-blame
  928. Use --hg-since not --git-since to control date selection
  929. File ".get_maintainer.conf", if it exists in the linux kernel source root
  930. directory, can change whatever get_maintainer defaults are desired.
  931. Entries in this file can be any command line argument.
  932. This file is prepended to any additional command line arguments.
  933. Multiple lines and # comments are allowed.
  934. Most options have both positive and negative forms.
  935. The negative forms for --<foo> are --no<foo> and --no-<foo>.
  936. EOT
  937. }
  938. sub top_of_kernel_tree {
  939. my ($lk_path) = @_;
  940. if ($lk_path ne "" && substr($lk_path,length($lk_path)-1,1) ne "/") {
  941. $lk_path .= "/";
  942. }
  943. if ( (-f "${lk_path}Kbuild")
  944. && (-e "${lk_path}MAINTAINERS")
  945. && (-f "${lk_path}Makefile")
  946. && (-f "${lk_path}README")
  947. && (-d "${lk_path}arch")
  948. && (-d "${lk_path}board")
  949. && (-d "${lk_path}common")
  950. && (-d "${lk_path}doc")
  951. && (-d "${lk_path}drivers")
  952. && (-d "${lk_path}dts")
  953. && (-d "${lk_path}fs")
  954. && (-d "${lk_path}lib")
  955. && (-d "${lk_path}include")
  956. && (-d "${lk_path}net")
  957. && (-d "${lk_path}post")
  958. && (-d "${lk_path}scripts")
  959. && (-d "${lk_path}test")
  960. && (-d "${lk_path}tools")) {
  961. return 1;
  962. }
  963. return 0;
  964. }
  965. sub parse_email {
  966. my ($formatted_email) = @_;
  967. my $name = "";
  968. my $address = "";
  969. if ($formatted_email =~ /^([^<]+)<(.+\@.*)>.*$/) {
  970. $name = $1;
  971. $address = $2;
  972. } elsif ($formatted_email =~ /^\s*<(.+\@\S*)>.*$/) {
  973. $address = $1;
  974. } elsif ($formatted_email =~ /^(.+\@\S*).*$/) {
  975. $address = $1;
  976. }
  977. $name =~ s/^\s+|\s+$//g;
  978. $name =~ s/^\"|\"$//g;
  979. $address =~ s/^\s+|\s+$//g;
  980. if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
  981. $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
  982. $name = "\"$name\"";
  983. }
  984. return ($name, $address);
  985. }
  986. sub format_email {
  987. my ($name, $address, $usename) = @_;
  988. my $formatted_email;
  989. $name =~ s/^\s+|\s+$//g;
  990. $name =~ s/^\"|\"$//g;
  991. $address =~ s/^\s+|\s+$//g;
  992. if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
  993. $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
  994. $name = "\"$name\"";
  995. }
  996. if ($usename) {
  997. if ("$name" eq "") {
  998. $formatted_email = "$address";
  999. } else {
  1000. $formatted_email = "$name <$address>";
  1001. }
  1002. } else {
  1003. $formatted_email = $address;
  1004. }
  1005. return $formatted_email;
  1006. }
  1007. sub find_first_section {
  1008. my $index = 0;
  1009. while ($index < @typevalue) {
  1010. my $tv = $typevalue[$index];
  1011. if (($tv =~ m/^([A-Z]):\s*(.*)/)) {
  1012. last;
  1013. }
  1014. $index++;
  1015. }
  1016. return $index;
  1017. }
  1018. sub find_starting_index {
  1019. my ($index) = @_;
  1020. while ($index > 0) {
  1021. my $tv = $typevalue[$index];
  1022. if (!($tv =~ m/^([A-Z]):\s*(.*)/)) {
  1023. last;
  1024. }
  1025. $index--;
  1026. }
  1027. return $index;
  1028. }
  1029. sub find_ending_index {
  1030. my ($index) = @_;
  1031. while ($index < @typevalue) {
  1032. my $tv = $typevalue[$index];
  1033. if (!($tv =~ m/^([A-Z]):\s*(.*)/)) {
  1034. last;
  1035. }
  1036. $index++;
  1037. }
  1038. return $index;
  1039. }
  1040. sub get_subsystem_name {
  1041. my ($index) = @_;
  1042. my $start = find_starting_index($index);
  1043. my $subsystem = $typevalue[$start];
  1044. if ($output_section_maxlen && length($subsystem) > $output_section_maxlen) {
  1045. $subsystem = substr($subsystem, 0, $output_section_maxlen - 3);
  1046. $subsystem =~ s/\s*$//;
  1047. $subsystem = $subsystem . "...";
  1048. }
  1049. return $subsystem;
  1050. }
  1051. sub get_maintainer_role {
  1052. my ($index) = @_;
  1053. my $i;
  1054. my $start = find_starting_index($index);
  1055. my $end = find_ending_index($index);
  1056. my $role = "unknown";
  1057. my $subsystem = get_subsystem_name($index);
  1058. for ($i = $start + 1; $i < $end; $i++) {
  1059. my $tv = $typevalue[$i];
  1060. if ($tv =~ m/^([A-Z]):\s*(.*)/) {
  1061. my $ptype = $1;
  1062. my $pvalue = $2;
  1063. if ($ptype eq "S") {
  1064. $role = $pvalue;
  1065. }
  1066. }
  1067. }
  1068. $role = lc($role);
  1069. if ($role eq "supported") {
  1070. $role = "supporter";
  1071. } elsif ($role eq "maintained") {
  1072. $role = "maintainer";
  1073. } elsif ($role eq "odd fixes") {
  1074. $role = "odd fixer";
  1075. } elsif ($role eq "orphan") {
  1076. $role = "orphan minder";
  1077. } elsif ($role eq "obsolete") {
  1078. $role = "obsolete minder";
  1079. } elsif ($role eq "buried alive in reporters") {
  1080. $role = "chief penguin";
  1081. }
  1082. return $role . ":" . $subsystem;
  1083. }
  1084. sub get_list_role {
  1085. my ($index) = @_;
  1086. my $subsystem = get_subsystem_name($index);
  1087. if ($subsystem eq "THE REST") {
  1088. $subsystem = "";
  1089. }
  1090. return $subsystem;
  1091. }
  1092. sub add_categories {
  1093. my ($index) = @_;
  1094. my $i;
  1095. my $start = find_starting_index($index);
  1096. my $end = find_ending_index($index);
  1097. push(@subsystem, $typevalue[$start]);
  1098. for ($i = $start + 1; $i < $end; $i++) {
  1099. my $tv = $typevalue[$i];
  1100. if ($tv =~ m/^([A-Z]):\s*(.*)/) {
  1101. my $ptype = $1;
  1102. my $pvalue = $2;
  1103. if ($ptype eq "L") {
  1104. my $list_address = $pvalue;
  1105. my $list_additional = "";
  1106. my $list_role = get_list_role($i);
  1107. if ($list_role ne "") {
  1108. $list_role = ":" . $list_role;
  1109. }
  1110. if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
  1111. $list_address = $1;
  1112. $list_additional = $2;
  1113. }
  1114. if ($list_additional =~ m/subscribers-only/) {
  1115. if ($email_subscriber_list) {
  1116. if (!$hash_list_to{lc($list_address)}) {
  1117. $hash_list_to{lc($list_address)} = 1;
  1118. push(@list_to, [$list_address,
  1119. "subscriber list${list_role}"]);
  1120. }
  1121. }
  1122. } else {
  1123. if ($email_list) {
  1124. if (!$hash_list_to{lc($list_address)}) {
  1125. $hash_list_to{lc($list_address)} = 1;
  1126. if ($list_additional =~ m/moderated/) {
  1127. push(@list_to, [$list_address,
  1128. "moderated list${list_role}"]);
  1129. } else {
  1130. push(@list_to, [$list_address,
  1131. "open list${list_role}"]);
  1132. }
  1133. }
  1134. }
  1135. }
  1136. } elsif ($ptype eq "M") {
  1137. my ($name, $address) = parse_email($pvalue);
  1138. if ($name eq "") {
  1139. if ($i > 0) {
  1140. my $tv = $typevalue[$i - 1];
  1141. if ($tv =~ m/^([A-Z]):\s*(.*)/) {
  1142. if ($1 eq "P") {
  1143. $name = $2;
  1144. $pvalue = format_email($name, $address, $email_usename);
  1145. }
  1146. }
  1147. }
  1148. }
  1149. if ($email_maintainer) {
  1150. my $role = get_maintainer_role($i);
  1151. push_email_addresses($pvalue, $role);
  1152. }
  1153. } elsif ($ptype eq "R") {
  1154. my ($name, $address) = parse_email($pvalue);
  1155. if ($name eq "") {
  1156. if ($i > 0) {
  1157. my $tv = $typevalue[$i - 1];
  1158. if ($tv =~ m/^([A-Z]):\s*(.*)/) {
  1159. if ($1 eq "P") {
  1160. $name = $2;
  1161. $pvalue = format_email($name, $address, $email_usename);
  1162. }
  1163. }
  1164. }
  1165. }
  1166. if ($email_reviewer) {
  1167. my $subsystem = get_subsystem_name($i);
  1168. push_email_addresses($pvalue, "reviewer:$subsystem");
  1169. }
  1170. } elsif ($ptype eq "T") {
  1171. push(@scm, $pvalue);
  1172. } elsif ($ptype eq "W") {
  1173. push(@web, $pvalue);
  1174. } elsif ($ptype eq "S") {
  1175. push(@status, $pvalue);
  1176. }
  1177. }
  1178. }
  1179. }
  1180. sub email_inuse {
  1181. my ($name, $address) = @_;
  1182. return 1 if (($name eq "") && ($address eq ""));
  1183. return 1 if (($name ne "") && exists($email_hash_name{lc($name)}));
  1184. return 1 if (($address ne "") && exists($email_hash_address{lc($address)}));
  1185. return 0;
  1186. }
  1187. sub push_email_address {
  1188. my ($line, $role) = @_;
  1189. my ($name, $address) = parse_email($line);
  1190. if ($address eq "") {
  1191. return 0;
  1192. }
  1193. if (!$email_remove_duplicates) {
  1194. push(@email_to, [format_email($name, $address, $email_usename), $role]);
  1195. } elsif (!email_inuse($name, $address)) {
  1196. push(@email_to, [format_email($name, $address, $email_usename), $role]);
  1197. $email_hash_name{lc($name)}++ if ($name ne "");
  1198. $email_hash_address{lc($address)}++;
  1199. }
  1200. return 1;
  1201. }
  1202. sub push_email_addresses {
  1203. my ($address, $role) = @_;
  1204. my @address_list = ();
  1205. if (rfc822_valid($address)) {
  1206. push_email_address($address, $role);
  1207. } elsif (@address_list = rfc822_validlist($address)) {
  1208. my $array_count = shift(@address_list);
  1209. while (my $entry = shift(@address_list)) {
  1210. push_email_address($entry, $role);
  1211. }
  1212. } else {
  1213. if (!push_email_address($address, $role)) {
  1214. warn("Invalid MAINTAINERS address: '" . $address . "'\n");
  1215. }
  1216. }
  1217. }
  1218. sub add_role {
  1219. my ($line, $role) = @_;
  1220. my ($name, $address) = parse_email($line);
  1221. my $email = format_email($name, $address, $email_usename);
  1222. foreach my $entry (@email_to) {
  1223. if ($email_remove_duplicates) {
  1224. my ($entry_name, $entry_address) = parse_email($entry->[0]);
  1225. if (($name eq $entry_name || $address eq $entry_address)
  1226. && ($role eq "" || !($entry->[1] =~ m/$role/))
  1227. ) {
  1228. if ($entry->[1] eq "") {
  1229. $entry->[1] = "$role";
  1230. } else {
  1231. $entry->[1] = "$entry->[1],$role";
  1232. }
  1233. }
  1234. } else {
  1235. if ($email eq $entry->[0]
  1236. && ($role eq "" || !($entry->[1] =~ m/$role/))
  1237. ) {
  1238. if ($entry->[1] eq "") {
  1239. $entry->[1] = "$role";
  1240. } else {
  1241. $entry->[1] = "$entry->[1],$role";
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. sub which {
  1248. my ($bin) = @_;
  1249. foreach my $path (split(/:/, $ENV{PATH})) {
  1250. if (-e "$path/$bin") {
  1251. return "$path/$bin";
  1252. }
  1253. }
  1254. return "";
  1255. }
  1256. sub which_conf {
  1257. my ($conf) = @_;
  1258. foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
  1259. if (-e "$path/$conf") {
  1260. return "$path/$conf";
  1261. }
  1262. }
  1263. return "";
  1264. }
  1265. sub mailmap_email {
  1266. my ($line) = @_;
  1267. my ($name, $address) = parse_email($line);
  1268. my $email = format_email($name, $address, 1);
  1269. my $real_name = $name;
  1270. my $real_address = $address;
  1271. if (exists $mailmap->{names}->{$email} ||
  1272. exists $mailmap->{addresses}->{$email}) {
  1273. if (exists $mailmap->{names}->{$email}) {
  1274. $real_name = $mailmap->{names}->{$email};
  1275. }
  1276. if (exists $mailmap->{addresses}->{$email}) {
  1277. $real_address = $mailmap->{addresses}->{$email};
  1278. }
  1279. } else {
  1280. if (exists $mailmap->{names}->{$address}) {
  1281. $real_name = $mailmap->{names}->{$address};
  1282. }
  1283. if (exists $mailmap->{addresses}->{$address}) {
  1284. $real_address = $mailmap->{addresses}->{$address};
  1285. }
  1286. }
  1287. return format_email($real_name, $real_address, 1);
  1288. }
  1289. sub mailmap {
  1290. my (@addresses) = @_;
  1291. my @mapped_emails = ();
  1292. foreach my $line (@addresses) {
  1293. push(@mapped_emails, mailmap_email($line));
  1294. }
  1295. merge_by_realname(@mapped_emails) if ($email_use_mailmap);
  1296. return @mapped_emails;
  1297. }
  1298. sub merge_by_realname {
  1299. my %address_map;
  1300. my (@emails) = @_;
  1301. foreach my $email (@emails) {
  1302. my ($name, $address) = parse_email($email);
  1303. if (exists $address_map{$name}) {
  1304. $address = $address_map{$name};
  1305. $email = format_email($name, $address, 1);
  1306. } else {
  1307. $address_map{$name} = $address;
  1308. }
  1309. }
  1310. }
  1311. sub git_execute_cmd {
  1312. my ($cmd) = @_;
  1313. my @lines = ();
  1314. my $output = `$cmd`;
  1315. $output =~ s/^\s*//gm;
  1316. @lines = split("\n", $output);
  1317. return @lines;
  1318. }
  1319. sub hg_execute_cmd {
  1320. my ($cmd) = @_;
  1321. my @lines = ();
  1322. my $output = `$cmd`;
  1323. @lines = split("\n", $output);
  1324. return @lines;
  1325. }
  1326. sub extract_formatted_signatures {
  1327. my (@signature_lines) = @_;
  1328. my @type = @signature_lines;
  1329. s/\s*(.*):.*/$1/ for (@type);
  1330. # cut -f2- -d":"
  1331. s/\s*.*:\s*(.+)\s*/$1/ for (@signature_lines);
  1332. ## Reformat email addresses (with names) to avoid badly written signatures
  1333. foreach my $signer (@signature_lines) {
  1334. $signer = deduplicate_email($signer);
  1335. }
  1336. return (\@type, \@signature_lines);
  1337. }
  1338. sub vcs_find_signers {
  1339. my ($cmd, $file) = @_;
  1340. my $commits;
  1341. my @lines = ();
  1342. my @signatures = ();
  1343. my @authors = ();
  1344. my @stats = ();
  1345. @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
  1346. my $pattern = $VCS_cmds{"commit_pattern"};
  1347. my $author_pattern = $VCS_cmds{"author_pattern"};
  1348. my $stat_pattern = $VCS_cmds{"stat_pattern"};
  1349. $stat_pattern =~ s/(\$\w+)/$1/eeg; #interpolate $stat_pattern
  1350. $commits = grep(/$pattern/, @lines); # of commits
  1351. @authors = grep(/$author_pattern/, @lines);
  1352. @signatures = grep(/^[ \t]*${signature_pattern}.*\@.*$/, @lines);
  1353. @stats = grep(/$stat_pattern/, @lines);
  1354. # print("stats: <@stats>\n");
  1355. return (0, \@signatures, \@authors, \@stats) if !@signatures;
  1356. save_commits_by_author(@lines) if ($interactive);
  1357. save_commits_by_signer(@lines) if ($interactive);
  1358. if (!$email_git_penguin_chiefs) {
  1359. @signatures = grep(!/${penguin_chiefs}/i, @signatures);
  1360. }
  1361. my ($author_ref, $authors_ref) = extract_formatted_signatures(@authors);
  1362. my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
  1363. return ($commits, $signers_ref, $authors_ref, \@stats);
  1364. }
  1365. sub vcs_find_author {
  1366. my ($cmd) = @_;
  1367. my @lines = ();
  1368. @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
  1369. if (!$email_git_penguin_chiefs) {
  1370. @lines = grep(!/${penguin_chiefs}/i, @lines);
  1371. }
  1372. return @lines if !@lines;
  1373. my @authors = ();
  1374. foreach my $line (@lines) {
  1375. if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
  1376. my $author = $1;
  1377. my ($name, $address) = parse_email($author);
  1378. $author = format_email($name, $address, 1);
  1379. push(@authors, $author);
  1380. }
  1381. }
  1382. save_commits_by_author(@lines) if ($interactive);
  1383. save_commits_by_signer(@lines) if ($interactive);
  1384. return @authors;
  1385. }
  1386. sub vcs_save_commits {
  1387. my ($cmd) = @_;
  1388. my @lines = ();
  1389. my @commits = ();
  1390. @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
  1391. foreach my $line (@lines) {
  1392. if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) {
  1393. push(@commits, $1);
  1394. }
  1395. }
  1396. return @commits;
  1397. }
  1398. sub vcs_blame {
  1399. my ($file) = @_;
  1400. my $cmd;
  1401. my @commits = ();
  1402. return @commits if (!(-f $file));
  1403. if (@range && $VCS_cmds{"blame_range_cmd"} eq "") {
  1404. my @all_commits = ();
  1405. $cmd = $VCS_cmds{"blame_file_cmd"};
  1406. $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
  1407. @all_commits = vcs_save_commits($cmd);
  1408. foreach my $file_range_diff (@range) {
  1409. next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
  1410. my $diff_file = $1;
  1411. my $diff_start = $2;
  1412. my $diff_length = $3;
  1413. next if ("$file" ne "$diff_file");
  1414. for (my $i = $diff_start; $i < $diff_start + $diff_length; $i++) {
  1415. push(@commits, $all_commits[$i]);
  1416. }
  1417. }
  1418. } elsif (@range) {
  1419. foreach my $file_range_diff (@range) {
  1420. next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
  1421. my $diff_file = $1;
  1422. my $diff_start = $2;
  1423. my $diff_length = $3;
  1424. next if ("$file" ne "$diff_file");
  1425. $cmd = $VCS_cmds{"blame_range_cmd"};
  1426. $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
  1427. push(@commits, vcs_save_commits($cmd));
  1428. }
  1429. } else {
  1430. $cmd = $VCS_cmds{"blame_file_cmd"};
  1431. $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
  1432. @commits = vcs_save_commits($cmd);
  1433. }
  1434. foreach my $commit (@commits) {
  1435. $commit =~ s/^\^//g;
  1436. }
  1437. return @commits;
  1438. }
  1439. my $printed_novcs = 0;
  1440. sub vcs_exists {
  1441. %VCS_cmds = %VCS_cmds_git;
  1442. return 1 if eval $VCS_cmds{"available"};
  1443. %VCS_cmds = %VCS_cmds_hg;
  1444. return 2 if eval $VCS_cmds{"available"};
  1445. %VCS_cmds = ();
  1446. if (!$printed_novcs) {
  1447. warn("$P: No supported VCS found. Add --nogit to options?\n");
  1448. warn("Using a git repository produces better results.\n");
  1449. warn("Try Linus Torvalds' latest git repository using:\n");
  1450. warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git\n");
  1451. $printed_novcs = 1;
  1452. }
  1453. return 0;
  1454. }
  1455. sub vcs_is_git {
  1456. vcs_exists();
  1457. return $vcs_used == 1;
  1458. }
  1459. sub vcs_is_hg {
  1460. return $vcs_used == 2;
  1461. }
  1462. sub interactive_get_maintainers {
  1463. my ($list_ref) = @_;
  1464. my @list = @$list_ref;
  1465. vcs_exists();
  1466. my %selected;
  1467. my %authored;
  1468. my %signed;
  1469. my $count = 0;
  1470. my $maintained = 0;
  1471. foreach my $entry (@list) {
  1472. $maintained = 1 if ($entry->[1] =~ /^(maintainer|supporter)/i);
  1473. $selected{$count} = 1;
  1474. $authored{$count} = 0;
  1475. $signed{$count} = 0;
  1476. $count++;
  1477. }
  1478. #menu loop
  1479. my $done = 0;
  1480. my $print_options = 0;
  1481. my $redraw = 1;
  1482. while (!$done) {
  1483. $count = 0;
  1484. if ($redraw) {
  1485. printf STDERR "\n%1s %2s %-65s",
  1486. "*", "#", "email/list and role:stats";
  1487. if ($email_git ||
  1488. ($email_git_fallback && !$maintained) ||
  1489. $email_git_blame) {
  1490. print STDERR "auth sign";
  1491. }
  1492. print STDERR "\n";
  1493. foreach my $entry (@list) {
  1494. my $email = $entry->[0];
  1495. my $role = $entry->[1];
  1496. my $sel = "";
  1497. $sel = "*" if ($selected{$count});
  1498. my $commit_author = $commit_author_hash{$email};
  1499. my $commit_signer = $commit_signer_hash{$email};
  1500. my $authored = 0;
  1501. my $signed = 0;
  1502. $authored++ for (@{$commit_author});
  1503. $signed++ for (@{$commit_signer});
  1504. printf STDERR "%1s %2d %-65s", $sel, $count + 1, $email;
  1505. printf STDERR "%4d %4d", $authored, $signed
  1506. if ($authored > 0 || $signed > 0);
  1507. printf STDERR "\n %s\n", $role;
  1508. if ($authored{$count}) {
  1509. my $commit_author = $commit_author_hash{$email};
  1510. foreach my $ref (@{$commit_author}) {
  1511. print STDERR " Author: @{$ref}[1]\n";
  1512. }
  1513. }
  1514. if ($signed{$count}) {
  1515. my $commit_signer = $commit_signer_hash{$email};
  1516. foreach my $ref (@{$commit_signer}) {
  1517. print STDERR " @{$ref}[2]: @{$ref}[1]\n";
  1518. }
  1519. }
  1520. $count++;
  1521. }
  1522. }
  1523. my $date_ref = \$email_git_since;
  1524. $date_ref = \$email_hg_since if (vcs_is_hg());
  1525. if ($print_options) {
  1526. $print_options = 0;
  1527. if (vcs_exists()) {
  1528. print STDERR <<EOT
  1529. Version Control options:
  1530. g use git history [$email_git]
  1531. gf use git-fallback [$email_git_fallback]
  1532. b use git blame [$email_git_blame]
  1533. bs use blame signatures [$email_git_blame_signatures]
  1534. c# minimum commits [$email_git_min_signatures]
  1535. %# min percent [$email_git_min_percent]
  1536. d# history to use [$$date_ref]
  1537. x# max maintainers [$email_git_max_maintainers]
  1538. t all signature types [$email_git_all_signature_types]
  1539. m use .mailmap [$email_use_mailmap]
  1540. EOT
  1541. }
  1542. print STDERR <<EOT
  1543. Additional options:
  1544. 0 toggle all
  1545. tm toggle maintainers
  1546. tg toggle git entries
  1547. tl toggle open list entries
  1548. ts toggle subscriber list entries
  1549. f emails in file [$file_emails]
  1550. k keywords in file [$keywords]
  1551. r remove duplicates [$email_remove_duplicates]
  1552. p# pattern match depth [$pattern_depth]
  1553. EOT
  1554. }
  1555. print STDERR
  1556. "\n#(toggle), A#(author), S#(signed) *(all), ^(none), O(options), Y(approve): ";
  1557. my $input = <STDIN>;
  1558. chomp($input);
  1559. $redraw = 1;
  1560. my $rerun = 0;
  1561. my @wish = split(/[, ]+/, $input);
  1562. foreach my $nr (@wish) {
  1563. $nr = lc($nr);
  1564. my $sel = substr($nr, 0, 1);
  1565. my $str = substr($nr, 1);
  1566. my $val = 0;
  1567. $val = $1 if $str =~ /^(\d+)$/;
  1568. if ($sel eq "y") {
  1569. $interactive = 0;
  1570. $done = 1;
  1571. $output_rolestats = 0;
  1572. $output_roles = 0;
  1573. last;
  1574. } elsif ($nr =~ /^\d+$/ && $nr > 0 && $nr <= $count) {
  1575. $selected{$nr - 1} = !$selected{$nr - 1};
  1576. } elsif ($sel eq "*" || $sel eq '^') {
  1577. my $toggle = 0;
  1578. $toggle = 1 if ($sel eq '*');
  1579. for (my $i = 0; $i < $count; $i++) {
  1580. $selected{$i} = $toggle;
  1581. }
  1582. } elsif ($sel eq "0") {
  1583. for (my $i = 0; $i < $count; $i++) {
  1584. $selected{$i} = !$selected{$i};
  1585. }
  1586. } elsif ($sel eq "t") {
  1587. if (lc($str) eq "m") {
  1588. for (my $i = 0; $i < $count; $i++) {
  1589. $selected{$i} = !$selected{$i}
  1590. if ($list[$i]->[1] =~ /^(maintainer|supporter)/i);
  1591. }
  1592. } elsif (lc($str) eq "g") {
  1593. for (my $i = 0; $i < $count; $i++) {
  1594. $selected{$i} = !$selected{$i}
  1595. if ($list[$i]->[1] =~ /^(author|commit|signer)/i);
  1596. }
  1597. } elsif (lc($str) eq "l") {
  1598. for (my $i = 0; $i < $count; $i++) {
  1599. $selected{$i} = !$selected{$i}
  1600. if ($list[$i]->[1] =~ /^(open list)/i);
  1601. }
  1602. } elsif (lc($str) eq "s") {
  1603. for (my $i = 0; $i < $count; $i++) {
  1604. $selected{$i} = !$selected{$i}
  1605. if ($list[$i]->[1] =~ /^(subscriber list)/i);
  1606. }
  1607. }
  1608. } elsif ($sel eq "a") {
  1609. if ($val > 0 && $val <= $count) {
  1610. $authored{$val - 1} = !$authored{$val - 1};
  1611. } elsif ($str eq '*' || $str eq '^') {
  1612. my $toggle = 0;
  1613. $toggle = 1 if ($str eq '*');
  1614. for (my $i = 0; $i < $count; $i++) {
  1615. $authored{$i} = $toggle;
  1616. }
  1617. }
  1618. } elsif ($sel eq "s") {
  1619. if ($val > 0 && $val <= $count) {
  1620. $signed{$val - 1} = !$signed{$val - 1};
  1621. } elsif ($str eq '*' || $str eq '^') {
  1622. my $toggle = 0;
  1623. $toggle = 1 if ($str eq '*');
  1624. for (my $i = 0; $i < $count; $i++) {
  1625. $signed{$i} = $toggle;
  1626. }
  1627. }
  1628. } elsif ($sel eq "o") {
  1629. $print_options = 1;
  1630. $redraw = 1;
  1631. } elsif ($sel eq "g") {
  1632. if ($str eq "f") {
  1633. bool_invert(\$email_git_fallback);
  1634. } else {
  1635. bool_invert(\$email_git);
  1636. }
  1637. $rerun = 1;
  1638. } elsif ($sel eq "b") {
  1639. if ($str eq "s") {
  1640. bool_invert(\$email_git_blame_signatures);
  1641. } else {
  1642. bool_invert(\$email_git_blame);
  1643. }
  1644. $rerun = 1;
  1645. } elsif ($sel eq "c") {
  1646. if ($val > 0) {
  1647. $email_git_min_signatures = $val;
  1648. $rerun = 1;
  1649. }
  1650. } elsif ($sel eq "x") {
  1651. if ($val > 0) {
  1652. $email_git_max_maintainers = $val;
  1653. $rerun = 1;
  1654. }
  1655. } elsif ($sel eq "%") {
  1656. if ($str ne "" && $val >= 0) {
  1657. $email_git_min_percent = $val;
  1658. $rerun = 1;
  1659. }
  1660. } elsif ($sel eq "d") {
  1661. if (vcs_is_git()) {
  1662. $email_git_since = $str;
  1663. } elsif (vcs_is_hg()) {
  1664. $email_hg_since = $str;
  1665. }
  1666. $rerun = 1;
  1667. } elsif ($sel eq "t") {
  1668. bool_invert(\$email_git_all_signature_types);
  1669. $rerun = 1;
  1670. } elsif ($sel eq "f") {
  1671. bool_invert(\$file_emails);
  1672. $rerun = 1;
  1673. } elsif ($sel eq "r") {
  1674. bool_invert(\$email_remove_duplicates);
  1675. $rerun = 1;
  1676. } elsif ($sel eq "m") {
  1677. bool_invert(\$email_use_mailmap);
  1678. read_mailmap();
  1679. $rerun = 1;
  1680. } elsif ($sel eq "k") {
  1681. bool_invert(\$keywords);
  1682. $rerun = 1;
  1683. } elsif ($sel eq "p") {
  1684. if ($str ne "" && $val >= 0) {
  1685. $pattern_depth = $val;
  1686. $rerun = 1;
  1687. }
  1688. } elsif ($sel eq "h" || $sel eq "?") {
  1689. print STDERR <<EOT
  1690. Interactive mode allows you to select the various maintainers, submitters,
  1691. commit signers and mailing lists that could be CC'd on a patch.
  1692. Any *'d entry is selected.
  1693. If you have git or hg installed, you can choose to summarize the commit
  1694. history of files in the patch. Also, each line of the current file can
  1695. be matched to its commit author and that commits signers with blame.
  1696. Various knobs exist to control the length of time for active commit
  1697. tracking, the maximum number of commit authors and signers to add,
  1698. and such.
  1699. Enter selections at the prompt until you are satisfied that the selected
  1700. maintainers are appropriate. You may enter multiple selections separated
  1701. by either commas or spaces.
  1702. EOT
  1703. } else {
  1704. print STDERR "invalid option: '$nr'\n";
  1705. $redraw = 0;
  1706. }
  1707. }
  1708. if ($rerun) {
  1709. print STDERR "git-blame can be very slow, please have patience..."
  1710. if ($email_git_blame);
  1711. goto &get_maintainers;
  1712. }
  1713. }
  1714. #drop not selected entries
  1715. $count = 0;
  1716. my @new_emailto = ();
  1717. foreach my $entry (@list) {
  1718. if ($selected{$count}) {
  1719. push(@new_emailto, $list[$count]);
  1720. }
  1721. $count++;
  1722. }
  1723. return @new_emailto;
  1724. }
  1725. sub bool_invert {
  1726. my ($bool_ref) = @_;
  1727. if ($$bool_ref) {
  1728. $$bool_ref = 0;
  1729. } else {
  1730. $$bool_ref = 1;
  1731. }
  1732. }
  1733. sub deduplicate_email {
  1734. my ($email) = @_;
  1735. my $matched = 0;
  1736. my ($name, $address) = parse_email($email);
  1737. $email = format_email($name, $address, 1);
  1738. $email = mailmap_email($email);
  1739. return $email if (!$email_remove_duplicates);
  1740. ($name, $address) = parse_email($email);
  1741. if ($name ne "" && $deduplicate_name_hash{lc($name)}) {
  1742. $name = $deduplicate_name_hash{lc($name)}->[0];
  1743. $address = $deduplicate_name_hash{lc($name)}->[1];
  1744. $matched = 1;
  1745. } elsif ($deduplicate_address_hash{lc($address)}) {
  1746. $name = $deduplicate_address_hash{lc($address)}->[0];
  1747. $address = $deduplicate_address_hash{lc($address)}->[1];
  1748. $matched = 1;
  1749. }
  1750. if (!$matched) {
  1751. $deduplicate_name_hash{lc($name)} = [ $name, $address ];
  1752. $deduplicate_address_hash{lc($address)} = [ $name, $address ];
  1753. }
  1754. $email = format_email($name, $address, 1);
  1755. $email = mailmap_email($email);
  1756. return $email;
  1757. }
  1758. sub save_commits_by_author {
  1759. my (@lines) = @_;
  1760. my @authors = ();
  1761. my @commits = ();
  1762. my @subjects = ();
  1763. foreach my $line (@lines) {
  1764. if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
  1765. my $author = $1;
  1766. $author = deduplicate_email($author);
  1767. push(@authors, $author);
  1768. }
  1769. push(@commits, $1) if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
  1770. push(@subjects, $1) if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
  1771. }
  1772. for (my $i = 0; $i < @authors; $i++) {
  1773. my $exists = 0;
  1774. foreach my $ref(@{$commit_author_hash{$authors[$i]}}) {
  1775. if (@{$ref}[0] eq $commits[$i] &&
  1776. @{$ref}[1] eq $subjects[$i]) {
  1777. $exists = 1;
  1778. last;
  1779. }
  1780. }
  1781. if (!$exists) {
  1782. push(@{$commit_author_hash{$authors[$i]}},
  1783. [ ($commits[$i], $subjects[$i]) ]);
  1784. }
  1785. }
  1786. }
  1787. sub save_commits_by_signer {
  1788. my (@lines) = @_;
  1789. my $commit = "";
  1790. my $subject = "";
  1791. foreach my $line (@lines) {
  1792. $commit = $1 if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
  1793. $subject = $1 if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
  1794. if ($line =~ /^[ \t]*${signature_pattern}.*\@.*$/) {
  1795. my @signatures = ($line);
  1796. my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
  1797. my @types = @$types_ref;
  1798. my @signers = @$signers_ref;
  1799. my $type = $types[0];
  1800. my $signer = $signers[0];
  1801. $signer = deduplicate_email($signer);
  1802. my $exists = 0;
  1803. foreach my $ref(@{$commit_signer_hash{$signer}}) {
  1804. if (@{$ref}[0] eq $commit &&
  1805. @{$ref}[1] eq $subject &&
  1806. @{$ref}[2] eq $type) {
  1807. $exists = 1;
  1808. last;
  1809. }
  1810. }
  1811. if (!$exists) {
  1812. push(@{$commit_signer_hash{$signer}},
  1813. [ ($commit, $subject, $type) ]);
  1814. }
  1815. }
  1816. }
  1817. }
  1818. sub vcs_assign {
  1819. my ($role, $divisor, @lines) = @_;
  1820. my %hash;
  1821. my $count = 0;
  1822. return if (@lines <= 0);
  1823. if ($divisor <= 0) {
  1824. warn("Bad divisor in " . (caller(0))[3] . ": $divisor\n");
  1825. $divisor = 1;
  1826. }
  1827. @lines = mailmap(@lines);
  1828. return if (@lines <= 0);
  1829. @lines = sort(@lines);
  1830. # uniq -c
  1831. $hash{$_}++ for @lines;
  1832. # sort -rn
  1833. foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
  1834. my $sign_offs = $hash{$line};
  1835. my $percent = $sign_offs * 100 / $divisor;
  1836. $percent = 100 if ($percent > 100);
  1837. next if (ignore_email_address($line));
  1838. $count++;
  1839. last if ($sign_offs < $email_git_min_signatures ||
  1840. $count > $email_git_max_maintainers ||
  1841. $percent < $email_git_min_percent);
  1842. push_email_address($line, '');
  1843. if ($output_rolestats) {
  1844. my $fmt_percent = sprintf("%.0f", $percent);
  1845. add_role($line, "$role:$sign_offs/$divisor=$fmt_percent%");
  1846. } else {
  1847. add_role($line, $role);
  1848. }
  1849. }
  1850. }
  1851. sub vcs_file_signoffs {
  1852. my ($file) = @_;
  1853. my $authors_ref;
  1854. my $signers_ref;
  1855. my $stats_ref;
  1856. my @authors = ();
  1857. my @signers = ();
  1858. my @stats = ();
  1859. my $commits;
  1860. $vcs_used = vcs_exists();
  1861. return if (!$vcs_used);
  1862. my $cmd = $VCS_cmds{"find_signers_cmd"};
  1863. $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
  1864. ($commits, $signers_ref, $authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
  1865. @signers = @{$signers_ref} if defined $signers_ref;
  1866. @authors = @{$authors_ref} if defined $authors_ref;
  1867. @stats = @{$stats_ref} if defined $stats_ref;
  1868. # print("commits: <$commits>\nsigners:<@signers>\nauthors: <@authors>\nstats: <@stats>\n");
  1869. foreach my $signer (@signers) {
  1870. $signer = deduplicate_email($signer);
  1871. }
  1872. vcs_assign("commit_signer", $commits, @signers);
  1873. vcs_assign("authored", $commits, @authors);
  1874. if ($#authors == $#stats) {
  1875. my $stat_pattern = $VCS_cmds{"stat_pattern"};
  1876. $stat_pattern =~ s/(\$\w+)/$1/eeg; #interpolate $stat_pattern
  1877. my $added = 0;
  1878. my $deleted = 0;
  1879. for (my $i = 0; $i <= $#stats; $i++) {
  1880. if ($stats[$i] =~ /$stat_pattern/) {
  1881. $added += $1;
  1882. $deleted += $2;
  1883. }
  1884. }
  1885. my @tmp_authors = uniq(@authors);
  1886. foreach my $author (@tmp_authors) {
  1887. $author = deduplicate_email($author);
  1888. }
  1889. @tmp_authors = uniq(@tmp_authors);
  1890. my @list_added = ();
  1891. my @list_deleted = ();
  1892. foreach my $author (@tmp_authors) {
  1893. my $auth_added = 0;
  1894. my $auth_deleted = 0;
  1895. for (my $i = 0; $i <= $#stats; $i++) {
  1896. if ($author eq deduplicate_email($authors[$i]) &&
  1897. $stats[$i] =~ /$stat_pattern/) {
  1898. $auth_added += $1;
  1899. $auth_deleted += $2;
  1900. }
  1901. }
  1902. for (my $i = 0; $i < $auth_added; $i++) {
  1903. push(@list_added, $author);
  1904. }
  1905. for (my $i = 0; $i < $auth_deleted; $i++) {
  1906. push(@list_deleted, $author);
  1907. }
  1908. }
  1909. vcs_assign("added_lines", $added, @list_added);
  1910. vcs_assign("removed_lines", $deleted, @list_deleted);
  1911. }
  1912. }
  1913. sub vcs_file_blame {
  1914. my ($file) = @_;
  1915. my @signers = ();
  1916. my @all_commits = ();
  1917. my @commits = ();
  1918. my $total_commits;
  1919. my $total_lines;
  1920. $vcs_used = vcs_exists();
  1921. return if (!$vcs_used);
  1922. @all_commits = vcs_blame($file);
  1923. @commits = uniq(@all_commits);
  1924. $total_commits = @commits;
  1925. $total_lines = @all_commits;
  1926. if ($email_git_blame_signatures) {
  1927. if (vcs_is_hg()) {
  1928. my $commit_count;
  1929. my $commit_authors_ref;
  1930. my $commit_signers_ref;
  1931. my $stats_ref;
  1932. my @commit_authors = ();
  1933. my @commit_signers = ();
  1934. my $commit = join(" -r ", @commits);
  1935. my $cmd;
  1936. $cmd = $VCS_cmds{"find_commit_signers_cmd"};
  1937. $cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
  1938. ($commit_count, $commit_signers_ref, $commit_authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
  1939. @commit_authors = @{$commit_authors_ref} if defined $commit_authors_ref;
  1940. @commit_signers = @{$commit_signers_ref} if defined $commit_signers_ref;
  1941. push(@signers, @commit_signers);
  1942. } else {
  1943. foreach my $commit (@commits) {
  1944. my $commit_count;
  1945. my $commit_authors_ref;
  1946. my $commit_signers_ref;
  1947. my $stats_ref;
  1948. my @commit_authors = ();
  1949. my @commit_signers = ();
  1950. my $cmd;
  1951. $cmd = $VCS_cmds{"find_commit_signers_cmd"};
  1952. $cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
  1953. ($commit_count, $commit_signers_ref, $commit_authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
  1954. @commit_authors = @{$commit_authors_ref} if defined $commit_authors_ref;
  1955. @commit_signers = @{$commit_signers_ref} if defined $commit_signers_ref;
  1956. push(@signers, @commit_signers);
  1957. }
  1958. }
  1959. }
  1960. if ($from_filename) {
  1961. if ($output_rolestats) {
  1962. my @blame_signers;
  1963. if (vcs_is_hg()) {{ # Double brace for last exit
  1964. my $commit_count;
  1965. my @commit_signers = ();
  1966. @commits = uniq(@commits);
  1967. @commits = sort(@commits);
  1968. my $commit = join(" -r ", @commits);
  1969. my $cmd;
  1970. $cmd = $VCS_cmds{"find_commit_author_cmd"};
  1971. $cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
  1972. my @lines = ();
  1973. @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
  1974. if (!$email_git_penguin_chiefs) {
  1975. @lines = grep(!/${penguin_chiefs}/i, @lines);
  1976. }
  1977. last if !@lines;
  1978. my @authors = ();
  1979. foreach my $line (@lines) {
  1980. if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
  1981. my $author = $1;
  1982. $author = deduplicate_email($author);
  1983. push(@authors, $author);
  1984. }
  1985. }
  1986. save_commits_by_author(@lines) if ($interactive);
  1987. save_commits_by_signer(@lines) if ($interactive);
  1988. push(@signers, @authors);
  1989. }}
  1990. else {
  1991. foreach my $commit (@commits) {
  1992. my $i;
  1993. my $cmd = $VCS_cmds{"find_commit_author_cmd"};
  1994. $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
  1995. my @author = vcs_find_author($cmd);
  1996. next if !@author;
  1997. my $formatted_author = deduplicate_email($author[0]);
  1998. my $count = grep(/$commit/, @all_commits);
  1999. for ($i = 0; $i < $count ; $i++) {
  2000. push(@blame_signers, $formatted_author);
  2001. }
  2002. }
  2003. }
  2004. if (@blame_signers) {
  2005. vcs_assign("authored lines", $total_lines, @blame_signers);
  2006. }
  2007. }
  2008. foreach my $signer (@signers) {
  2009. $signer = deduplicate_email($signer);
  2010. }
  2011. vcs_assign("commits", $total_commits, @signers);
  2012. } else {
  2013. foreach my $signer (@signers) {
  2014. $signer = deduplicate_email($signer);
  2015. }
  2016. vcs_assign("modified commits", $total_commits, @signers);
  2017. }
  2018. }
  2019. sub vcs_file_exists {
  2020. my ($file) = @_;
  2021. my $exists;
  2022. my $vcs_used = vcs_exists();
  2023. return 0 if (!$vcs_used);
  2024. my $cmd = $VCS_cmds{"file_exists_cmd"};
  2025. $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
  2026. $cmd .= " 2>&1";
  2027. $exists = &{$VCS_cmds{"execute_cmd"}}($cmd);
  2028. return 0 if ($? != 0);
  2029. return $exists;
  2030. }
  2031. sub vcs_list_files {
  2032. my ($file) = @_;
  2033. my @lsfiles = ();
  2034. my $vcs_used = vcs_exists();
  2035. return 0 if (!$vcs_used);
  2036. my $cmd = $VCS_cmds{"list_files_cmd"};
  2037. $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
  2038. @lsfiles = &{$VCS_cmds{"execute_cmd"}}($cmd);
  2039. return () if ($? != 0);
  2040. return @lsfiles;
  2041. }
  2042. sub uniq {
  2043. my (@parms) = @_;
  2044. my %saw;
  2045. @parms = grep(!$saw{$_}++, @parms);
  2046. return @parms;
  2047. }
  2048. sub sort_and_uniq {
  2049. my (@parms) = @_;
  2050. my %saw;
  2051. @parms = sort @parms;
  2052. @parms = grep(!$saw{$_}++, @parms);
  2053. return @parms;
  2054. }
  2055. sub clean_file_emails {
  2056. my (@file_emails) = @_;
  2057. my @fmt_emails = ();
  2058. foreach my $email (@file_emails) {
  2059. $email =~ s/[\(\<\{]{0,1}([A-Za-z0-9_\.\+-]+\@[A-Za-z0-9\.-]+)[\)\>\}]{0,1}/\<$1\>/g;
  2060. my ($name, $address) = parse_email($email);
  2061. if ($name eq '"[,\.]"') {
  2062. $name = "";
  2063. }
  2064. my @nw = split(/[^A-Za-zÀ-ÿ\'\,\.\+-]/, $name);
  2065. if (@nw > 2) {
  2066. my $first = $nw[@nw - 3];
  2067. my $middle = $nw[@nw - 2];
  2068. my $last = $nw[@nw - 1];
  2069. if (((length($first) == 1 && $first =~ m/[A-Za-z]/) ||
  2070. (length($first) == 2 && substr($first, -1) eq ".")) ||
  2071. (length($middle) == 1 ||
  2072. (length($middle) == 2 && substr($middle, -1) eq "."))) {
  2073. $name = "$first $middle $last";
  2074. } else {
  2075. $name = "$middle $last";
  2076. }
  2077. }
  2078. if (substr($name, -1) =~ /[,\.]/) {
  2079. $name = substr($name, 0, length($name) - 1);
  2080. } elsif (substr($name, -2) =~ /[,\.]"/) {
  2081. $name = substr($name, 0, length($name) - 2) . '"';
  2082. }
  2083. if (substr($name, 0, 1) =~ /[,\.]/) {
  2084. $name = substr($name, 1, length($name) - 1);
  2085. } elsif (substr($name, 0, 2) =~ /"[,\.]/) {
  2086. $name = '"' . substr($name, 2, length($name) - 2);
  2087. }
  2088. my $fmt_email = format_email($name, $address, $email_usename);
  2089. push(@fmt_emails, $fmt_email);
  2090. }
  2091. return @fmt_emails;
  2092. }
  2093. sub merge_email {
  2094. my @lines;
  2095. my %saw;
  2096. for (@_) {
  2097. my ($address, $role) = @$_;
  2098. if (!$saw{$address}) {
  2099. if ($output_roles) {
  2100. push(@lines, "$address ($role)");
  2101. } else {
  2102. push(@lines, $address);
  2103. }
  2104. $saw{$address} = 1;
  2105. }
  2106. }
  2107. return @lines;
  2108. }
  2109. sub output {
  2110. my (@parms) = @_;
  2111. if ($output_multiline) {
  2112. foreach my $line (@parms) {
  2113. print("${line}\n");
  2114. }
  2115. } else {
  2116. print(join($output_separator, @parms));
  2117. print("\n");
  2118. }
  2119. }
  2120. my $rfc822re;
  2121. sub make_rfc822re {
  2122. # Basic lexical tokens are specials, domain_literal, quoted_string, atom, and
  2123. # comment. We must allow for rfc822_lwsp (or comments) after each of these.
  2124. # This regexp will only work on addresses which have had comments stripped
  2125. # and replaced with rfc822_lwsp.
  2126. my $specials = '()<>@,;:\\\\".\\[\\]';
  2127. my $controls = '\\000-\\037\\177';
  2128. my $dtext = "[^\\[\\]\\r\\\\]";
  2129. my $domain_literal = "\\[(?:$dtext|\\\\.)*\\]$rfc822_lwsp*";
  2130. my $quoted_string = "\"(?:[^\\\"\\r\\\\]|\\\\.|$rfc822_lwsp)*\"$rfc822_lwsp*";
  2131. # Use zero-width assertion to spot the limit of an atom. A simple
  2132. # $rfc822_lwsp* causes the regexp engine to hang occasionally.
  2133. my $atom = "[^$specials $controls]+(?:$rfc822_lwsp+|\\Z|(?=[\\[\"$specials]))";
  2134. my $word = "(?:$atom|$quoted_string)";
  2135. my $localpart = "$word(?:\\.$rfc822_lwsp*$word)*";
  2136. my $sub_domain = "(?:$atom|$domain_literal)";
  2137. my $domain = "$sub_domain(?:\\.$rfc822_lwsp*$sub_domain)*";
  2138. my $addr_spec = "$localpart\@$rfc822_lwsp*$domain";
  2139. my $phrase = "$word*";
  2140. my $route = "(?:\@$domain(?:,\@$rfc822_lwsp*$domain)*:$rfc822_lwsp*)";
  2141. my $route_addr = "\\<$rfc822_lwsp*$route?$addr_spec\\>$rfc822_lwsp*";
  2142. my $mailbox = "(?:$addr_spec|$phrase$route_addr)";
  2143. my $group = "$phrase:$rfc822_lwsp*(?:$mailbox(?:,\\s*$mailbox)*)?;\\s*";
  2144. my $address = "(?:$mailbox|$group)";
  2145. return "$rfc822_lwsp*$address";
  2146. }
  2147. sub rfc822_strip_comments {
  2148. my $s = shift;
  2149. # Recursively remove comments, and replace with a single space. The simpler
  2150. # regexps in the Email Addressing FAQ are imperfect - they will miss escaped
  2151. # chars in atoms, for example.
  2152. while ($s =~ s/^((?:[^"\\]|\\.)*
  2153. (?:"(?:[^"\\]|\\.)*"(?:[^"\\]|\\.)*)*)
  2154. \((?:[^()\\]|\\.)*\)/$1 /osx) {}
  2155. return $s;
  2156. }
  2157. # valid: returns true if the parameter is an RFC822 valid address
  2158. #
  2159. sub rfc822_valid {
  2160. my $s = rfc822_strip_comments(shift);
  2161. if (!$rfc822re) {
  2162. $rfc822re = make_rfc822re();
  2163. }
  2164. return $s =~ m/^$rfc822re$/so && $s =~ m/^$rfc822_char*$/;
  2165. }
  2166. # validlist: In scalar context, returns true if the parameter is an RFC822
  2167. # valid list of addresses.
  2168. #
  2169. # In list context, returns an empty list on failure (an invalid
  2170. # address was found); otherwise a list whose first element is the
  2171. # number of addresses found and whose remaining elements are the
  2172. # addresses. This is needed to disambiguate failure (invalid)
  2173. # from success with no addresses found, because an empty string is
  2174. # a valid list.
  2175. sub rfc822_validlist {
  2176. my $s = rfc822_strip_comments(shift);
  2177. if (!$rfc822re) {
  2178. $rfc822re = make_rfc822re();
  2179. }
  2180. # * null list items are valid according to the RFC
  2181. # * the '1' business is to aid in distinguishing failure from no results
  2182. my @r;
  2183. if ($s =~ m/^(?:$rfc822re)?(?:,(?:$rfc822re)?)*$/so &&
  2184. $s =~ m/^$rfc822_char*$/) {
  2185. while ($s =~ m/(?:^|,$rfc822_lwsp*)($rfc822re)/gos) {
  2186. push(@r, $1);
  2187. }
  2188. return wantarray ? (scalar(@r), @r) : 1;
  2189. }
  2190. return wantarray ? () : 0;
  2191. }