mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: florian@mickler.org, Andrew Morton <akpm@linux-foundation.org>,
	Stephen Hemminger <shemminger@vyatta.com>,
	Wolfram Sang <w.sang@pengutronix.de>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] scripts/get_maintainer.pl: Add --git-blame --rolestats "Authored lines" information
Date: Fri, 10 Sep 2010 17:22:21 -0700	[thread overview]
Message-ID: <1284164541.1783.204.camel@Joe-Laptop> (raw)
In-Reply-To: <1284115665.1783.144.camel@Joe-Laptop>

> > Something based on percentage of the driver written rather than log
> > entry counts might also be interesting.
> There is a --git-blame option, but it uses a count of file commits
> active in the file rather than % of lines authored.

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>
---
 scripts/get_maintainer.pl |   60 ++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 57 insertions(+), 3 deletions(-)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index b228198..a91ae63 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -13,7 +13,7 @@
 use strict;
 
 my $P = $0;
-my $V = '0.24';
+my $V = '0.25';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
@@ -88,6 +88,7 @@ my %VCS_cmds_git = (
     "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}",
@@ -101,6 +102,7 @@ my %VCS_cmds_hg = (
 	"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}",
@@ -1014,6 +1016,9 @@ sub vcs_find_signers {
     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);
 
@@ -1027,6 +1032,28 @@ sub vcs_find_signers {
     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 = ();
@@ -1084,6 +1111,10 @@ sub vcs_blame {
 	@commits = vcs_save_commits($cmd);
     }
 
+    foreach my $commit (@commits) {
+	$commit =~ s/^\^//g;
+    }
+
     return @commits;
 }
 
@@ -1121,6 +1152,8 @@ sub vcs_assign {
 	@lines = mailmap(@lines);
     }
 
+    return if (@lines <= 0);
+
     @lines = sort(@lines);
 
     # uniq -c
@@ -1165,14 +1198,17 @@ sub vcs_file_blame {
     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;
@@ -1182,10 +1218,28 @@ sub vcs_file_blame {
 	$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);



  parent reply	other threads:[~2010-09-11  0:22 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-10  9:33 [PATCH] get_maintainer.pl: append reason for cc to the name by default florian
2010-09-10  9:42 ` Joe Perches
2010-09-10  9:46   ` Wolfram Sang
2010-09-10  9:53   ` Mark Brown
2010-09-10 10:04     ` Joe Perches
2010-09-10 10:18       ` Mark Brown
2010-09-10 10:47         ` Joe Perches
2010-09-10 11:07           ` Mark Brown
2010-09-11  0:22           ` Joe Perches [this message]
2010-09-11  9:38             ` [PATCH] scripts/get_maintainer.pl: Add --git-blame --rolestats "Authored lines" information Florian Mickler
2010-09-11  9:52               ` Joe Perches
2010-09-11 10:02                 ` Florian Mickler
2010-09-11 10:22                   ` Joe Perches
2010-09-11 19:22                   ` [PATCH] Documentation/SubmittingPatches: Add and describe scripts/get_maintainer.pl Joe Perches
2010-09-11 19:34                     ` Florian Mickler
2010-09-11 19:43                     ` [PATCH V2] " Joe Perches
2010-09-12 16:18                       ` Florian Mickler
2010-09-10 11:44         ` [PATCH] get_maintainer.pl: append reason for cc to the name by default Alan Cox
2010-09-10 10:22       ` Florian Mickler
2010-09-10 10:47         ` Joe Perches
2010-09-11 21:22     ` Joe Perches
2010-09-10 10:30   ` Florian Mickler
2010-09-10 11:04     ` Mark Brown
2010-09-10 11:15       ` Florian Mickler
2010-09-10 21:04     ` Andrew Morton
2010-09-10 21:39       ` Florian Mickler
2010-09-10 21:44       ` Joe Perches
2010-09-13  4:01     ` Valdis.Kletnieks
2010-09-13  5:21       ` [PATCH] get_maintainer.pl: Look for .get_maintainer.conf in lk, then $HOME then scripts Joe Perches
2010-09-13  6:13         ` Florian Mickler
2010-09-13 13:21         ` Valdis.Kletnieks
2010-09-10 11:11   ` [PATCH] get_maintainer.pl: append reason for cc to the name by default Florian Mickler
2010-09-10 15:12     ` Joe Perches
2010-09-11  9:34       ` Florian Mickler
2010-09-11  0:13   ` Christoph Hellwig
2010-09-11  0:31     ` Joe Perches
2010-09-11  0:45       ` Christoph Hellwig
2010-09-11  0:56         ` Joe Perches
2010-09-11  9:28         ` Florian Mickler
2010-09-13  7:16           ` Eric W. Biederman
2010-09-13  7:57             ` Joe Perches
2010-09-13  8:54               ` Florian Mickler
2010-09-14 17:19                 ` Eric W. Biederman
2010-09-14 17:46                   ` Florian Mickler
2010-09-15  3:28                     ` Joe Perches
2010-09-15  4:34                       ` Florian Mickler
2010-09-15  4:45                         ` Joe Perches
2010-09-15 12:49                           ` Florian Mickler
2010-09-14 23:15                   ` Joe Perches
2010-09-13  9:01             ` Florian Mickler
2010-09-14 17:24               ` Eric W. Biederman
2010-09-26 18:52 ` RFC: " Joe Perches
2010-09-27 14:57   ` Florian Mickler
2010-09-27 15:44     ` Ted Ts'o
2010-09-27 17:00       ` Florian Mickler
2010-09-27 18:21         ` Ted Ts'o
2010-09-27 19:26           ` Florian Mickler
2010-09-27 20:08             ` Joe Perches
2010-09-27 20:47               ` Ted Ts'o
2010-09-27 21:16                 ` Joe Perches
2010-09-28  4:22                   ` Ted Ts'o
2010-09-28  4:37                   ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1284164541.1783.204.camel@Joe-Laptop \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=florian@mickler.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    --cc=w.sang@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome