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
guarantee).
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.
This commit is contained in:
Francois Gouget 2004-10-07 17:33:29 +00:00 committed by Alexandre Julliard
parent d1dceca69f
commit c4c271f1e4
1 changed files with 27 additions and 33 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/perl #!/usr/bin/perl -w
# #
# genpatch - A utility that generates patches for submission to # genpatch - A utility that generates patches for submission to
# wine-patches@winehq.org # wine-patches@winehq.org
@ -66,18 +66,13 @@ use Getopt::Std;
use File::Basename; use File::Basename;
use POSIX qw(strftime); use POSIX qw(strftime);
my $gen_date; # date the patch was generated # Command line options
my %options; # command line options my %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
# Default the patch name to the UTC time. Use a more descriptive date for the # Default the patch name to the UTC time. Use a more descriptive date for the
# patch generation date. # patch generation date.
$options{n} = strftime "%Y%m%d%H%M", gmtime; $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)) unless(getopts("vn:f:c:m:a:p:", \%options))
{ {
@ -86,28 +81,27 @@ unless(getopts("vn:f:c:m:a:p:", \%options))
exit 1; exit 1;
} }
$options{p} = "patches" unless(exists $options{p}); $options{p} = "patches" if (!defined $options{p});
$options{f} = "$options{p}/$options{n}.diff" unless(exists $options{f}); $options{f} = "$options{p}/$options{n}.diff" if (!defined $options{f});
$options{p} = dirname $options{f}; $options{p} = dirname $options{f};
@added_files = split ' ', $options{a}; $options{a} = "" if (!defined $options{a});
@modified_files = split ' ', $options{m}; 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; $options{c} =~ s/\\n/\n\t/g;
if(-d $options{p}) if (!-d $options{p})
{ {
if(-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;
}
} }
else elsif (-e $options{f})
{ {
mkdir $options{p}, (0777 & ~umask) or print STDERR "$options{f} already exists. Aborting.\n";
die "Unable to mkdir $options{p}: $!"; 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}); print "Generating $options{f}.\n" if($options{v});
open OPT_F, ">$options{f}" or die "Unable to open $options{f} for write: $!"; open OPT_F, ">$options{f}" or die "Unable to open $options{f} for write: $!";
print OPT_F <<EOF; print OPT_F <<EOF;
@ -119,26 +113,26 @@ AddedFiles: $options{a}
EOF EOF
print "Invoking cvs diff.\n" if($options{v}); print "Invoking cvs diff.\n" if($options{v});
open CVS_IN, "cvs diff -u @modified_files|" or die "Unable to invoke cvs: $!"; open CVS_IN, "cvs diff -u $options{m} |"
while($cvs_line = <CVS_IN>) 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; 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}); 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 " . open DIFF_IN, "diff -u /dev/null $added_file|"
"invoke diff: $!"; or die "Unable to invoke diff: $!";
print OPT_F <DIFF_IN>; print OPT_F <DIFF_IN>;
close DIFF_IN; close DIFF_IN;
} }