get_maintainer.pl 33 KB

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