Skip to content

Commit c9ecefe

Browse files
JoePerchestorvalds
authored andcommitted
get_maintainer: add commit author information to --rolestats
get_maintainer currently uses "Signed-off-by" style lines to find interested parties to send patches to when the MAINTAINERS file does not have a specific section entry with a matching file pattern. Add statistics for commit authors and lines added and deleted to the information provided by --rolestats. These statistics are also emitted whenever --rolestats and --git are selected even when there is a specified maintainer. This can have the effect of expanding the number of people that are shown as possible "maintainers" of a particular file because "authors", "added_lines", and "removed_lines" are also used as criterion for the --max-maintainers option separate from the "commit_signers". The first "--git-max-maintainers" values of each criterion are emitted. Any "ties" are not shown. For example: (forcedeth does not have a named maintainer) Old output: $ ./scripts/get_maintainer.pl -f drivers/net/ethernet/nvidia/forcedeth.c "David S. Miller" <davem@davemloft.net> (commit_signer:8/10=80%) Jiri Pirko <jiri@resnulli.us> (commit_signer:2/10=20%) Patrick McHardy <kaber@trash.net> (commit_signer:2/10=20%) Larry Finger <Larry.Finger@lwfinger.net> (commit_signer:1/10=10%) Peter Zijlstra <peterz@infradead.org> (commit_signer:1/10=10%) netdev@vger.kernel.org (open list:NETWORKING DRIVERS) linux-kernel@vger.kernel.org (open list) New output: $ ./scripts/get_maintainer.pl -f drivers/net/ethernet/nvidia/forcedeth.c "David S. Miller" <davem@davemloft.net> (commit_signer:8/10=80%) Jiri Pirko <jiri@resnulli.us> (commit_signer:2/10=20%,authored:2/10=20%,removed_lines:3/33=9%) Patrick McHardy <kaber@trash.net> (commit_signer:2/10=20%,authored:2/10=20%,added_lines:12/95=13%,removed_lines:10/33=30%) Larry Finger <Larry.Finger@lwfinger.net> (commit_signer:1/10=10%,authored:1/10=10%,added_lines:35/95=37%) Peter Zijlstra <peterz@infradead.org> (commit_signer:1/10=10%) "Peter Hüwe" <PeterHuewe@gmx.de> (authored:1/10=10%,removed_lines:15/33=45%) Joe Perches <joe@perches.com> (authored:1/10=10%) Neil Horman <nhorman@tuxdriver.com> (added_lines:40/95=42%) Bill Pemberton <wfp5p@virginia.edu> (removed_lines:3/33=9%) netdev@vger.kernel.org (open list:NETWORKING DRIVERS) linux-kernel@vger.kernel.org (open list) Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1d3fa37 commit c9ecefe

1 file changed

Lines changed: 85 additions & 6 deletions

File tree

‎scripts/get_maintainer.pl‎

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"available" => '(which("git") ne "") && (-d ".git")',
9999
"find_signers_cmd" =>
100100
"git log --no-color --follow --since=\$email_git_since " .
101+
'--numstat --no-merges ' .
101102
'--format="GitCommit: %H%n' .
102103
'GitAuthor: %an <%ae>%n' .
103104
'GitDate: %aD%n' .
@@ -106,6 +107,7 @@
106107
" -- \$file",
107108
"find_commit_signers_cmd" =>
108109
"git log --no-color " .
110+
'--numstat ' .
109111
'--format="GitCommit: %H%n' .
110112
'GitAuthor: %an <%ae>%n' .
111113
'GitDate: %aD%n' .
@@ -114,6 +116,7 @@
114116
" -1 \$commit",
115117
"find_commit_author_cmd" =>
116118
"git log --no-color " .
119+
'--numstat ' .
117120
'--format="GitCommit: %H%n' .
118121
'GitAuthor: %an <%ae>%n' .
119122
'GitDate: %aD%n' .
@@ -125,6 +128,7 @@
125128
"blame_commit_pattern" => "^([0-9a-f]+) ",
126129
"author_pattern" => "^GitAuthor: (.*)",
127130
"subject_pattern" => "^GitSubject: (.*)",
131+
"stat_pattern" => "^(\\d+)\\t(\\d+)\\t\$file\$",
128132
);
129133

130134
my %VCS_cmds_hg = (
@@ -152,6 +156,7 @@
152156
"blame_commit_pattern" => "^([ 0-9a-f]+):",
153157
"author_pattern" => "^HgAuthor: (.*)",
154158
"subject_pattern" => "^HgSubject: (.*)",
159+
"stat_pattern" => "^(\\d+)\t(\\d+)\t\$file\$",
155160
);
156161

157162
my $conf = which_conf(".get_maintainer.conf");
@@ -1269,20 +1274,30 @@ sub extract_formatted_signatures {
12691274
}
12701275

12711276
sub vcs_find_signers {
1272-
my ($cmd) = @_;
1277+
my ($cmd, $file) = @_;
12731278
my $commits;
12741279
my @lines = ();
12751280
my @signatures = ();
1281+
my @authors = ();
1282+
my @stats = ();
12761283

12771284
@lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
12781285

12791286
my $pattern = $VCS_cmds{"commit_pattern"};
1287+
my $author_pattern = $VCS_cmds{"author_pattern"};
1288+
my $stat_pattern = $VCS_cmds{"stat_pattern"};
1289+
1290+
$stat_pattern =~ s/(\$\w+)/$1/eeg; #interpolate $stat_pattern
12801291

12811292
$commits = grep(/$pattern/, @lines); # of commits
12821293

1294+
@authors = grep(/$author_pattern/, @lines);
12831295
@signatures = grep(/^[ \t]*${signature_pattern}.*\@.*$/, @lines);
1296+
@stats = grep(/$stat_pattern/, @lines);
12841297

1285-
return (0, @signatures) if !@signatures;
1298+
# print("stats: <@stats>\n");
1299+
1300+
return (0, \@signatures, \@authors, \@stats) if !@signatures;
12861301

12871302
save_commits_by_author(@lines) if ($interactive);
12881303
save_commits_by_signer(@lines) if ($interactive);
@@ -1291,9 +1306,10 @@ sub vcs_find_signers {
12911306
@signatures = grep(!/${penguin_chiefs}/i, @signatures);
12921307
}
12931308

1309+
my ($author_ref, $authors_ref) = extract_formatted_signatures(@authors);
12941310
my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
12951311

1296-
return ($commits, @$signers_ref);
1312+
return ($commits, $signers_ref, $authors_ref, \@stats);
12971313
}
12981314

12991315
sub vcs_find_author {
@@ -1849,7 +1865,12 @@ sub vcs_assign {
18491865
sub vcs_file_signoffs {
18501866
my ($file) = @_;
18511867

1868+
my $authors_ref;
1869+
my $signers_ref;
1870+
my $stats_ref;
1871+
my @authors = ();
18521872
my @signers = ();
1873+
my @stats = ();
18531874
my $commits;
18541875

18551876
$vcs_used = vcs_exists();
@@ -1858,13 +1879,59 @@ sub vcs_file_signoffs {
18581879
my $cmd = $VCS_cmds{"find_signers_cmd"};
18591880
$cmd =~ s/(\$\w+)/$1/eeg; # interpolate $cmd
18601881

1861-
($commits, @signers) = vcs_find_signers($cmd);
1882+
($commits, $signers_ref, $authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
1883+
1884+
@signers = @{$signers_ref} if defined $signers_ref;
1885+
@authors = @{$authors_ref} if defined $authors_ref;
1886+
@stats = @{$stats_ref} if defined $stats_ref;
1887+
1888+
# print("commits: <$commits>\nsigners:<@signers>\nauthors: <@authors>\nstats: <@stats>\n");
18621889

18631890
foreach my $signer (@signers) {
18641891
$signer = deduplicate_email($signer);
18651892
}
18661893

18671894
vcs_assign("commit_signer", $commits, @signers);
1895+
vcs_assign("authored", $commits, @authors);
1896+
if ($#authors == $#stats) {
1897+
my $stat_pattern = $VCS_cmds{"stat_pattern"};
1898+
$stat_pattern =~ s/(\$\w+)/$1/eeg; #interpolate $stat_pattern
1899+
1900+
my $added = 0;
1901+
my $deleted = 0;
1902+
for (my $i = 0; $i <= $#stats; $i++) {
1903+
if ($stats[$i] =~ /$stat_pattern/) {
1904+
$added += $1;
1905+
$deleted += $2;
1906+
}
1907+
}
1908+
my @tmp_authors = uniq(@authors);
1909+
foreach my $author (@tmp_authors) {
1910+
$author = deduplicate_email($author);
1911+
}
1912+
@tmp_authors = uniq(@tmp_authors);
1913+
my @list_added = ();
1914+
my @list_deleted = ();
1915+
foreach my $author (@tmp_authors) {
1916+
my $auth_added = 0;
1917+
my $auth_deleted = 0;
1918+
for (my $i = 0; $i <= $#stats; $i++) {
1919+
if ($author eq deduplicate_email($authors[$i]) &&
1920+
$stats[$i] =~ /$stat_pattern/) {
1921+
$auth_added += $1;
1922+
$auth_deleted += $2;
1923+
}
1924+
}
1925+
for (my $i = 0; $i < $auth_added; $i++) {
1926+
push(@list_added, $author);
1927+
}
1928+
for (my $i = 0; $i < $auth_deleted; $i++) {
1929+
push(@list_deleted, $author);
1930+
}
1931+
}
1932+
vcs_assign("added_lines", $added, @list_added);
1933+
vcs_assign("removed_lines", $deleted, @list_deleted);
1934+
}
18681935
}
18691936

18701937
sub vcs_file_blame {
@@ -1887,26 +1954,38 @@ sub vcs_file_blame {
18871954
if ($email_git_blame_signatures) {
18881955
if (vcs_is_hg()) {
18891956
my $commit_count;
1957+
my $commit_authors_ref;
1958+
my $commit_signers_ref;
1959+
my $stats_ref;
1960+
my @commit_authors = ();
18901961
my @commit_signers = ();
18911962
my $commit = join(" -r ", @commits);
18921963
my $cmd;
18931964

18941965
$cmd = $VCS_cmds{"find_commit_signers_cmd"};
18951966
$cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
18961967

1897-
($commit_count, @commit_signers) = vcs_find_signers($cmd);
1968+
($commit_count, $commit_signers_ref, $commit_authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
1969+
@commit_authors = @{$commit_authors_ref} if defined $commit_authors_ref;
1970+
@commit_signers = @{$commit_signers_ref} if defined $commit_signers_ref;
18981971

18991972
push(@signers, @commit_signers);
19001973
} else {
19011974
foreach my $commit (@commits) {
19021975
my $commit_count;
1976+
my $commit_authors_ref;
1977+
my $commit_signers_ref;
1978+
my $stats_ref;
1979+
my @commit_authors = ();
19031980
my @commit_signers = ();
19041981
my $cmd;
19051982

19061983
$cmd = $VCS_cmds{"find_commit_signers_cmd"};
19071984
$cmd =~ s/(\$\w+)/$1/eeg; #substitute variables in $cmd
19081985

1909-
($commit_count, @commit_signers) = vcs_find_signers($cmd);
1986+
($commit_count, $commit_signers_ref, $commit_authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
1987+
@commit_authors = @{$commit_authors_ref} if defined $commit_authors_ref;
1988+
@commit_signers = @{$commit_signers_ref} if defined $commit_signers_ref;
19101989

19111990
push(@signers, @commit_signers);
19121991
}

0 commit comments

Comments
 (0)