scripts/get_maintainer.pl: warn on missing git or git repository
[sfrench/cifs-2.6.git] / scripts / get_maintainer.pl
index 60dc0c48c929b15953a751a1875c1aebd767e80e..22c7f4e740f1bce1313c1a79806a404d8d915d3d 100755 (executable)
@@ -13,7 +13,7 @@
 use strict;
 
 my $P = $0;
-my $V = '0.15';
+my $V = '0.16';
 
 use Getopt::Long qw(:config no_auto_abbrev);
 
@@ -169,6 +169,7 @@ foreach my $file (@ARGV) {
 }
 
 my @email_to = ();
+my @list_to = ();
 my @scm = ();
 my @web = ();
 my @subsystem = ();
@@ -182,7 +183,7 @@ foreach my $file (@files) {
 
     my $exclude = 0;
     foreach my $line (@typevalue) {
-       if ($line =~ m/^(\C):(.*)/) {
+       if ($line =~ m/^(\C):\s*(.*)/) {
            my $type = $1;
            my $value = $2;
            if ($type eq 'X') {
@@ -196,7 +197,7 @@ foreach my $file (@files) {
     if (!$exclude) {
        my $tvi = 0;
        foreach my $line (@typevalue) {
-           if ($line =~ m/^(\C):(.*)/) {
+           if ($line =~ m/^(\C):\s*(.*)/) {
                my $type = $1;
                my $value = $2;
                if ($type eq 'F') {
@@ -215,29 +216,33 @@ foreach my $file (@files) {
 
 }
 
-if ($email_git_penguin_chiefs) {
+if ($email) {
     foreach my $chief (@penguin_chief) {
        if ($chief =~ m/^(.*):(.*)/) {
-           my $chief_name = $1;
-           my $chief_addr = $2;
+           my $email_address;
            if ($email_usename) {
-               push(@email_to, format_email($chief_name, $chief_addr));
+               $email_address = format_email($1, $2);
+           } else {
+               $email_address = $2;
+           }
+           if ($email_git_penguin_chiefs) {
+               push(@email_to, $email_address);
            } else {
-               push(@email_to, $chief_addr);
+               @email_to = grep(!/${email_address}/, @email_to);
            }
        }
     }
 }
 
-if ($email) {
-    my $address_cnt = @email_to;
-    if ($address_cnt == 0 && $email_list) {
-       push(@email_to, "linux-kernel\@vger.kernel.org");
+if ($email || $email_list) {
+    my @to = ();
+    if ($email) {
+       @to = (@to, @email_to);
     }
-
-#Don't sort email address list, but do remove duplicates
-    @email_to = uniq(@email_to);
-    output(@email_to);
+    if ($email_list) {
+       @to = (@to, @list_to);
+    }
+    output(uniq(@to));
 }
 
 if ($scm) {
@@ -307,10 +312,10 @@ Output type options:
   --multiline => print 1 entry per line
 
 Default options:
-  [--email --git --m --l --multiline]
+  [--email --git --m --n --l --multiline]
 
 Other options:
-  --version -> show version
+  --version => show version
   --help => show this help information
 
 EOT
@@ -366,26 +371,30 @@ sub add_categories {
     $index = $index - 1;
     while ($index >= 0) {
        my $tv = $typevalue[$index];
-       if ($tv =~ m/^(\C):(.*)/) {
+       if ($tv =~ m/^(\C):\s*(.*)/) {
            my $ptype = $1;
            my $pvalue = $2;
            if ($ptype eq "L") {
-               my $subscr = $pvalue;
-               if ($subscr =~ m/\s*\(subscribers-only\)/) {
+               my $list_address = $pvalue;
+               my $list_additional = "";
+               if ($list_address =~ m/([^\s]+)\s+(.*)$/) {
+                   $list_address = $1;
+                   $list_additional = $2;
+               }
+               if ($list_additional =~ m/subscribers-only/) {
                    if ($email_subscriber_list) {
-                       $subscr =~ s/\s*\(subscribers-only\)//g;
-                       push(@email_to, $subscr);
+                       push(@list_to, $list_address);
                    }
                } else {
                    if ($email_list) {
-                       push(@email_to, $pvalue);
+                       push(@list_to, $list_address);
                    }
                }
            } elsif ($ptype eq "M") {
                if ($email_maintainer) {
                    if ($index >= 0) {
                        my $tv = $typevalue[$index - 1];
-                       if ($tv =~ m/^(\C):(.*)/) {
+                       if ($tv =~ m/^(\C):\s*(.*)/) {
                            if ($1 eq "P" && $email_usename) {
                                push(@email_to, format_email($2, $pvalue));
                            } else {
@@ -415,7 +424,7 @@ sub add_categories {
 sub which {
     my ($bin) = @_;
 
-    foreach my $path (split /:/, $ENV{PATH}) {
+    foreach my $path (split(/:/, $ENV{PATH})) {
        if (-e "$path/$bin") {
            return "$path/$bin";
        }
@@ -434,16 +443,22 @@ sub recent_git_signoffs {
     my @lines = ();
 
     if (which("git") eq "") {
-       die("$P: git not found.  Add --nogit to options?\n");
+       warn("$P: git not found.  Add --nogit to options?\n");
+       return;
+    }
+    if (!(-d ".git")) {
+       warn("$P: .git repository not found.\n");
+       warn("Use a .git repository for better results.\n");
+       warn("ie: git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git\n");
+       return;
     }
 
     $cmd = "git log --since=${email_git_since} -- ${file}";
-    $cmd .= " | grep -Pi \"^[-_        a-z]+by:.*\\\@\"";
+    $cmd .= " | grep -Ei \"^[-_        a-z]+by:.*\\\@.*\$\"";
     if (!$email_git_penguin_chiefs) {
-       $cmd .= " | grep -Pv \"${penguin_chiefs}\"";
+       $cmd .= " | grep -Ev \"${penguin_chiefs}\"";
     }
     $cmd .= " | cut -f2- -d\":\"";
-    $cmd .= " | sed -e \"s/^\\s+//g\"";
     $cmd .= " | sort | uniq -c | sort -rn";
 
     $output = `${cmd}`;
@@ -481,7 +496,6 @@ sub recent_git_signoffs {
            push(@email_to, $line);
        }
     }
-    return $output;
 }
 
 sub uniq {