From: Joe Perches <joe@perches.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
Julia Lawall <julia@diku.dk>, Greg KH <greg@kroah.com>
Subject: [PATCH 4/7] scripts/get_maintainer.pl: Better email routines, use perl not shell where possible
Date: Wed, 5 Aug 2009 19:43:45 -0700 [thread overview]
Message-ID: <41e625dc1cf63389b43120dbd2f7930dcda0d006.1249525834.git.joe@perches.com> (raw)
In-Reply-To: <cover.1249525834.git.joe@perches.com>
Added format_email and parse_email routines to reduce inline use.
Added email_address_inuse to eliminate multiple maintainer entries
for the same email address, the first name encountered is used.
Used internal perl equivalents of shell cmd use of grep|cut|sort|uniq
Signed-off-by: Joe Perches <joe@perches.com>
---
scripts/get_maintainer.pl | 154 ++++++++++++++++++++++++++++-----------------
1 files changed, 97 insertions(+), 57 deletions(-)
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 5132949..969c8fd 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -13,7 +13,7 @@
use strict;
my $P = $0;
-my $V = '0.19';
+my $V = '0.20';
use Getopt::Long qw(:config no_auto_abbrev);
@@ -258,11 +258,8 @@ if ($email) {
foreach my $chief (@penguin_chief) {
if ($chief =~ m/^(.*):(.*)/) {
my $email_address;
- if ($email_usename) {
- $email_address = format_email($1, $2);
- } else {
- $email_address = $2;
- }
+
+ $email_address = format_email($1, $2);
if ($email_git_penguin_chiefs) {
push(@email_to, $email_address);
} else {
@@ -400,21 +397,57 @@ sub top_of_kernel_tree {
return 0;
}
-sub format_email {
- my ($name, $email) = @_;
+sub parse_email {
+ my ($formatted_email) = @_;
+
+ my $name = "";
+ my $address = "";
+
+ if ($formatted_email =~ /^([^<]+)<(.*\@.*)>$/) {
+ $name = $1;
+ $address = $2;
+ } elsif ($formatted_email =~ /^<(.*\@.*)>$/) {
+ $address = $1;
+ } elsif ($formatted_email =~ /^(.*\@.*)$/) {
+ $address = $1;
+ }
$name =~ s/^\s+|\s+$//g;
$name =~ s/^\"|\"$//g;
- $email =~ s/^\s+|\s+$//g;
+ $address =~ s/^\s+|\s+$//g;
- my $formatted_email = "";
+ if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
+ $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
+ $name = "\"$name\"";
+ }
+
+ return ($name, $address);
+}
+
+sub format_email {
+ my ($name, $address) = @_;
+
+ my $formatted_email;
+
+ $name =~ s/^\s+|\s+$//g;
+ $name =~ s/^\"|\"$//g;
+ $address =~ s/^\s+|\s+$//g;
if ($name =~ /[^a-z0-9 \.\-]/i) { ##has "must quote" chars
$name =~ s/(?<!\\)"/\\"/g; ##escape quotes
- $formatted_email = "\"${name}\"\ \<${email}\>";
+ $name = "\"$name\"";
+ }
+
+ if ($email_usename) {
+ if ("$name" eq "") {
+ $formatted_email = "$address";
+ } else {
+ $formatted_email = "$name <${address}>";
+ }
} else {
- $formatted_email = "${name} \<${email}\>";
+ $formatted_email = $address;
}
+
return $formatted_email;
}
@@ -444,19 +477,18 @@ sub add_categories {
}
}
} elsif ($ptype eq "M") {
- my $p_used = 0;
- if ($index >= 0) {
- my $tv = $typevalue[$index - 1];
- if ($tv =~ m/^(\C):\s*(.*)/) {
- if ($1 eq "P") {
- if ($email_usename) {
- push_email_address(format_email($2, $pvalue));
- $p_used = 1;
+ my ($name, $address) = parse_email($pvalue);
+ if ($name eq "") {
+ if ($index >= 0) {
+ my $tv = $typevalue[$index - 1];
+ if ($tv =~ m/^(\C):\s*(.*)/) {
+ if ($1 eq "P") {
+ $name = $2;
}
}
}
}
- if (!$p_used) {
+ if ($email_maintainer) {
push_email_addresses($pvalue);
}
} elsif ($ptype eq "T") {
@@ -475,29 +507,27 @@ sub add_categories {
}
}
+sub email_address_inuse {
+ my ($test_address) = @_;
+
+ foreach my $line (@email_to) {
+ my ($name, $address) = parse_email($line);
+
+ return 1 if ($address eq $test_address);
+ }
+ return 0;
+}
+
sub push_email_address {
- my ($email_address) = @_;
+ my ($line) = @_;
- my $email_name = "";
+ my ($name, $address) = parse_email($line);
- if ($email_maintainer) {
- if ($email_address =~ m/([^<]+)<(.*\@.*)>$/) {
- $email_name = $1;
- $email_address = $2;
- if ($email_usename) {
- push(@email_to, format_email($email_name, $email_address));
- } else {
- push(@email_to, $email_address);
- }
- } elsif ($email_address =~ m/<(.+)>/) {
- $email_address = $1;
- push(@email_to, $email_address);
- } else {
- push(@email_to, $email_address);
- }
+ if (!email_address_inuse($address)) {
+ push(@email_to, format_email($name, $address));
}
}
-
+
sub push_email_addresses {
my ($address) = @_;
@@ -535,6 +565,7 @@ sub recent_git_signoffs {
my $output = "";
my $count = 0;
my @lines = ();
+ my %hash;
my $total_sign_offs;
if (which("git") eq "") {
@@ -548,25 +579,31 @@ sub recent_git_signoffs {
}
$cmd = "git log --since=${email_git_since} -- ${file}";
- $cmd .= " | grep -Ei \"^[-_ a-z]+by:.*\\\@.*\$\"";
- if (!$email_git_penguin_chiefs) {
- $cmd .= " | grep -Ev \"${penguin_chiefs}\"";
- }
- $cmd .= " | cut -f2- -d\":\"";
- $cmd .= " | sort | uniq -c | sort -rn";
$output = `${cmd}`;
$output =~ s/^\s*//gm;
@lines = split("\n", $output);
- $total_sign_offs = 0;
+ @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines);
+ if (!$email_git_penguin_chiefs) {
+ @lines = grep(!/${penguin_chiefs}/i, @lines);
+ }
+ # cut -f2- -d":"
+ s/.*:\s*(.+)\s*/$1/ for (@lines);
+
+ @lines = mailmap(@lines);
+
+ $total_sign_offs = @lines;
+ @lines = sort(@lines);
+ # uniq -c
foreach my $line (@lines) {
- if ($line =~ m/([0-9]+)\s+(.*)/) {
- $total_sign_offs += $1;
- } else {
- die("$P: Unexpected git output: ${line}\n");
- }
+ $hash{$line}++;
+ }
+ # sort -rn
+ @lines = ();
+ foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
+ push(@lines,"$hash{$line} $line");
}
foreach my $line (@lines) {
@@ -579,8 +616,8 @@ sub recent_git_signoffs {
$sign_offs * 100 / $total_sign_offs < $email_git_min_percent) {
last;
}
+ push_email_address($line);
}
- push_email_address($line);
}
}
@@ -632,15 +669,18 @@ sub git_assign_blame {
@commits = uniq(@commits);
foreach my $commit (@commits) {
$cmd = "git log -1 ${commit}";
- $cmd .= " | grep -Ei \"^[-_ a-z]+by:.*\\\@.*\$\"";
- if (!$email_git_penguin_chiefs) {
- $cmd .= " | grep -Ev \"${penguin_chiefs}\"";
- }
- $cmd .= " | cut -f2- -d\":\"";
$output = `${cmd}`;
$output =~ s/^\s*//gm;
@lines = split("\n", $output);
+
+ @lines = grep(/^[-_ a-z]+by:.*\@.*$/i, @lines);
+ if (!$email_git_penguin_chiefs) {
+ @lines = grep(!/${penguin_chiefs}/i, @lines);
+ }
+ # cut -f2- -d":"
+ s/.*:\s*(.+)\s*/$1/ for (@lines);
+
$hash{$_}++ for @lines;
$total_sign_offs += @lines;
}
--
1.6.3.1.10.g659a0.dirty
next prev parent reply other threads:[~2009-08-06 2:43 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-06 2:43 [PATCH 0/7] scripts/get_maintainer.pl: New features Joe Perches
2009-08-06 2:43 ` [PATCH 1/7] scripts/get_maintainer.pl: Add --git-blame Joe Perches
2009-08-06 2:43 ` [PATCH 2/7] scripts/get_maintainer.pl: Add sections in pattern match depth order Joe Perches
2009-08-06 3:51 ` Greg KH
2009-08-06 2:43 ` [PATCH 3/7] scripts/get_maintainer.pl: Add --pattern-depth Joe Perches
2009-08-06 2:43 ` Joe Perches [this message]
2009-08-06 2:43 ` [PATCH 5/7] scripts/get_maintainer.pl: Add .mailmap use, shell and email cleanups Joe Perches
2009-08-06 2:43 ` [PATCH 6/7] scripts/get_maintainer.pl: Using --separator implies --nomultiline Joe Perches
2009-08-06 2:43 ` [PATCH 7/7] scripts/get_maintainer.pl: Add --remove-duplicates Joe Perches
2009-08-06 3:54 ` [PATCH 0/7] scripts/get_maintainer.pl: New features Greg KH
2009-08-26 21:48 ` [PATCH] scripts/get_maintainer.pl: Add maintainers in order listed in matched section Joe Perches
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=41e625dc1cf63389b43120dbd2f7930dcda0d006.1249525834.git.joe@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=greg@kroah.com \
--cc=julia@diku.dk \
--cc=linux-kernel@vger.kernel.org \
/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
all inboxes | Powered by JetHome®