use strict;
my $P = $0;
-my $V = '0.24';
+my $V = '0.25';
use Getopt::Long qw(:config no_auto_abbrev);
my $email_list = 1;
my $email_subscriber_list = 0;
my $email_git_penguin_chiefs = 0;
-my $email_git = 1;
+my $email_git = 0;
my $email_git_all_signature_types = 0;
my $email_git_blame = 0;
+my $email_git_fallback = 1;
my $email_git_min_signatures = 1;
my $email_git_max_maintainers = 5;
my $email_git_min_percent = 5;
"available" => '(which("git") ne "") && (-d ".git")',
"find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file",
"find_commit_signers_cmd" => "git log --no-color -1 \$commit",
+ "find_commit_author_cmd" => "git log -1 --format=\"%an <%ae>\" \$commit",
"blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
"blame_file_cmd" => "git blame -l \$file",
"commit_pattern" => "^commit [0-9a-f]{40,40}",
"hg log --date=\$email_hg_since" .
" --template='commit {node}\\n{desc}\\n' -- \$file",
"find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit",
+ "find_commit_author_cmd" => "hg log -l 1 --template='{author}\\n' -r \$commit",
"blame_range_cmd" => "", # not supported
"blame_file_cmd" => "hg blame -c \$file",
"commit_pattern" => "^commit [0-9a-f]{40,40}",
"blame_commit_pattern" => "^([0-9a-f]+):"
);
-if (-f "${lk_path}.get_maintainer.conf") {
+my $conf = which_conf(".get_maintainer.conf");
+if (-f $conf) {
my @conf_args;
- open(my $conffile, '<', "${lk_path}.get_maintainer.conf")
- or warn "$P: Can't open .get_maintainer.conf: $!\n";
+ open(my $conffile, '<', "$conf")
+ or warn "$P: Can't find a readable .get_maintainer.conf file $!\n";
+
while (<$conffile>) {
my $line = $_;
'git!' => \$email_git,
'git-all-signature-types!' => \$email_git_all_signature_types,
'git-blame!' => \$email_git_blame,
+ 'git-fallback!' => \$email_git_fallback,
'git-chief-penguins!' => \$email_git_penguin_chiefs,
'git-min-signatures=i' => \$email_git_min_signatures,
'git-max-maintainers=i' => \$email_git_max_maintainers,
}
if ($from_filename) {
push(@files, $file);
- if (-f $file && ($keywords || $file_emails)) {
+ if ($file ne "MAINTAINERS" && -f $file && ($keywords || $file_emails)) {
open(my $f, '<', $file)
or die "$P: Can't open $file: $!\n";
my $text = do { local($/) ; <$f> };
foreach my $file (@files) {
my %hash;
+ my $exact_pattern_match = 0;
my $tvi = find_first_section();
while ($tvi < @typevalue) {
my $start = find_starting_index($tvi);
my $value_pd = ($value =~ tr@/@@);
my $file_pd = ($file =~ tr@/@@);
$value_pd++ if (substr($value,-1,1) ne "/");
+ $value_pd = -1 if ($value =~ /^\.\*/);
+ $exact_pattern_match = 1 if ($value_pd >= $file_pd);
if ($pattern_depth == 0 ||
(($file_pd - $value_pd) < $pattern_depth)) {
$hash{$tvi} = $value_pd;
foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
add_categories($line);
- if ($sections) {
- my $i;
- my $start = find_starting_index($line);
- my $end = find_ending_index($line);
- for ($i = $start; $i < $end; $i++) {
- my $line = $typevalue[$i];
- if ($line =~ /^[FX]:/) { ##Restore file patterns
- $line =~ s/([^\\])\.([^\*])/$1\?$2/g;
- $line =~ s/([^\\])\.$/$1\?/g; ##Convert . back to ?
- $line =~ s/\\\./\./g; ##Convert \. to .
- $line =~ s/\.\*/\*/g; ##Convert .* to *
- }
- $line =~ s/^([A-Z]):/$1:\t/g;
- print("$line\n");
+ if ($sections) {
+ my $i;
+ my $start = find_starting_index($line);
+ my $end = find_ending_index($line);
+ for ($i = $start; $i < $end; $i++) {
+ my $line = $typevalue[$i];
+ if ($line =~ /^[FX]:/) { ##Restore file patterns
+ $line =~ s/([^\\])\.([^\*])/$1\?$2/g;
+ $line =~ s/([^\\])\.$/$1\?/g; ##Convert . back to ?
+ $line =~ s/\\\./\./g; ##Convert \. to .
+ $line =~ s/\.\*/\*/g; ##Convert .* to *
}
- print("\n");
+ $line =~ s/^([A-Z]):/$1:\t/g;
+ print("$line\n");
}
+ print("\n");
+ }
}
- if ($email && $email_git) {
+ if ($email &&
+ ($email_git || ($email_git_fallback && !$exact_pattern_match))) {
vcs_file_signoffs($file);
}
--git => include recent git \*-by: signers
--git-all-signature-types => include signers regardless of signature type
or use only ${signaturePattern} signers (default: $email_git_all_signature_types)
+ --git-fallback => use git when no exact MAINTAINERS pattern (default: $email_git_fallback)
--git-chief-penguins => include ${penguin_chiefs}
--git-min-signatures => number of signatures required (default: $email_git_min_signatures)
--git-max-maintainers => maximum maintainers to add (default: $email_git_max_maintainers)
return "";
}
+sub which_conf {
+ my ($conf) = @_;
+
+ foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
+ if (-e "$path/$conf") {
+ return "$path/$conf";
+ }
+ }
+
+ return "";
+}
+
sub mailmap {
my (@lines) = @_;
my %hash;
if (!$email_git_penguin_chiefs) {
@lines = grep(!/${penguin_chiefs}/i, @lines);
}
+
+ return (0, @lines) if !@lines;
+
# cut -f2- -d":"
s/.*:\s*(.+)\s*/$1/ for (@lines);
return ($commits, @lines);
}
+sub vcs_find_author {
+ my ($cmd) = @_;
+ my @lines = ();
+
+ @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
+
+ if (!$email_git_penguin_chiefs) {
+ @lines = grep(!/${penguin_chiefs}/i, @lines);
+ }
+
+ return @lines if !@lines;
+
+## Reformat email addresses (with names) to avoid badly written signatures
+
+ foreach my $line (@lines) {
+ my ($name, $address) = parse_email($line);
+ $line = format_email($name, $address, 1);
+ }
+
+ return @lines;
+}
+
sub vcs_save_commits {
my ($cmd) = @_;
my @lines = ();
@commits = vcs_save_commits($cmd);
}
+ foreach my $commit (@commits) {
+ $commit =~ s/^\^//g;
+ }
+
return @commits;
}
@lines = mailmap(@lines);
}
+ return if (@lines <= 0);
+
@lines = sort(@lines);
# uniq -c
my ($file) = @_;
my @signers = ();
+ my @all_commits = ();
my @commits = ();
my $total_commits;
+ my $total_lines;
return if (!vcs_exists());
- @commits = vcs_blame($file);
- @commits = uniq(@commits);
+ @all_commits = vcs_blame($file);
+ @commits = uniq(@all_commits);
$total_commits = @commits;
+ $total_lines = @all_commits;
foreach my $commit (@commits) {
my $commit_count;
$cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
($commit_count, @commit_signers) = vcs_find_signers($cmd);
+
push(@signers, @commit_signers);
}
if ($from_filename) {
+ if ($output_rolestats) {
+ my @blame_signers;
+ foreach my $commit (@commits) {
+ my $i;
+ my $cmd = $VCS_cmds{"find_commit_author_cmd"};
+ $cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
+ my @author = vcs_find_author($cmd);
+ next if !@author;
+ my $count = grep(/$commit/, @all_commits);
+ for ($i = 0; $i < $count ; $i++) {
+ push(@blame_signers, $author[0]);
+ }
+ }
+ if (@blame_signers) {
+ vcs_assign("authored lines", $total_lines, @blame_signers);
+ }
+ }
vcs_assign("commits", $total_commits, @signers);
} else {
vcs_assign("modified commits", $total_commits, @signers);