3 # genpatch - A utility that generates patches for submission to
4 # wine-patches@winehq.com
6 # By Steven Elliott <elliotsl@mindspring.com>
8 # This program is subject to the same license as Wine (www.winehq.com).
12 genpatch - A utility that generates patches for submission to
13 wine-patches@winehq.com
17 genpatch [B<-v>] [B<-n> patch_name] [B<-f> patch_file]
18 [B<-c> change_log] [B<-m> modified_files]
23 The genpatch utility generated patches for submission to
24 wine-patches@winehq by acting as a wrapper to "cvs diff". The "B<-v>"
25 switch specifies that verbose output should be generated. The "B<-n>"
26 switch overrides the patch name ("Name" field) which defaults to a
27 numeric UTC date. The "B<-f>" switch overrides the filename of the patch
28 which defaults to "patches/<patch_name>.diff". The "B<-c>" switch
29 specifies the CVS change log entry ("ChangeLog" field) which can be
30 seen when "cvs log" is invoked. The "B<-m>" ("ModifiedFiles" field) and
31 "B<-a>" ("AddedFiles" field) switches override the set of files that
32 would normally be included by the "cvs diff". Normally "cvs diff"
33 includes all files modified relative to the deltas indicated by the
34 "CVS/Entries" file and ignores all newly added files. The "B<-m>" switch
35 specifies a whitespace separated list of files that were modified.
36 The "B<-a>" switch specifies a whitespace separated list of files that
41 genpatch B<-n> NLSFix B<-c> "various fixes for NLS support" \
42 B<-m> ole/ole2nls.c B<-a> ole/ole3nls.c
44 The above generates a patch named "NLSFix" in "patches/NLSFix.diff"
45 that includes a modification to "ole/ole2nls.c" and a newly added
54 use POSIX qw(strftime);
56 my $gen_date; # date the patch was generated
57 my %options; # command line options
58 my @modified_files; # optional list of files that were modified
59 my @added_files; # added files as an array
60 my $added_file; # added file being considered
61 my $patches_dir; # location of the patch file
62 my $cvs_line; # line of output from CVS
63 my $mod_files_str; # string that describes the modified files
65 # Default the patch name to the UTC time. Use a more descriptive date for the
66 # patch generation date.
67 $options{n} = strftime "%Y%m%d%H%M", gmtime;
68 $gen_date = strftime "%Y/%m/%d %H:%M:%S UTC", gmtime;
70 unless(getopts("vn:f:c:m:a:", \%options))
72 print STDERR "Usage: $0 [-v] [-n patch_name] [-f patch_file] " .
73 "[-c change_log] [-m modified_files] [-a added_files]\n";
77 $options{f} = "patches/$options{n}.diff" unless(exists $options{f});
78 $patches_dir = dirname $options{f};
79 @added_files = split ' ', $options{a};
80 @modified_files = split ' ', $options{m};
86 print STDERR "$options{f} already exists. Aborting.\n";
92 mkdir $patches_dir, (0777 & ~umask) or
93 die "Unable to mkdir $patches_dir: $!";
96 $mod_files_str = exists($options{m}) ? $options{m} : "<see cvs diff>";
97 print "Generating $options{f}.\n" if($options{v});
98 open OPT_F, ">$options{f}" or die "Unable to open $options{f} for write: $!";
101 ChangeLog: $options{c}
103 ModifiedFiles: $mod_files_str
104 AddedFiles: $options{a}
107 print "Invoking cvs diff.\n" if($options{v});
108 open CVS_IN, "cvs diff -u @modified_files|" or die "Unable to invoke cvs: $!";
109 while($cvs_line = <CVS_IN>)
112 if($cvs_line =~ /^\? (.*)/)
114 push @added_files, $1 unless(exists $options{a});
118 print OPT_F <CVS_IN>;
123 foreach $added_file (@added_files)
125 print "Adding $added_file as a new file.\n" if($options{v});
126 open DIFF_IN, "diff -u /dev/null $added_file|" or die "Unable to " .
128 print OPT_F <DIFF_IN>;