cvs-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Cvs-cvs] ccvs/contrib ChangeLog log_accum.pl


From: Derek Robert Price
Subject: [Cvs-cvs] ccvs/contrib ChangeLog log_accum.pl
Date: Fri, 12 May 2006 18:42:52 +0000

CVSROOT:        /cvsroot/cvs
Module name:    ccvs
Branch:         
Changes by:     Derek Robert Price <address@hidden>     06/05/12 18:42:52

Modified files:
        contrib        : ChangeLog log_accum.pl 

Log message:
        * log_accum.pl: Handle config files.
        (new_config, parse_config): New functions.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/contrib/ChangeLog.diff?tr1=1.189&tr2=1.190&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/cvs/ccvs/contrib/log_accum.pl.diff?tr1=1.25&tr2=1.26&r1=text&r2=text

Patches:
Index: ccvs/contrib/ChangeLog
diff -u ccvs/contrib/ChangeLog:1.189 ccvs/contrib/ChangeLog:1.190
--- ccvs/contrib/ChangeLog:1.189        Fri May 12 14:15:35 2006
+++ ccvs/contrib/ChangeLog      Fri May 12 18:42:52 2006
@@ -1,5 +1,8 @@
 2006-05-12  Derek Price  <address@hidden>
 
+       * log_accum.pl: Handle config files.
+       (new_config, parse_config): New functions.
+
        * log_accum.pl: Move argument parsing to Getopt::Long, eliminating
        more globals.
        (set_defaults): New function.
Index: ccvs/contrib/log_accum.pl
diff -u ccvs/contrib/log_accum.pl:1.25 ccvs/contrib/log_accum.pl:1.26
--- ccvs/contrib/log_accum.pl:1.25      Fri May 12 17:37:49 2006
+++ ccvs/contrib/log_accum.pl   Fri May 12 18:42:52 2006
@@ -251,7 +251,17 @@
 #      file-text       Text to include in temp file names.
 sub set_defaults
 {
-    my ($config) = @_;
+    my ($config, $configs) = @_;
+
+    # Condense the configs.
+    while (@$configs)
+    {
+       my $c = pop @$configs;
+       foreach (keys %$c)
+       {
+           $config->{$_} = $c->{$_} unless exists $config->{$_};
+       }
+    }
 
     # Anything not set will default to false in Perl.
 
@@ -289,6 +299,111 @@
 
 
 
+sub new_config
+{
+    my %config;
+
+    # Set up the option processing functions.
+    $config{'only-tags'} =
+       sub
+       {
+           $_[1] = '' if $_[1] eq "HEAD" || $_[1] eq "TRUNK";
+           push @{$config{'tag'}}, $_[1];
+       };
+    $config{'quiet'} =
+       sub
+       {
+           $config{'verbose'} = !$_[1];
+       };
+    $config{'file-prefix'} =
+       sub
+       {
+           die "Invalid identifier passed to option $_[0]: $_[1]"
+               unless $_[1] =~ /^([a-zA-Z0-9_.-]+)$/;
+           $config{'file-text'} = $1;
+       };
+    $config{'user'} =
+       sub
+       {
+           warn "Using deprecated -u option. Use -T instead.";
+           &{$config{'file-text'}} (@_);
+       };
+    $config{'suppress-diffs-against-empties'} =
+       sub
+       {
+           $config{'empty-diffs'} = !$_[1];
+       };
+
+    return \%config;
+}
+
+
+
+# This is global for convenience.  It is used in parse_config & process_argv.
+my @option_spec = ("config|c=s@",
+                  "mail-to|m=s@",
+                  "tag|only-tag|r=s@",
+                  "file-prefix|file-text|T=s", "user|u=s",
+                  "debug|verbose|v!",
+                  "quiet|q!",
+                  "commit-log|f=s",
+                  "url|cvsweb|U=s",
+                  "cvsroot|C=s",
+                  "send-diff|diff|d!",
+                  "diff-arg|D=s@",
+                  "suppress-diffs-against-empties|E!",
+                  "empty-diffs|e!",
+                  "separate-diffs|S!");
+
+sub parse_config
+{
+    my ($parsed_configs, $files) = @_;
+    my ($config, @configs);
+
+    foreach my $file (@$files)
+    {
+       local @ARGV = ();
+
+       warn "config loop detected" && next if $parsed_configs->{$file};
+       $parsed_configs->{$file} = 1;
+
+       print STDERR "parse_config: parsing $file\n" if $debug;
+       open CONFIG, "<$file" or die "can't open $file: $!";
+
+       while (<CONFIG>)
+       {
+           # Skip comments and lines with nothing but blanks.
+           next if /^\s*(#.*)?$/;
+
+           # Split it.
+           chomp;
+           /^(\S*)(\s+(.*))?$/;
+
+           # Save the option.
+           push @ARGV, "--$1";
+
+           # There is a difference between no argument and an empty string
+           # argument.
+           push @ARGV, $3 if $2;
+       }
+       close CONFIG;
+
+       # Get the options from the config file.
+       $config = new_config;
+       die "argument parsing failed"
+           unless GetOptions $config, @option_spec;
+
+       push @configs, parse_config ($parsed_configs, $config->{'config'})
+           if exists $config->{'config'};
+
+       push @configs, $config;
+    }
+
+    return @configs;
+}
+
+
+
 ## process the command line arguments sent to this script
 ## it returns an array of files, %s, sent from the loginfo
 ## command
@@ -352,92 +467,17 @@
 sub process_argv
 {
     my ($arg, $donefiles);
-    my (%config, $module, @files, %oldrev, %newrev);
-
-    my @option_spec = ("config|c=s",
-                      "mail-to|m=s@",
-                      "tag|only-tag|r=s@",
-                      "file-prefix|file-text|T=s", "user|u=s",
-                      "debug|verbose|v!",
-                      "quiet|q!",
-                      "commit-log|f=s",
-                      "url|cvsweb|U=s",
-                      "cvsroot|C=s",
-                      "send-diff|diff|d!",
-                      "diff-arg|D=s@",
-                      "suppress-diffs-against-empties|E!",
-                      "empty-diffs|e!",
-                      "separate-diffs|S!");
-
-    # Set up the option processing functions.
-    $config{'only-tags'} =
-       sub
-       {
-           $_[1] = '' if $_[1] eq "HEAD" || $_[1] eq "TRUNK";
-           push @{$config{'tag'}}, $_[1];
-       };
-    $config{'quiet'} =
-       sub
-       {
-           $config{'verbose'} = !$_[1];
-       };
-    $config{'file-prefix'} =
-       sub
-       {
-           die "Invalid identifier passed to option $_[0]: $_[1]"
-               unless $_[1] =~ /^([a-zA-Z0-9_.-]+)$/;
-           $config{'file-text'} = $1;
-       };
-    $config{'user'} =
-       sub
-       {
-           warn "Using deprecated -u option. Use -T instead.";
-           &{$config{'file-text'}} (@_);
-       };
-    $config{'suppress-diffs-against-empties'} =
-       sub
-       {
-           $config{'empty-diffs'} = !$_[1];
-       };
-       
-    # Copy @ARGV to reuse it.
-    my @args = @ARGV;
+    my ($config, $module, @files, %oldrev, %newrev);
+    my @configs;
 
     # Get the options.
+    $config = new_config;
     die "argument parsing failed"
-       unless GetOptions (\%config, @option_spec);
-
-    if (exists $config{'config'})
-    {
-       @ARGV = ();
-       open CONFIG, "<" . $config{'config'}
-           or die "can't open ", $config{'config'}, ": $!";
-       while (<CONFIG>)
-       {
-           # Skip comments and lines with nothing but blanks.
-           next if /^\s*(#.*)?$/;
-
-           # Split it.
-           chomp;
-           /^(\S*)(\s+(.*))?$/;
-
-           # Save the option.
-           push @ARGV, "--$1";
-
-           # There is a difference between no argument and an empty string
-           # argument.
-           push @ARGV, $3 if $2;
-       }
-
-       # Get the options from the config file.
-       die "argument parsing failed"
-           unless GetOptions (\%config, @option_spec);
+       unless GetOptions ($config, @option_spec);
 
-       # Reparse the command line options so they may overide the config file.
-       @ARGV = @args;
-       die "argument parsing failed"
-           unless GetOptions (\%config, @option_spec);
-    }
+    my %parsed_files;
+    push @configs, parse_config \%parsed_files, $config->{'config'}
+       if exists $config->{'config'};
 
     # Get the path and the file list.
     $module = shift @ARGV;
@@ -489,9 +529,10 @@
        die "Too many arguments." if @ARGV;
     }
 
-    set_defaults \%config;
+    # Condense the configs.
+    set_defaults $config, address@hidden;
 
-    return \%config, $module, address@hidden, \%oldrev, \%newrev;
+    return $config, $module, address@hidden, \%oldrev, \%newrev;
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]