Commit 683c6f8f authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

scripts/get_maintainer.pl: improve --interactive UI

o Added searching by git-blame as well as git-history
o Added different selection toggles
o Added ability to list commits by author or by sign-off-type
o Use custom git and hg formats to make searching for subject/author
  a bit easier.
o Move inlined section matching and searching git/hg history to
  new get_maintainer subroutine
o Added subroutines save_commits_by_author and save_commits_by_signer
o Removed subroutines vcs_get_shortlog and vcs_email_shortlog
o Rename camelcase signaturePattern to signature_pattern

Update to 0.26 beta3
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Cc: Florian Mickler <florian@mickler.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent dace8e30
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
use strict; use strict;
my $P = $0; my $P = $0;
my $V = '0.25'; my $V = '0.26-beta3';
use Getopt::Long qw(:config no_auto_abbrev); use Getopt::Long qw(:config no_auto_abbrev);
...@@ -27,6 +27,7 @@ my $email_git_penguin_chiefs = 0; ...@@ -27,6 +27,7 @@ my $email_git_penguin_chiefs = 0;
my $email_git = 0; my $email_git = 0;
my $email_git_all_signature_types = 0; my $email_git_all_signature_types = 0;
my $email_git_blame = 0; my $email_git_blame = 0;
my $email_git_blame_signatures = 1;
my $email_git_fallback = 1; my $email_git_fallback = 1;
my $email_git_min_signatures = 1; my $email_git_min_signatures = 1;
my $email_git_max_maintainers = 5; my $email_git_max_maintainers = 5;
...@@ -51,9 +52,12 @@ my $pattern_depth = 0; ...@@ -51,9 +52,12 @@ my $pattern_depth = 0;
my $version = 0; my $version = 0;
my $help = 0; my $help = 0;
my $vcs_used = 0;
my $exit = 0; my $exit = 0;
my %shortlog_buffer; my %commit_author_hash;
my %commit_signer_hash;
my @penguin_chief = (); my @penguin_chief = ();
push(@penguin_chief, "Linus Torvalds:torvalds\@linux-foundation.org"); push(@penguin_chief, "Linus Torvalds:torvalds\@linux-foundation.org");
...@@ -77,7 +81,6 @@ my @signature_tags = (); ...@@ -77,7 +81,6 @@ my @signature_tags = ();
push(@signature_tags, "Signed-off-by:"); push(@signature_tags, "Signed-off-by:");
push(@signature_tags, "Reviewed-by:"); push(@signature_tags, "Reviewed-by:");
push(@signature_tags, "Acked-by:"); push(@signature_tags, "Acked-by:");
my $signaturePattern = "\(" . join("|", @signature_tags) . "\)";
# rfc822 email address - preloaded methods go here. # rfc822 email address - preloaded methods go here.
my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])"; my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])";
...@@ -90,29 +93,62 @@ my %VCS_cmds; ...@@ -90,29 +93,62 @@ my %VCS_cmds;
my %VCS_cmds_git = ( my %VCS_cmds_git = (
"execute_cmd" => \&git_execute_cmd, "execute_cmd" => \&git_execute_cmd,
"available" => '(which("git") ne "") && (-d ".git")', "available" => '(which("git") ne "") && (-d ".git")',
"find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file", "find_signers_cmd" =>
"find_commit_signers_cmd" => "git log --no-color -1 \$commit", "git log --no-color --since=\$email_git_since " .
"find_commit_author_cmd" => "git log -1 --format=\"%an <%ae>\" \$commit", '--format="GitCommit: %H%n' .
'GitAuthor: %an <%ae>%n' .
'GitDate: %aD%n' .
'GitSubject: %s%n' .
'%b%n"' .
" -- \$file",
"find_commit_signers_cmd" =>
"git log --no-color " .
'--format="GitCommit: %H%n' .
'GitAuthor: %an <%ae>%n' .
'GitDate: %aD%n' .
'GitSubject: %s%n' .
'%b%n"' .
" -1 \$commit",
"find_commit_author_cmd" =>
"git log --no-color " .
'--format="GitCommit: %H%n' .
'GitAuthor: %an <%ae>%n' .
'GitDate: %aD%n' .
'GitSubject: %s%n"' .
" -1 \$commit",
"blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file", "blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
"blame_file_cmd" => "git blame -l \$file", "blame_file_cmd" => "git blame -l \$file",
"commit_pattern" => "^commit [0-9a-f]{40,40}", "commit_pattern" => "^GitCommit: ([0-9a-f]{40,40})",
"blame_commit_pattern" => "^([0-9a-f]+) ", "blame_commit_pattern" => "^([0-9a-f]+) ",
"shortlog_cmd" => "git log --no-color --oneline --since=\$email_git_since --author=\"\$email\" -- \$file" "author_pattern" => "^GitAuthor: (.*)",
"subject_pattern" => "^GitSubject: (.*)",
); );
my %VCS_cmds_hg = ( my %VCS_cmds_hg = (
"execute_cmd" => \&hg_execute_cmd, "execute_cmd" => \&hg_execute_cmd,
"available" => '(which("hg") ne "") && (-d ".hg")', "available" => '(which("hg") ne "") && (-d ".hg")',
"find_signers_cmd" => "find_signers_cmd" =>
"hg log --date=\$email_hg_since" . "hg log --date=\$email_hg_since " .
" --template='commit {node}\\n{desc}\\n' -- \$file", "--template='HgCommit: {node}\\n" .
"find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit", "HgAuthor: {author}\\n" .
"find_commit_author_cmd" => "hg log -l 1 --template='{author}\\n' -r \$commit", "HgSubject: {desc}\\n'" .
" -- \$file",
"find_commit_signers_cmd" =>
"hg log " .
"--template='HgSubject: {desc}\\n'" .
" -r \$commit",
"find_commit_author_cmd" =>
"hg log " .
"--template='HgCommit: {node}\\n" .
"HgAuthor: {author}\\n" .
"HgSubject: {desc|firstline}\\n'" .
" -r \$commit",
"blame_range_cmd" => "", # not supported "blame_range_cmd" => "", # not supported
"blame_file_cmd" => "hg blame -c \$file", "blame_file_cmd" => "hg blame -n \$file",
"commit_pattern" => "^commit [0-9a-f]{40,40}", "commit_pattern" => "^HgCommit: ([0-9a-f]{40,40})",
"blame_commit_pattern" => "^([0-9a-f]+):", "blame_commit_pattern" => "^([ 0-9a-f]+):",
"shortlog_cmd" => "ht log --date=\$email_hg_since" "author_pattern" => "^HgAuthor: (.*)",
"subject_pattern" => "^HgSubject: (.*)",
); );
my $conf = which_conf(".get_maintainer.conf"); my $conf = which_conf(".get_maintainer.conf");
...@@ -146,6 +182,7 @@ if (!GetOptions( ...@@ -146,6 +182,7 @@ if (!GetOptions(
'git!' => \$email_git, 'git!' => \$email_git,
'git-all-signature-types!' => \$email_git_all_signature_types, 'git-all-signature-types!' => \$email_git_all_signature_types,
'git-blame!' => \$email_git_blame, 'git-blame!' => \$email_git_blame,
'git-blame-signatures!' => \$email_git_blame_signatures,
'git-fallback!' => \$email_git_fallback, 'git-fallback!' => \$email_git_fallback,
'git-chief-penguins!' => \$email_git_penguin_chiefs, 'git-chief-penguins!' => \$email_git_penguin_chiefs,
'git-min-signatures=i' => \$email_git_min_signatures, 'git-min-signatures=i' => \$email_git_min_signatures,
...@@ -193,13 +230,9 @@ if (-t STDIN && !@ARGV) { ...@@ -193,13 +230,9 @@ if (-t STDIN && !@ARGV) {
die "$P: missing patchfile or -f file - use --help if necessary\n"; die "$P: missing patchfile or -f file - use --help if necessary\n";
} }
if ($output_separator ne ", ") { $output_multiline = 0 if ($output_separator ne ", ");
$output_multiline = 0; $output_rolestats = 1 if ($interactive);
} $output_roles = 1 if ($output_rolestats);
if ($output_rolestats) {
$output_roles = 1;
}
if ($sections) { if ($sections) {
$email = 0; $email = 0;
...@@ -227,12 +260,6 @@ if (!top_of_kernel_tree($lk_path)) { ...@@ -227,12 +260,6 @@ if (!top_of_kernel_tree($lk_path)) {
. "a linux kernel source tree.\n"; . "a linux kernel source tree.\n";
} }
if ($email_git_all_signature_types) {
$signaturePattern = "(.+?)[Bb][Yy]:";
}
## Read MAINTAINERS for type/value pairs ## Read MAINTAINERS for type/value pairs
my @typevalue = (); my @typevalue = ();
...@@ -371,16 +398,67 @@ foreach my $file (@ARGV) { ...@@ -371,16 +398,67 @@ foreach my $file (@ARGV) {
@file_emails = uniq(@file_emails); @file_emails = uniq(@file_emails);
my %email_hash_name;
my %email_hash_address;
my @email_to = (); my @email_to = ();
my %hash_list_to;
my @list_to = (); my @list_to = ();
my @scm = (); my @scm = ();
my @web = (); my @web = ();
my @subsystem = (); my @subsystem = ();
my @status = (); my @status = ();
my $signature_pattern;
my @to = get_maintainer();
# Find responsible parties @to = merge_email(@to);
foreach my $file (@files) { output(@to) if (@to);
if ($scm) {
@scm = uniq(@scm);
output(@scm);
}
if ($status) {
@status = uniq(@status);
output(@status);
}
if ($subsystem) {
@subsystem = uniq(@subsystem);
output(@subsystem);
}
if ($web) {
@web = uniq(@web);
output(@web);
}
exit($exit);
sub get_maintainer {
%email_hash_name = ();
%email_hash_address = ();
%commit_author_hash = ();
%commit_signer_hash = ();
@email_to = ();
%hash_list_to = ();
@list_to = ();
@scm = ();
@web = ();
@subsystem = ();
@status = ();
if ($email_git_all_signature_types) {
$signature_pattern = "(.+?)[Bb][Yy]:";
} else {
$signature_pattern = "\(" . join("|", @signature_tags) . "\)";
}
# Find responsible parties
foreach my $file (@files) {
my %hash; my %hash;
my $exact_pattern_match = 0; my $exact_pattern_match = 0;
...@@ -429,7 +507,6 @@ foreach my $file (@files) { ...@@ -429,7 +507,6 @@ foreach my $file (@files) {
} }
} }
} }
$tvi = $end + 1; $tvi = $end + 1;
} }
...@@ -454,27 +531,23 @@ foreach my $file (@files) { ...@@ -454,27 +531,23 @@ foreach my $file (@files) {
} }
} }
if ($email && if ($email && ($email_git ||
($email_git || ($email_git_fallback && !$exact_pattern_match))) { ($email_git_fallback && !$exact_pattern_match))) {
vcs_file_signoffs($file); vcs_file_signoffs($file);
} }
if ($email && $email_git_blame) { if ($email && $email_git_blame) {
vcs_file_blame($file); vcs_file_blame($file);
} }
if ($email && $interactive){
vcs_file_shortlogs($file);
} }
}
if ($keywords) { if ($keywords) {
@keyword_tvi = sort_and_uniq(@keyword_tvi); @keyword_tvi = sort_and_uniq(@keyword_tvi);
foreach my $line (@keyword_tvi) { foreach my $line (@keyword_tvi) {
add_categories($line); add_categories($line);
} }
} }
if ($email) { if ($email) {
foreach my $chief (@penguin_chief) { foreach my $chief (@penguin_chief) {
if ($chief =~ m/^(.*):(.*)/) { if ($chief =~ m/^(.*):(.*)/) {
my $email_address; my $email_address;
...@@ -495,44 +568,23 @@ if ($email) { ...@@ -495,44 +568,23 @@ if ($email) {
push_email_address($tmp_email, ''); push_email_address($tmp_email, '');
add_role($tmp_email, 'in file'); add_role($tmp_email, 'in file');
} }
} }
if ($email || $email_list) {
my @to = (); my @to = ();
if ($email || $email_list) {
if ($email) { if ($email) {
if ($interactive) {
@email_to = @{vcs_interactive_menu(\@email_to)};
}
@to = (@to, @email_to); @to = (@to, @email_to);
} }
if ($email_list) { if ($email_list) {
@to = (@to, @list_to); @to = (@to, @list_to);
} }
output(merge_email(@to)); }
}
if ($scm) {
@scm = uniq(@scm);
output(@scm);
}
if ($status) {
@status = uniq(@status);
output(@status);
}
if ($subsystem) { @to = interactive_get_maintainer(\@to) if ($interactive);
@subsystem = uniq(@subsystem);
output(@subsystem);
}
if ($web) { return @to;
@web = uniq(@web);
output(@web);
} }
exit($exit);
sub file_match_pattern { sub file_match_pattern {
my ($file, $pattern) = @_; my ($file, $pattern) = @_;
if (substr($pattern, -1) eq "/") { if (substr($pattern, -1) eq "/") {
...@@ -561,7 +613,7 @@ MAINTAINER field selection options: ...@@ -561,7 +613,7 @@ MAINTAINER field selection options:
--email => print email address(es) if any --email => print email address(es) if any
--git => include recent git \*-by: signers --git => include recent git \*-by: signers
--git-all-signature-types => include signers regardless of signature type --git-all-signature-types => include signers regardless of signature type
or use only ${signaturePattern} signers (default: $email_git_all_signature_types) or use only ${signature_pattern} signers (default: $email_git_all_signature_types)
--git-fallback => use git when no exact MAINTAINERS pattern (default: $email_git_fallback) --git-fallback => use git when no exact MAINTAINERS pattern (default: $email_git_fallback)
--git-chief-penguins => include ${penguin_chiefs} --git-chief-penguins => include ${penguin_chiefs}
--git-min-signatures => number of signatures required (default: $email_git_min_signatures) --git-min-signatures => number of signatures required (default: $email_git_min_signatures)
...@@ -847,11 +899,19 @@ sub add_categories { ...@@ -847,11 +899,19 @@ sub add_categories {
} }
if ($list_additional =~ m/subscribers-only/) { if ($list_additional =~ m/subscribers-only/) {
if ($email_subscriber_list) { if ($email_subscriber_list) {
push(@list_to, [$list_address, "subscriber list${list_role}"]); if (!$hash_list_to{$list_address}) {
$hash_list_to{$list_address} = 1;
push(@list_to, [$list_address,
"subscriber list${list_role}"]);
}
} }
} else { } else {
if ($email_list) { if ($email_list) {
push(@list_to, [$list_address, "open list${list_role}"]); if (!$hash_list_to{$list_address}) {
$hash_list_to{$list_address} = 1;
push(@list_to, [$list_address,
"open list${list_role}"]);
}
} }
} }
} elsif ($ptype eq "M") { } elsif ($ptype eq "M") {
...@@ -882,9 +942,6 @@ sub add_categories { ...@@ -882,9 +942,6 @@ sub add_categories {
} }
} }
my %email_hash_name;
my %email_hash_address;
sub email_inuse { sub email_inuse {
my ($name, $address) = @_; my ($name, $address) = @_;
...@@ -1037,10 +1094,31 @@ sub hg_execute_cmd { ...@@ -1037,10 +1094,31 @@ sub hg_execute_cmd {
return @lines; return @lines;
} }
sub extract_formatted_signatures {
my (@signature_lines) = @_;
my @type = @signature_lines;
s/\s*(.*):.*/$1/ for (@type);
# cut -f2- -d":"
s/\s*.*:\s*(.+)\s*/$1/ for (@signature_lines);
## Reformat email addresses (with names) to avoid badly written signatures
foreach my $signer (@signature_lines) {
my ($name, $address) = parse_email($signer);
$signer = format_email($name, $address, 1);
}
return (\@type, \@signature_lines);
}
sub vcs_find_signers { sub vcs_find_signers {
my ($cmd) = @_; my ($cmd) = @_;
my @lines = ();
my $commits; my $commits;
my @lines = ();
my @signatures = ();
@lines = &{$VCS_cmds{"execute_cmd"}}($cmd); @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
...@@ -1048,24 +1126,20 @@ sub vcs_find_signers { ...@@ -1048,24 +1126,20 @@ sub vcs_find_signers {
$commits = grep(/$pattern/, @lines); # of commits $commits = grep(/$pattern/, @lines); # of commits
@lines = grep(/^[ \t]*${signaturePattern}.*\@.*$/, @lines); @signatures = grep(/^[ \t]*${signature_pattern}.*\@.*$/, @lines);
if (!$email_git_penguin_chiefs) {
@lines = grep(!/${penguin_chiefs}/i, @lines);
}
return (0, @lines) if !@lines; return (0, @signatures) if !@signatures;
# cut -f2- -d":" save_commits_by_author(@lines) if ($interactive);
s/.*:\s*(.+)\s*/$1/ for (@lines); save_commits_by_signer(@lines) if ($interactive);
## Reformat email addresses (with names) to avoid badly written signatures if (!$email_git_penguin_chiefs) {
@signatures = grep(!/${penguin_chiefs}/i, @signatures);
foreach my $line (@lines) {
my ($name, $address) = parse_email($line);
$line = format_email($name, $address, 1);
} }
return ($commits, @lines); my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
return ($commits, @$signers_ref);
} }
sub vcs_find_author { sub vcs_find_author {
...@@ -1080,14 +1154,20 @@ sub vcs_find_author { ...@@ -1080,14 +1154,20 @@ sub vcs_find_author {
return @lines if !@lines; return @lines if !@lines;
## Reformat email addresses (with names) to avoid badly written signatures my @authors = ();
foreach my $line (@lines) { foreach my $line (@lines) {
my ($name, $address) = parse_email($line); if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
$line = format_email($name, $address, 1); my $author = $1;
my ($name, $address) = parse_email($author);
$author = format_email($name, $address, 1);
push(@authors, $author);
}
} }
return @lines; save_commits_by_author(@lines) if ($interactive);
save_commits_by_signer(@lines) if ($interactive);
return @authors;
} }
sub vcs_save_commits { sub vcs_save_commits {
...@@ -1159,7 +1239,7 @@ sub vcs_exists { ...@@ -1159,7 +1239,7 @@ sub vcs_exists {
%VCS_cmds = %VCS_cmds_git; %VCS_cmds = %VCS_cmds_git;
return 1 if eval $VCS_cmds{"available"}; return 1 if eval $VCS_cmds{"available"};
%VCS_cmds = %VCS_cmds_hg; %VCS_cmds = %VCS_cmds_hg;
return 1 if eval $VCS_cmds{"available"}; return 2 if eval $VCS_cmds{"available"};
%VCS_cmds = (); %VCS_cmds = ();
if (!$printed_novcs) { if (!$printed_novcs) {
warn("$P: No supported VCS found. Add --nogit to options?\n"); warn("$P: No supported VCS found. Add --nogit to options?\n");
...@@ -1171,125 +1251,309 @@ sub vcs_exists { ...@@ -1171,125 +1251,309 @@ sub vcs_exists {
return 0; return 0;
} }
sub vcs_interactive_menu { sub vcs_is_git {
my $list_ref = shift; return $vcs_used == 1;
}
sub vcs_is_hg {
return $vcs_used == 2;
}
sub interactive_get_maintainer {
my ($list_ref) = @_;
my @list = @$list_ref; my @list = @$list_ref;
return if (!vcs_exists()); vcs_exists();
my %selected; my %selected;
my %shortlog; my %authored;
my $input; my %signed;
my $count = 0; my $count = 0;
#select maintainers by default #select maintainers by default
foreach my $entry (@list){ foreach my $entry (@list){
my $role = $entry->[1]; my $role = $entry->[1];
$selected{$count} = ($role =~ /maintainer:|supporter:/); $selected{$count} = ($role =~ /^(maintainer|supporter|open list)/);
$authored{$count} = 0;
$signed{$count} = 0;
$count++; $count++;
} }
#menu loop #menu loop
do { my $done = 0;
my $count = 0; my $print_options = 0;
foreach my $entry (@list){ my $redraw = 1;
while (!$done) {
$count = 0;
if ($redraw) {
printf STDERR "\n%1s %2s %-65sauth sign\n",
"*", "#", "email/list and role:stats";
foreach my $entry (@list) {
my $email = $entry->[0]; my $email = $entry->[0];
my $role = $entry->[1]; my $role = $entry->[1];
if ($selected{$count}){ my $sel = "";
print STDERR "* "; $sel = "*" if ($selected{$count});
} else { my $commit_author = $commit_author_hash{$email};
print STDERR " "; my $commit_signer = $commit_signer_hash{$email};
} my $authored = 0;
print STDERR "$count: $email,\t\t $role"; my $signed = 0;
print STDERR "\n"; $authored++ for (@{$commit_author});
if ($shortlog{$count}){ $signed++ for (@{$commit_signer});
my $entries_ref = vcs_get_shortlog($email); printf STDERR "%1s %2d %-65s", $sel, $count + 1, $email;
foreach my $entry_ref (@{$entries_ref}){ printf STDERR "%4d %4d", $authored, $signed
my $filename = @{$entry_ref}[0]; if ($authored > 0 || $signed > 0);
my @shortlog = @{@{$entry_ref}[1]}; printf STDERR "\n %s\n", $role;
print STDERR "\tshortlog for $filename (authored commits: " . @shortlog . ").\n"; if ($authored{$count}) {
foreach my $commit (@shortlog){ my $commit_author = $commit_author_hash{$email};
print STDERR "\t $commit\n"; foreach my $ref (@{$commit_author}) {
} print STDERR " Author: @{$ref}[1]\n";
print STDERR "\n"; }
}
if ($signed{$count}) {
my $commit_signer = $commit_signer_hash{$email};
foreach my $ref (@{$commit_signer}) {
print STDERR " @{$ref}[2]: @{$ref}[1]\n";
} }
} }
$count++; $count++;
} }
print STDERR "\n"; }
print STDERR "Choose whom to cc by entering a commaseperated list of numbers and hitting enter.\n"; my $date_ref = \$email_git_since;
print STDERR "To show a short list of commits, precede the number by a '?',\n"; $date_ref = \$email_hg_since if (vcs_is_hg());
print STDERR "A blank line indicates that you are satisfied with your choice.\n"; if ($print_options) {
$input = <STDIN>; $print_options = 0;
if (vcs_exists()) {
print STDERR
"\nVersion Control options:\n" .
"g use git history [$email_git]\n" .
"gf use git-fallback [$email_git_fallback]\n" .
"b use git blame [$email_git_blame]\n" .
"bs use blame signatures [$email_git_blame_signatures]\n" .
"c# minimum commits [$email_git_min_signatures]\n" .
"%# min percent [$email_git_min_percent]\n" .
"d# history to use [$$date_ref]\n" .
"x# max maintainers [$email_git_max_maintainers]\n" .
"t all signature types [$email_git_all_signature_types]\n";
}
print STDERR "\nAdditional options:\n" .
"0 toggle all\n" .
"f emails in file [$file_emails]\n" .
"k keywords in file [$keywords]\n" .
"r remove duplicates [$email_remove_duplicates]\n" .
"p# pattern match depth [$pattern_depth]\n";
}
print STDERR
"\n#(toggle), A#(author), S#(signed) *(all), ^(none), O(options), Y(approve): ";
my $input = <STDIN>;
chomp($input); chomp($input);
my @wish = split(/[, ]+/,$input); $redraw = 1;
foreach my $nr (@wish){ my $rerun = 0;
my $logtoggle = 0; my @wish = split(/[, ]+/, $input);
if ($nr =~ /\?/){ foreach my $nr (@wish) {
$nr =~ s/\?//; $nr = lc($nr);
$logtoggle = 1; my $sel = substr($nr, 0, 1);
my $str = substr($nr, 1);
my $val = 0;
$val = $1 if $str =~ /^(\d+)$/;
if ($sel eq "y") {
$interactive = 0;
$done = 1;
$output_rolestats = 0;
$output_roles = 0;
last;
} elsif ($nr =~ /^\d+$/ && $nr > 0 && $nr <= $count) {
$selected{$nr - 1} = !$selected{$nr - 1};
} elsif ($sel eq "*" || $sel eq '^') {
my $toggle = 0;
$toggle = 1 if ($sel eq '*');
for (my $i = 0; $i < $count; $i++) {
$selected{$i} = $toggle;
}
} elsif ($sel eq "0") {
for (my $i = 0; $i < $count; $i++) {
$selected{$i} = !$selected{$i};
}
} elsif ($sel eq "a") {
if ($val > 0 && $val <= $count) {
$authored{$val - 1} = !$authored{$val - 1};
} elsif ($str eq '*' || $str eq '^') {
my $toggle = 0;
$toggle = 1 if ($str eq '*');
for (my $i = 0; $i < $count; $i++) {
$authored{$i} = $toggle;
}
}
} elsif ($sel eq "s") {
if ($val > 0 && $val <= $count) {
$signed{$val - 1} = !$signed{$val - 1};
} elsif ($str eq '*' || $str eq '^') {
my $toggle = 0;
$toggle = 1 if ($str eq '*');
for (my $i = 0; $i < $count; $i++) {
$signed{$i} = $toggle;
}
}
} elsif ($sel eq "o") {
$print_options = 1;
$redraw = 1;
} elsif ($sel eq "g") {
if ($str eq "f") {
bool_invert(\$email_git_fallback);
} else {
bool_invert(\$email_git);
} }
$rerun = 1;
#skip out of bounds numbers } elsif ($sel eq "b") {
next unless ($nr <= $count && $nr >= 0); if ($str eq "s") {
bool_invert(\$email_git_blame_signatures);
if ($logtoggle){
$shortlog{$nr} = !$shortlog{$nr};
} else { } else {
$selected{$nr} = !$selected{$nr}; bool_invert(\$email_git_blame);
}
#switch shortlog on if an entry get's selected $rerun = 1;
if ($selected{$nr}){ } elsif ($sel eq "c") {
$shortlog{$nr}=1; if ($val > 0) {
$email_git_min_signatures = $val;
$rerun = 1;
}
} elsif ($sel eq "x") {
if ($val > 0) {
$email_git_max_maintainers = $val;
$rerun = 1;
}
} elsif ($sel eq "%") {
if ($str ne "" && $val >= 0) {
$email_git_min_percent = $val;
$rerun = 1;
}
} elsif ($sel eq "d") {
if (vcs_is_git()) {
$email_git_since = $str;
} elsif (vcs_is_hg()) {
$email_hg_since = $str;
}
$rerun = 1;
} elsif ($sel eq "t") {
bool_invert(\$email_git_all_signature_types);
$rerun = 1;
} elsif ($sel eq "f") {
bool_invert(\$file_emails);
$rerun = 1;
} elsif ($sel eq "r") {
bool_invert(\$email_remove_duplicates);
$rerun = 1;
} elsif ($sel eq "k") {
bool_invert(\$keywords);
$rerun = 1;
} elsif ($sel eq "p") {
if ($str ne "" && $val >= 0) {
$pattern_depth = $val;
$rerun = 1;
}
} else {
print STDERR "invalid option: '$nr'\n";
$redraw = 0;
}
}
if ($rerun) {
print STDERR "git-blame can be very slow, please have patience..."
if ($email_git_blame);
goto &get_maintainer;
} }
} }
};
} while(length($input) > 0);
#drop not selected entries #drop not selected entries
$count = 0; $count = 0;
my @new_emailto; my @new_emailto = ();
foreach my $entry (@list){ foreach my $entry (@list) {
if ($selected{$count}){ if ($selected{$count}) {
push(@new_emailto,$list[$count]); push(@new_emailto, $list[$count]);
print STDERR "$count: ";
print STDERR $email_to[$count]->[0];
print STDERR ",\t\t ";
print STDERR $email_to[$count]->[1];
print STDERR "\n";
} }
$count++; $count++;
} }
return \@new_emailto; return @new_emailto;
} }
sub vcs_get_shortlog { sub bool_invert {
my $arg = shift; my ($bool_ref) = @_;
my ($name, $address) = parse_email($arg);
return $shortlog_buffer{$address}; if ($$bool_ref) {
$$bool_ref = 0;
} else {
$$bool_ref = 1;
}
} }
sub vcs_file_shortlogs { sub save_commits_by_author {
my ($file) = @_; my (@lines) = @_;
print STDERR "shortlog processing $file:";
foreach my $entry (@email_to){ my @authors = ();
my ($name, $address) = parse_email($entry->[0]); my @commits = ();
print STDERR "."; my @subjects = ();
my $commits_ref = vcs_email_shortlog($address, $file);
push(@{$shortlog_buffer{$address}}, [ $file, $commits_ref ]); foreach my $line (@lines) {
} if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
print STDERR "\n"; my $author = $1;
my ($name, $address) = parse_email($author);
$author = format_email($name, $address, 1);
push(@authors, $author);
}
push(@commits, $1) if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
push(@subjects, $1) if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
}
for (my $i = 0; $i < @authors; $i++) {
my $exists = 0;
foreach my $ref(@{$commit_author_hash{$authors[$i]}}) {
if (@{$ref}[0] eq $commits[$i] &&
@{$ref}[1] eq $subjects[$i]) {
$exists = 1;
last;
}
}
if (!$exists) {
push(@{$commit_author_hash{$authors[$i]}},
[ ($commits[$i], $subjects[$i]) ]);
}
}
} }
sub vcs_email_shortlog { sub save_commits_by_signer {
my $email = shift; my (@lines) = @_;
my ($file) = @_;
my $commit = "";
my $subject = "";
my $cmd = $VCS_cmds{"shortlog_cmd"}; foreach my $line (@lines) {
$cmd =~ s/(\$\w+)/$1/eeg; #substitute variables $commit = $1 if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
my @lines = &{$VCS_cmds{"execute_cmd"}}($cmd); $subject = $1 if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
return \@lines; if ($line =~ /^[ \t]*${signature_pattern}.*\@.*$/) {
my @signatures = ($line);
my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
my @types = @$types_ref;
my @signers = @$signers_ref;
my $type = $types[0];
my $signer = $signers[0];
my $exists = 0;
foreach my $ref(@{$commit_signer_hash{$signer}}) {
if (@{$ref}[0] eq $commit &&
@{$ref}[1] eq $subject &&
@{$ref}[2] eq $type) {
$exists = 1;
last;
}
}
if (!$exists) {
push(@{$commit_signer_hash{$signer}},
[ ($commit, $subject, $type) ]);
}
}
}
} }
sub vcs_assign { sub vcs_assign {
...@@ -1342,7 +1606,8 @@ sub vcs_file_signoffs { ...@@ -1342,7 +1606,8 @@ sub vcs_file_signoffs {
my @signers = (); my @signers = ();
my $commits; my $commits;
return if (!vcs_exists()); $vcs_used = vcs_exists();
return if (!$vcs_used);
my $cmd = $VCS_cmds{"find_signers_cmd"}; my $cmd = $VCS_cmds{"find_signers_cmd"};
$cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd $cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
...@@ -1360,28 +1625,83 @@ sub vcs_file_blame { ...@@ -1360,28 +1625,83 @@ sub vcs_file_blame {
my $total_commits; my $total_commits;
my $total_lines; my $total_lines;
return if (!vcs_exists()); $vcs_used = vcs_exists();
return if (!$vcs_used);
@all_commits = vcs_blame($file); @all_commits = vcs_blame($file);
@commits = uniq(@all_commits); @commits = uniq(@all_commits);
$total_commits = @commits; $total_commits = @commits;
$total_lines = @all_commits; $total_lines = @all_commits;
if ($email_git_blame_signatures) {
if (vcs_is_hg()) {
my $commit_count;
my @commit_signers = ();
my $commit = join(" -r ", @commits);
my $cmd;
$cmd = $VCS_cmds{"find_commit_signers_cmd"};
$cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
($commit_count, @commit_signers) = vcs_find_signers($cmd);
push(@signers, @commit_signers);
} else {
foreach my $commit (@commits) { foreach my $commit (@commits) {
my $commit_count; my $commit_count;
my @commit_signers = (); my @commit_signers = ();
my $cmd;
my $cmd = $VCS_cmds{"find_commit_signers_cmd"}; $cmd = $VCS_cmds{"find_commit_signers_cmd"};
$cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd $cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
($commit_count, @commit_signers) = vcs_find_signers($cmd); ($commit_count, @commit_signers) = vcs_find_signers($cmd);
push(@signers, @commit_signers); push(@signers, @commit_signers);
} }
}
}
if ($from_filename) { if ($from_filename) {
if ($output_rolestats) { if ($output_rolestats) {
my @blame_signers; my @blame_signers;
if (vcs_is_hg()) {{ # Double brace for last exit
my $commit_count;
my @commit_signers = ();
@commits = uniq(@commits);
@commits = sort(@commits);
my $commit = join(" -r ", @commits);
my $cmd;
$cmd = $VCS_cmds{"find_commit_author_cmd"};
$cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
my @lines = ();
@lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
if (!$email_git_penguin_chiefs) {
@lines = grep(!/${penguin_chiefs}/i, @lines);
}
last if !@lines;
my @authors = ();
foreach my $line (@lines) {
if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
my $author = $1;
my ($name, $address) = parse_email($author);
$author = format_email($name, $address, 1);
push(@authors, $1);
}
}
save_commits_by_author(@lines) if ($interactive);
save_commits_by_signer(@lines) if ($interactive);
push(@signers, @authors);
}}
else {
foreach my $commit (@commits) { foreach my $commit (@commits) {
my $i; my $i;
my $cmd = $VCS_cmds{"find_commit_author_cmd"}; my $cmd = $VCS_cmds{"find_commit_author_cmd"};
...@@ -1393,6 +1713,7 @@ sub vcs_file_blame { ...@@ -1393,6 +1713,7 @@ sub vcs_file_blame {
push(@blame_signers, $author[0]); push(@blame_signers, $author[0]);
} }
} }
}
if (@blame_signers) { if (@blame_signers) {
vcs_assign("authored lines", $total_lines, @blame_signers); vcs_assign("authored lines", $total_lines, @blame_signers);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment