Skip to content

Commit 63ab52d

Browse files
JoePerchestorvalds
authored andcommitted
scripts/get_maintainer.pl: Add --git-blame --rolestats "Authored lines" information
When options --git-blame and --rolestats are specified, add the maintainers with the qualifying --git-min-percent amount of lines authored of the complete file. Does not add more authors than specified by --git-max-maintainers. For anyone using hg, this option works but is _very_ slow. It's orders of magnitude slower than git slow. The get_maintainer.pl version was incremented to 0.25. This can be used with or without --git. For instance: $ ./scripts/get_maintainer.pl --git-blame --nogit --rolestats -f lib/bitmap.c Paul Jackson <pj@sgi.com> (authored lines:406/613=66%,commits:7/20=35%) Akinobu Mita <mita@miraclelinux.com> (authored lines:87/613=14%,commits:3/20=15%) Reinette Chatre <reinette.chatre@linux.intel.com> (authored lines:42/613=7%) Andrew Morton <akpm@linux-foundation.org> (commits:16/20=80%) Paul Mundt <lethal@linux-sh.org> (commits:3/20=15%) Randy Dunlap <randy.dunlap@oracle.com> (commits:2/20=10%) $ ./scripts/get_maintainer.pl --git-blame --git --rolestats -f lib/bitmap.c Andrew Morton <akpm@linux-foundation.org> (commit_signer:4/5=80%,commits:16/20=80%) Akinobu Mita <akinobu.mita@gmail.com> (commit_signer:2/5=40%,authored lines:87/613=14%,commits:3/20=15%) Jack Steiner <steiner@sgi.com> (commit_signer:1/5=20%) Ben Hutchings <ben@decadent.org.uk> (commit_signer:1/5=20%) Lee Schermerhorn <lee.schermerhorn@hp.com> (commit_signer:1/5=20%) Paul Jackson <pj@sgi.com> (authored lines:406/613=66%,commits:7/20=35%) Reinette Chatre <reinette.chatre@linux.intel.com> (authored lines:42/613=7%) Paul Mundt <lethal@linux-sh.org> (commits:3/20=15%) Randy Dunlap <randy.dunlap@oracle.com> (commits:2/20=10%) linux-kernel@vger.kernel.org (open list) Signed-off-by: Joe Perches <joe@perches.com> Cc: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b903c0b commit 63ab52d

1 file changed

Lines changed: 57 additions & 3 deletions

File tree

‎scripts/get_maintainer.pl‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use strict;
1414

1515
my $P = $0;
16-
my $V = '0.24';
16+
my $V = '0.25';
1717

1818
use Getopt::Long qw(:config no_auto_abbrev);
1919

@@ -88,6 +88,7 @@
8888
"available" => '(which("git") ne "") && (-d ".git")',
8989
"find_signers_cmd" => "git log --no-color --since=\$email_git_since -- \$file",
9090
"find_commit_signers_cmd" => "git log --no-color -1 \$commit",
91+
"find_commit_author_cmd" => "git log -1 --format=\"%an <%ae>\" \$commit",
9192
"blame_range_cmd" => "git blame -l -L \$diff_start,+\$diff_length \$file",
9293
"blame_file_cmd" => "git blame -l \$file",
9394
"commit_pattern" => "^commit [0-9a-f]{40,40}",
@@ -101,6 +102,7 @@
101102
"hg log --date=\$email_hg_since" .
102103
" --template='commit {node}\\n{desc}\\n' -- \$file",
103104
"find_commit_signers_cmd" => "hg log --template='{desc}\\n' -r \$commit",
105+
"find_commit_author_cmd" => "hg log -l 1 --template='{author}\\n' -r \$commit",
104106
"blame_range_cmd" => "", # not supported
105107
"blame_file_cmd" => "hg blame -c \$file",
106108
"commit_pattern" => "^commit [0-9a-f]{40,40}",
@@ -1014,6 +1016,9 @@ sub vcs_find_signers {
10141016
if (!$email_git_penguin_chiefs) {
10151017
@lines = grep(!/${penguin_chiefs}/i, @lines);
10161018
}
1019+
1020+
return (0, @lines) if !@lines;
1021+
10171022
# cut -f2- -d":"
10181023
s/.*:\s*(.+)\s*/$1/ for (@lines);
10191024

@@ -1027,6 +1032,28 @@ sub vcs_find_signers {
10271032
return ($commits, @lines);
10281033
}
10291034

1035+
sub vcs_find_author {
1036+
my ($cmd) = @_;
1037+
my @lines = ();
1038+
1039+
@lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
1040+
1041+
if (!$email_git_penguin_chiefs) {
1042+
@lines = grep(!/${penguin_chiefs}/i, @lines);
1043+
}
1044+
1045+
return @lines if !@lines;
1046+
1047+
## Reformat email addresses (with names) to avoid badly written signatures
1048+
1049+
foreach my $line (@lines) {
1050+
my ($name, $address) = parse_email($line);
1051+
$line = format_email($name, $address, 1);
1052+
}
1053+
1054+
return @lines;
1055+
}
1056+
10301057
sub vcs_save_commits {
10311058
my ($cmd) = @_;
10321059
my @lines = ();
@@ -1084,6 +1111,10 @@ sub vcs_blame {
10841111
@commits = vcs_save_commits($cmd);
10851112
}
10861113

1114+
foreach my $commit (@commits) {
1115+
$commit =~ s/^\^//g;
1116+
}
1117+
10871118
return @commits;
10881119
}
10891120

@@ -1121,6 +1152,8 @@ sub vcs_assign {
11211152
@lines = mailmap(@lines);
11221153
}
11231154

1155+
return if (@lines <= 0);
1156+
11241157
@lines = sort(@lines);
11251158

11261159
# uniq -c
@@ -1165,14 +1198,17 @@ sub vcs_file_blame {
11651198
my ($file) = @_;
11661199

11671200
my @signers = ();
1201+
my @all_commits = ();
11681202
my @commits = ();
11691203
my $total_commits;
1204+
my $total_lines;
11701205

11711206
return if (!vcs_exists());
11721207

1173-
@commits = vcs_blame($file);
1174-
@commits = uniq(@commits);
1208+
@all_commits = vcs_blame($file);
1209+
@commits = uniq(@all_commits);
11751210
$total_commits = @commits;
1211+
$total_lines = @all_commits;
11761212

11771213
foreach my $commit (@commits) {
11781214
my $commit_count;
@@ -1182,10 +1218,28 @@ sub vcs_file_blame {
11821218
$cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
11831219

11841220
($commit_count, @commit_signers) = vcs_find_signers($cmd);
1221+
11851222
push(@signers, @commit_signers);
11861223
}
11871224

11881225
if ($from_filename) {
1226+
if ($output_rolestats) {
1227+
my @blame_signers;
1228+
foreach my $commit (@commits) {
1229+
my $i;
1230+
my $cmd = $VCS_cmds{"find_commit_author_cmd"};
1231+
$cmd =~ s/(\$\w+)/$1/eeg; #interpolate $cmd
1232+
my @author = vcs_find_author($cmd);
1233+
next if !@author;
1234+
my $count = grep(/$commit/, @all_commits);
1235+
for ($i = 0; $i < $count ; $i++) {
1236+
push(@blame_signers, $author[0]);
1237+
}
1238+
}
1239+
if (@blame_signers) {
1240+
vcs_assign("authored lines", $total_lines, @blame_signers);
1241+
}
1242+
}
11891243
vcs_assign("commits", $total_commits, @signers);
11901244
} else {
11911245
vcs_assign("modified commits", $total_commits, @signers);

0 commit comments

Comments
 (0)