Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 164510
b: refs/heads/master
c: f549266
h: refs/heads/master
v: v3
  • Loading branch information
Joe Perches authored and Linus Torvalds committed Sep 22, 2009
1 parent be0c12a commit 5474d7e
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b61d4a71e483fe1aa1c4b170c28d85be77edce4f
refs/heads/master: f5492666a3b62344de9026a960c11888160362c9
138 changes: 109 additions & 29 deletions trunk/scripts/get_maintainer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use strict;

my $P = $0;
my $V = '0.17';
my $V = '0.18beta2';

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

Expand All @@ -29,6 +29,7 @@
my $email_git_max_maintainers = 5;
my $email_git_min_percent = 5;
my $email_git_since = "1-year-ago";
my $email_git_blame = 0;
my $output_multiline = 1;
my $output_separator = ", ";
my $scm = 0;
Expand Down Expand Up @@ -68,6 +69,7 @@
'git-max-maintainers=i' => \$email_git_max_maintainers,
'git-min-percent=i' => \$email_git_min_percent,
'git-since=s' => \$email_git_since,
'git-blame!' => \$email_git_blame,
'm!' => \$email_maintainer,
'n!' => \$email_usename,
'l!' => \$email_list,
Expand Down Expand Up @@ -107,8 +109,9 @@
die "$P: Missing required option: email, scm, status, subsystem or web\n";
}

if ($email && ($email_maintainer + $email_list + $email_subscriber_list
+ $email_git + $email_git_penguin_chiefs) == 0) {
if ($email &&
($email_maintainer + $email_list + $email_subscriber_list +
$email_git + $email_git_penguin_chiefs + $email_git_blame) == 0) {
usage();
die "$P: Please select at least 1 email option\n";
}
Expand Down Expand Up @@ -150,6 +153,7 @@
## use the filenames on the command line or find the filenames in the patchfiles

my @files = ();
my @range = ();

foreach my $file (@ARGV) {
##if $file is a directory and it lacks a trailing slash, add one
Expand All @@ -162,13 +166,19 @@
push(@files, $file);
} else {
my $file_cnt = @files;
my $lastfile;
open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
while (<PATCH>) {
if (m/^\+\+\+\s+(\S+)/) {
my $filename = $1;
$filename =~ s@^[^/]*/@@;
$filename =~ s@\n@@;
$lastfile = $filename;
push(@files, $filename);
} elsif (m/^\@\@ -(\d+),(\d+)/) {
if ($email_git_blame) {
push(@range, "$lastfile:$1:$2");
}
}
}
close(PATCH);
Expand Down Expand Up @@ -226,6 +236,9 @@
recent_git_signoffs($file);
}

if ($email && $email_git_blame) {
git_assign_blame($file);
}
}

if ($email) {
Expand Down Expand Up @@ -311,6 +324,7 @@ sub usage {
--git-max-maintainers => maximum maintainers to add (default: 5)
--git-min-percent => minimum percentage of commits required (default: 5)
--git-since => git history to use (default: 1-year-ago)
--git-blame => use git blame to find modified commits for patch or file
--m => include maintainer(s) if any
--n => include name 'Full Name <addr\@domain.tld>'
--l => include list(s) if any
Expand All @@ -333,13 +347,15 @@ sub usage {
Notes:
Using "-f directory" may give unexpected results:
Used with "--git", git signators for _all_ files in and below
directory are examined as git recurses directories.
Any specified X: (exclude) pattern matches are _not_ ignored.
Used with "--nogit", directory is used as a pattern match,
no individual file within the directory or subdirectory
is matched.
Used with "--git", git signators for _all_ files in and below
directory are examined as git recurses directories.
Any specified X: (exclude) pattern matches are _not_ ignored.
Used with "--nogit", directory is used as a pattern match,
no individual file within the directory or subdirectory
is matched.
Used with "--git-blame", does not iterate all files in directory
Using "--git-blame" is slow and may add old committers and authors
that are no longer active maintainers to the output.
EOT
}

Expand Down Expand Up @@ -449,14 +465,19 @@ sub push_email_address {
my ($email_address) = @_;

my $email_name = "";
if ($email_address =~ m/([^<]+)<(.*\@.*)>$/) {
$email_name = $1;
$email_address = $2;
}

if ($email_maintainer) {
if ($email_usename && $email_name) {
push(@email_to, format_email($email_name, $email_address));
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);
}
Expand Down Expand Up @@ -545,20 +566,79 @@ sub recent_git_signoffs {
last;
}
}
if ($line =~ m/(.+)<(.+)>/) {
my $git_name = $1;
my $git_addr = $2;
if ($email_usename) {
push(@email_to, format_email($git_name, $git_addr));
} else {
push(@email_to, $git_addr);
}
} elsif ($line =~ m/<(.+)>/) {
my $git_addr = $1;
push(@email_to, $git_addr);
} else {
push(@email_to, $line);
push_email_address($line);
}
}

sub save_commits {
my ($cmd, @commits) = @_;
my $output;
my @lines = ();

$output = `${cmd}`;

@lines = split("\n", $output);
foreach my $line (@lines) {
if ($line =~ m/^(\w+) /) {
push (@commits, $1);
}
}
return @commits;
}

sub git_assign_blame {
my ($file) = @_;

my @lines = ();
my @commits = ();
my $cmd;
my $output;
my %hash;
my $total_sign_offs;
my $count;

if (@range) {
foreach my $file_range_diff (@range) {
next if (!($file_range_diff =~ m/(.+):(.+):(.+)/));
my $diff_file = $1;
my $diff_start = $2;
my $diff_length = $3;
next if (!("$file" eq "$diff_file"));
$cmd = "git blame -l -L $diff_start,+$diff_length $file\n";
@commits = save_commits($cmd, @commits);
}
} else {
if (-f $file) {
$cmd = "git blame -l $file\n";
@commits = save_commits($cmd, @commits);
}
}

$total_sign_offs = 0;
@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);
$hash{$_}++ for @lines;
$total_sign_offs += @lines;
}

$count = 0;
foreach my $line (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
my $sign_offs = $hash{$line};
$count++;
last if ($sign_offs < $email_git_min_signatures ||
$count > $email_git_max_maintainers ||
$sign_offs * 100 / $total_sign_offs < $email_git_min_percent);
push_email_address($line);
}
}

Expand Down

0 comments on commit 5474d7e

Please sign in to comment.