blob: 539f1f40dc077876e4b8dce64ec241eee8760816 [file] [log] [blame]
Steven Elliott32bfb622000-02-27 16:36:59 +00001#!/usr/bin/perl
2#
3# genpatch - A utility that generates patches for submission to
4# wine-patches@winehq.com
5#
6# By Steven Elliott <elliotsl@mindspring.com>
7#
8# This program is subject to the same license as Wine (www.winehq.com).
9
Steven Elliotta51c6032000-03-19 12:46:02 +000010=head1 NAME
11
12genpatch - A utility that generates patches for submission to
13wine-patches@winehq.com
14
15=head1 SYNOPSIS
16
17genpatch [B<-v>] [B<-n> patch_name] [B<-f> patch_file]
18 [B<-c> change_log] [B<-m> modified_files]
19 [B<-a> added_files]
20
21=head1 DESCRIPTION
22
23The genpatch utility generated patches for submission to
24wine-patches@winehq by acting as a wrapper to "cvs diff". The "B<-v>"
25switch specifies that verbose output should be generated. The "B<-n>"
26switch overrides the patch name ("Name" field) which defaults to a
27numeric UTC date. The "B<-f>" switch overrides the filename of the patch
28which defaults to "patches/<patch_name>.diff". The "B<-c>" switch
29specifies the CVS change log entry ("ChangeLog" field) which can be
30seen when "cvs log" is invoked. The "B<-m>" ("ModifiedFiles" field) and
31"B<-a>" ("AddedFiles" field) switches override the set of files that
32would normally be included by the "cvs diff". Normally "cvs diff"
33includes all files modified relative to the deltas indicated by the
34"CVS/Entries" file and ignores all newly added files. The "B<-m>" switch
35specifies a whitespace separated list of files that were modified.
36The "B<-a>" switch specifies a whitespace separated list of files that
37were added.
38
39=head1 EXAMPLE
40
41genpatch B<-n> NLSFix B<-c> "various fixes for NLS support" \
42 B<-m> ole/ole2nls.c B<-a> ole/ole3nls.c
43
44The above generates a patch named "NLSFix" in "patches/NLSFix.diff"
45that includes a modification to "ole/ole2nls.c" and a newly added
46"ole/ole3nls.c".
47
48=cut
49
50use strict;
51
Steven Elliott32bfb622000-02-27 16:36:59 +000052use Getopt::Std;
53use File::Basename;
54use POSIX qw(strftime);
Steven Elliott32bfb622000-02-27 16:36:59 +000055
Steven Elliotta51c6032000-03-19 12:46:02 +000056my $gen_date; # date the patch was generated
57my %options; # command line options
58my @modified_files; # optional list of files that were modified
59my @added_files; # added files as an array
60my $added_file; # added file being considered
Steven Elliotta51c6032000-03-19 12:46:02 +000061my $cvs_line; # line of output from CVS
62my $mod_files_str; # string that describes the modified files
Steven Elliott32bfb622000-02-27 16:36:59 +000063
64# Default the patch name to the UTC time. Use a more descriptive date for the
65# patch generation date.
66$options{n} = strftime "%Y%m%d%H%M", gmtime;
67$gen_date = strftime "%Y/%m/%d %H:%M:%S UTC", gmtime;
68
Eric Poueche1885d12000-04-09 18:39:08 +000069unless(getopts("vn:f:c:m:a:p:", \%options))
Steven Elliott32bfb622000-02-27 16:36:59 +000070{
Steven Elliotta51c6032000-03-19 12:46:02 +000071 print STDERR "Usage: $0 [-v] [-n patch_name] [-f patch_file] " .
Eric Poueche1885d12000-04-09 18:39:08 +000072 "[-c change_log] [-m modified_files] [-a added_files] [-p path_to_patches]\n";
Steven Elliott32bfb622000-02-27 16:36:59 +000073 exit 1;
74}
75
Eric Poueche1885d12000-04-09 18:39:08 +000076$options{p} = "patches" unless(exists $options{p});
77$options{f} = "$options{p}/$options{n}.diff" unless(exists $options{f});
78$options{p} = dirname $options{f};
Steven Elliotta51c6032000-03-19 12:46:02 +000079@added_files = split ' ', $options{a};
80@modified_files = split ' ', $options{m};
Eric Poueche1885d12000-04-09 18:39:08 +000081$options{c} =~ s/\\n/\n\t/g;
Steven Elliott32bfb622000-02-27 16:36:59 +000082
Eric Poueche1885d12000-04-09 18:39:08 +000083if(-d $options{p})
Steven Elliott32bfb622000-02-27 16:36:59 +000084{
85 if(-e $options{f})
86 {
87 print STDERR "$options{f} already exists. Aborting.\n";
88 exit 1;
89 }
90}
91else
92{
Eric Poueche1885d12000-04-09 18:39:08 +000093 mkdir $options{p}, (0777 & ~umask) or
94 die "Unable to mkdir $options{p}: $!";
Steven Elliott32bfb622000-02-27 16:36:59 +000095}
96
Steven Elliotta51c6032000-03-19 12:46:02 +000097$mod_files_str = exists($options{m}) ? $options{m} : "<see cvs diff>";
98print "Generating $options{f}.\n" if($options{v});
Steven Elliott32bfb622000-02-27 16:36:59 +000099open OPT_F, ">$options{f}" or die "Unable to open $options{f} for write: $!";
100print OPT_F <<EOF;
101Name: $options{n}
102ChangeLog: $options{c}
103GenDate: $gen_date
Steven Elliotta51c6032000-03-19 12:46:02 +0000104ModifiedFiles: $mod_files_str
105AddedFiles: $options{a}
Steven Elliott32bfb622000-02-27 16:36:59 +0000106EOF
107
Steven Elliotta51c6032000-03-19 12:46:02 +0000108print "Invoking cvs diff.\n" if($options{v});
109open CVS_IN, "cvs diff -u @modified_files|" or die "Unable to invoke cvs: $!";
110while($cvs_line = <CVS_IN>)
Steven Elliott32bfb622000-02-27 16:36:59 +0000111{
Steven Elliotta51c6032000-03-19 12:46:02 +0000112 chomp $cvs_line;
113 if($cvs_line =~ /^\? (.*)/)
114 {
115 push @added_files, $1 unless(exists $options{a});
116 }
117 else
118 {
119 print OPT_F <CVS_IN>;
120 }
121}
122close CVS_IN;
123
124foreach $added_file (@added_files)
125{
126 print "Adding $added_file as a new file.\n" if($options{v});
127 open DIFF_IN, "diff -u /dev/null $added_file|" or die "Unable to " .
Steven Elliott32bfb622000-02-27 16:36:59 +0000128 "invoke diff: $!";
129 print OPT_F <DIFF_IN>;
130 close DIFF_IN;
131}
132
Steven Elliotta51c6032000-03-19 12:46:02 +0000133close OPT_F;