All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH 3/4] get_maintainer: use array for defining available version control
Date: Mon, 26 May 2014 13:33:12 -0700	[thread overview]
Message-ID: <20140526203356.233948409@networkplumber.org> (raw)
In-Reply-To: 20140526203309.782169359@networkplumber.org

[-- Attachment #1: get-maintainer-array.patch --]
[-- Type: text/plain, Size: 8669 bytes --]

Changes which cleanup how multiple version control systems are
handled:
 * Rather than hardcoding the test for version control, use an array
   of available version control systems and label each one.
 * Instead of copying the hash of current version control, use a reference to
   get the current version control.
 * Remove unnecessary quoting on the label of the hash

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>


--- a/scripts/get_maintainer.pl	2014-05-26 13:14:14.264500168 -0700
+++ b/scripts/get_maintainer.pl	2014-05-26 13:27:47.000000000 -0700
@@ -53,7 +53,7 @@ my $pattern_depth = 0;
 my $version = 0;
 my $help = 0;
 
-my $vcs_used = 0;
+my $vcs_used;	# undef
 
 my $exit = 0;
 
@@ -90,10 +90,8 @@ my $rfc822_lwsp = "(?:(?:\\r\\n)?[ \\t])
 my $rfc822_char = '[\\000-\\377]';
 
 # VCS command support: class-like functions and strings
-
-my %VCS_cmds;
-
 my %VCS_cmds_git = (
+    name	=> 'git',
     execute_cmd => \&git_execute_cmd,
     available   => '(which("git") ne "") && (-e ".git")',
 
@@ -129,6 +127,7 @@ my %VCS_cmds_git = (
 );
 
 my %VCS_cmds_hg = (
+    name	=> 'hg',
     execute_cmd => \&hg_execute_cmd,
     available   => '(which("hg") ne "" ) && ( -d ".hg" )',
     find_signers_cmd => "hg log --date=\$email_hg_since "
@@ -152,6 +151,7 @@ my %VCS_cmds_hg = (
     subject_pattern      => "^HgSubject: (.*)",
     stat_pattern         => "^(\\d+)\t(\\d+)\t\$file\$",
 );
+my @VCS_avail = ( \%VCS_cmds_git, \%VCS_cmds_hg );
 
 my $conf = which_conf(".get_maintainer.conf");
 if (-f $conf) {
@@ -1275,11 +1275,11 @@ sub vcs_find_signers {
     my @authors = ();
     my @stats = ();
 
-    @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
+    @lines = &{$vcs_used->{execute_cmd}}($cmd);
 
-    my $pattern = $VCS_cmds{"commit_pattern"};
-    my $author_pattern = $VCS_cmds{"author_pattern"};
-    my $stat_pattern = $VCS_cmds{"stat_pattern"};
+    my $pattern = $vcs_used->{commit_pattern};
+    my $author_pattern = $vcs_used->{author_pattern};
+    my $stat_pattern = $vcs_used->{stat_pattern};
 
     $stat_pattern =~ s/(\$\w+)/$1/eeg;		#interpolate $stat_pattern
 
@@ -1310,7 +1310,7 @@ sub vcs_find_author {
     my ($cmd) = @_;
     my @lines = ();
 
-    @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
+    @lines = &{$vcs_used->{execute_cmd}}($cmd);
 
     if (!$email_git_penguin_chiefs) {
 	@lines = grep(!/${penguin_chiefs}/i, @lines);
@@ -1320,7 +1320,7 @@ sub vcs_find_author {
 
     my @authors = ();
     foreach my $line (@lines) {
-	if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
+	if ($line =~ m/$vcs_used->{author_pattern}/) {
 	    my $author = $1;
 	    my ($name, $address) = parse_email($author);
 	    $author = format_email($name, $address, 1);
@@ -1339,10 +1339,10 @@ sub vcs_save_commits {
     my @lines = ();
     my @commits = ();
 
-    @lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
+    @lines = &{$vcs_used->{execute_cmd}}($cmd);
 
     foreach my $line (@lines) {
-	if ($line =~ m/$VCS_cmds{"blame_commit_pattern"}/) {
+	if ($line =~ m/$vcs_used->{blame_commit_pattern}/) {
 	    push(@commits, $1);
 	}
     }
@@ -1357,10 +1357,10 @@ sub vcs_blame {
 
     return @commits if (!(-f $file));
 
-    if (@range && $VCS_cmds{"blame_range_cmd"} eq "") {
+    if (@range && $vcs_used->{blame_range_cmd} eq "") {
 	my @all_commits = ();
 
-	$cmd = $VCS_cmds{"blame_file_cmd"};
+	$cmd = $vcs_used->{blame_file_cmd};
 	$cmd =~ s/(\$\w+)/$1/eeg;		#interpolate $cmd
 	@all_commits = vcs_save_commits($cmd);
 
@@ -1381,12 +1381,12 @@ sub vcs_blame {
 	    my $diff_start = $2;
 	    my $diff_length = $3;
 	    next if ("$file" ne "$diff_file");
-	    $cmd = $VCS_cmds{"blame_range_cmd"};
+	    $cmd = $vcs_used->{blame_range_cmd};
 	    $cmd =~ s/(\$\w+)/$1/eeg;		#interpolate $cmd
 	    push(@commits, vcs_save_commits($cmd));
 	}
     } else {
-	$cmd = $VCS_cmds{"blame_file_cmd"};
+	$cmd = $vcs_used->{blame_file_cmd};
 	$cmd =~ s/(\$\w+)/$1/eeg;		#interpolate $cmd
 	@commits = vcs_save_commits($cmd);
     }
@@ -1400,11 +1400,10 @@ sub vcs_blame {
 
 my $printed_novcs = 0;
 sub vcs_exists {
-    %VCS_cmds = %VCS_cmds_git;
-    return 1 if eval $VCS_cmds{"available"};
-    %VCS_cmds = %VCS_cmds_hg;
-    return 2 if eval $VCS_cmds{"available"};
-    %VCS_cmds = ();
+    foreach my $vc (@VCS_avail) {
+	return $vc if eval $vc->{available};
+    }
+
     if (!$printed_novcs) {
 	warn("$P: No supported VCS found.  Add --nogit to options?\n");
 	warn("Using a git repository produces better results.\n");
@@ -1412,16 +1411,17 @@ sub vcs_exists {
 	warn("git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git\n");
 	$printed_novcs = 1;
     }
-    return 0;
+
+    return; #undef
 }
 
 sub vcs_is_git {
-    vcs_exists();
-    return $vcs_used == 1;
+    $vcs_used = vcs_exists();
+    return defined($vcs_used) && ($vcs_used->{name} eq 'git');
 }
 
 sub vcs_is_hg {
-    return $vcs_used == 2;
+    return defined($vcs_used) && ($vcs_used->{name} eq 'hg');
 }
 
 sub interactive_get_maintainers {
@@ -1752,13 +1752,13 @@ sub save_commits_by_author {
     my @subjects = ();
 
     foreach my $line (@lines) {
-	if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
+	if ($line =~ m/$vcs_used->{author_pattern}/) {
 	    my $author = $1;
 	    $author = deduplicate_email($author);
 	    push(@authors, $author);
 	}
-	push(@commits, $1) if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
-	push(@subjects, $1) if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
+	push(@commits, $1) if ($line =~ m/$vcs_used->{commit_pattern}/);
+	push(@subjects, $1) if ($line =~ m/$vcs_used->{subject_pattern}/);
     }
 
     for (my $i = 0; $i < @authors; $i++) {
@@ -1784,8 +1784,8 @@ sub save_commits_by_signer {
     my $subject = "";
 
     foreach my $line (@lines) {
-	$commit = $1 if ($line =~ m/$VCS_cmds{"commit_pattern"}/);
-	$subject = $1 if ($line =~ m/$VCS_cmds{"subject_pattern"}/);
+	$commit = $1 if ($line =~ m/$vcs_used->{commit_pattern}/);
+	$subject = $1 if ($line =~ m/$vcs_used->{subject_pattern}/);
 	if ($line =~ /^[ \t]*${signature_pattern}.*\@.*$/) {
 	    my @signatures = ($line);
 	    my ($types_ref, $signers_ref) = extract_formatted_signatures(@signatures);
@@ -1870,7 +1870,7 @@ sub vcs_file_signoffs {
     $vcs_used = vcs_exists();
     return if (!$vcs_used);
 
-    my $cmd = $VCS_cmds{"find_signers_cmd"};
+    my $cmd = $vcs_used->{find_signers_cmd};
     $cmd =~ s/(\$\w+)/$1/eeg;		# interpolate $cmd
 
     ($commits, $signers_ref, $authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
@@ -1888,7 +1888,7 @@ sub vcs_file_signoffs {
     vcs_assign("commit_signer", $commits, @signers);
     vcs_assign("authored", $commits, @authors);
     if ($#authors == $#stats) {
-	my $stat_pattern = $VCS_cmds{"stat_pattern"};
+	my $stat_pattern = $vcs_used->{stat_pattern};
 	$stat_pattern =~ s/(\$\w+)/$1/eeg;	#interpolate $stat_pattern
 
 	my $added = 0;
@@ -1956,7 +1956,7 @@ sub vcs_file_blame {
 	    my $commit = join(" -r ", @commits);
 	    my $cmd;
 
-	    $cmd = $VCS_cmds{"find_commit_signers_cmd"};
+	    $cmd = $vcs_used->{find_commit_signers_cmd};
 	    $cmd =~ s/(\$\w+)/$1/eeg;	#substitute variables in $cmd
 
 	    ($commit_count, $commit_signers_ref, $commit_authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
@@ -1974,7 +1974,7 @@ sub vcs_file_blame {
 		my @commit_signers = ();
 		my $cmd;
 
-		$cmd = $VCS_cmds{"find_commit_signers_cmd"};
+		$cmd = $vcs_used->{find_commit_signers_cmd};
 		$cmd =~ s/(\$\w+)/$1/eeg;	#substitute variables in $cmd
 
 		($commit_count, $commit_signers_ref, $commit_authors_ref, $stats_ref) = vcs_find_signers($cmd, $file);
@@ -1997,12 +1997,12 @@ sub vcs_file_blame {
 		my $commit = join(" -r ", @commits);
 		my $cmd;
 
-		$cmd = $VCS_cmds{"find_commit_author_cmd"};
+		$cmd = $vcs_used->{find_commit_author_cmd};
 		$cmd =~ s/(\$\w+)/$1/eeg;	#substitute variables in $cmd
 
 		my @lines = ();
 
-		@lines = &{$VCS_cmds{"execute_cmd"}}($cmd);
+		@lines = &{$vcs_used->{execute_cmd}}($cmd);
 
 		if (!$email_git_penguin_chiefs) {
 		    @lines = grep(!/${penguin_chiefs}/i, @lines);
@@ -2012,7 +2012,7 @@ sub vcs_file_blame {
 
 		my @authors = ();
 		foreach my $line (@lines) {
-		    if ($line =~ m/$VCS_cmds{"author_pattern"}/) {
+		    if ($line =~ m/$vcs_used->{author_pattern}/) {
 			my $author = $1;
 			$author = deduplicate_email($author);
 			push(@authors, $author);
@@ -2027,7 +2027,7 @@ sub vcs_file_blame {
 	    else {
 		foreach my $commit (@commits) {
 		    my $i;
-		    my $cmd = $VCS_cmds{"find_commit_author_cmd"};
+		    my $cmd = $vcs_used->{find_commit_author_cmd};
 		    $cmd =~ s/(\$\w+)/$1/eeg;	#interpolate $cmd
 		    my @author = vcs_find_author($cmd);
 		    next if !@author;


  parent reply	other threads:[~2014-05-26 20:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-26 20:33 [PATCH 0/4] get_maintainer script cleanups Stephen Hemminger
2014-05-26 20:33 ` [PATCH 1/4] get_maintainer: use three argument open Stephen Hemminger
2014-05-26 20:33 ` [PATCH 2/4] get_maintainer: remove quoting on hash label Stephen Hemminger
2014-05-26 20:33 ` Stephen Hemminger [this message]
2014-05-26 20:33 ` [PATCH 4/4] get_maintainer: use anonymous function instead of eval Stephen Hemminger
2014-05-27  1:00 ` [PATCH 0/4] get_maintainer script cleanups Joe Perches
2014-05-27  1:03   ` Joe Perches
2014-05-27  1:09     ` Stephen Hemminger
2014-05-27  1:22     ` [PATCH 5/4] get_maintainer: shut up perl critic Stephen Hemminger
2014-05-27  1:32       ` Joe Perches
2014-05-27 17:00         ` Stephen Hemminger
2014-05-27  1:06   ` [PATCH 0/4] get_maintainer script cleanups Stephen Hemminger

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=20140526203356.233948409@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=akpm@linux-foundation.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.