Strictify genpatch

Francois Gouget fgouget at free.fr
Thu Oct 7 04:26:12 CDT 2004


Changelog:

  * tools/genpatch

    The generated patch was missing a line of the diff.
    genpatch was also depending on the new files being listed first by 
'cvs diff' (which is the case but I'm not sure there is any hard 
garantee).
    Use 'perl -w' for more checking, fix the resulting 'undefined value' 
warnings. In many cases we don't just want $options{xxx} to exist, we 
want it to be defined.
    Restrict the scope of variables and remove unneeded variables.


-- 
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
  "Only wimps use tape backup: _real_ men just upload their important stuff on
        ftp, and let the rest of the world mirror it ;)" -- Linus Torvalds
-------------- next part --------------
Index: tools/genpatch
===================================================================
RCS file: /var/cvs/wine/tools/genpatch,v
retrieving revision 1.6
diff -u -u -r1.6 genpatch
--- tools/genpatch	26 Nov 2003 03:55:01 -0000	1.6
+++ tools/genpatch	7 Oct 2004 09:22:14 -0000
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w
 #
 # genpatch - A utility that generates patches for submission to
 # wine-patches at winehq.org
@@ -66,18 +66,13 @@
 use File::Basename;
 use POSIX qw(strftime);
 
-my $gen_date;       # date the patch was generated
-my %options;        # command line options
-my @modified_files; # optional list of files that were modified
-my @added_files;    # added files as an array
-my $added_file;     # added file being considered
-my $cvs_line;       # line of output from CVS
-my $mod_files_str;  # string that describes the modified files
+# Command line options
+my %options;
 
 # Default the patch name to the UTC time.  Use a more descriptive date for the
 # patch generation date.
 $options{n} = strftime "%Y%m%d%H%M", gmtime;
-$gen_date = strftime "%Y/%m/%d %H:%M:%S UTC", gmtime;
+my $gen_date = strftime "%Y/%m/%d %H:%M:%S UTC", gmtime;
 
 unless(getopts("vn:f:c:m:a:p:", \%options))
 {
@@ -86,28 +81,27 @@
     exit 1;
 }
 
-$options{p} = "patches" unless(exists $options{p});
-$options{f} = "$options{p}/$options{n}.diff" unless(exists $options{f});
+$options{p} = "patches" if (!defined $options{p});
+$options{f} = "$options{p}/$options{n}.diff" if (!defined $options{f});
 $options{p} = dirname $options{f};
- at added_files = split ' ', $options{a};
- at modified_files = split ' ', $options{m};
+$options{a} = "" if (!defined $options{a});
+my @added_files = split ' ', $options{a};
+$options{m} = "" if (!defined $options{m});
+$options{c} = ""  if (!defined $options{c});
 $options{c} =~ s/\\n/\n\t/g;
 
-if(-d $options{p})
+if (!-d $options{p})
 {
-    if(-e $options{f})
-    {
-        print STDERR "$options{f} already exists.  Aborting.\n";
-        exit 1;
-    }
+    mkdir $options{p}, (0777 & ~umask)
+    or die "Unable to mkdir $options{p}: $!";
 }
-else
+elsif (-e $options{f})
 {
-    mkdir $options{p}, (0777 & ~umask) or
-        die "Unable to mkdir $options{p}: $!";
+    print STDERR "$options{f} already exists.  Aborting.\n";
+    exit 1;
 }
 
-$mod_files_str = exists($options{m}) ? $options{m} : "<see cvs diff>";
+my $mod_files_str = $options{m} ? $options{m} : "<see cvs diff>";
 print "Generating $options{f}.\n" if($options{v});
 open OPT_F, ">$options{f}" or die "Unable to open $options{f} for write: $!";
 print OPT_F <<EOF;
@@ -119,26 +113,26 @@
 EOF
 
 print "Invoking cvs diff.\n" if($options{v});
-open CVS_IN, "cvs diff -u @modified_files|" or die "Unable to invoke cvs: $!";
-while($cvs_line = <CVS_IN>)
+open CVS_IN, "cvs diff -u $options{m} |"
+or die "Unable to invoke cvs: $!";
+while (my $cvs_line = <CVS_IN>)
 {
-    chomp $cvs_line;
-    if($cvs_line =~ /^\? (.*)/)
+    if ($cvs_line !~ /^\? (.*)/)
     {
-        push @added_files, $1 unless(exists $options{a});
+        print OPT_F $cvs_line;
     }
-    else
+    elsif (!$options{a})
     {
-        print OPT_F <CVS_IN>;
+        push @added_files, chomp $1;
     }
 }
 close CVS_IN;
 
-foreach $added_file (@added_files)
+foreach my $added_file (@added_files)
 {
     print "Adding $added_file as a new file.\n" if($options{v});
-    open DIFF_IN, "diff -u /dev/null $added_file|" or die "Unable to " .
-        "invoke diff: $!";
+    open DIFF_IN, "diff -u /dev/null $added_file|"
+    or die "Unable to invoke diff: $!";
     print OPT_F <DIFF_IN>;
     close DIFF_IN;
 }


More information about the wine-patches mailing list