#!/usr/bin/perl # # This script is put in the public domain by Henrik Nordström # . It is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # If you find this script useful then you are encouraged to send feedback # to the author, but you have absolutely no obligation to do so. # # Author: # Henrik Nordström # http://hem.passagen.se/hno/ # # Distribution URL: # http://devel.squid-cache.org/CVS.html # # Version history: # 2002-12-08 Added support for premade patches # 2001-09-25 First public domain release # use File::Basename; $type="text/plain"; $file = basename($0); $top = dirname($0); $module = ""; if ($file eq "diff2") { $module = "squid"; } elsif ($file eq "diff") { $module = "squid3"; } elsif ($file eq "diff3") { $module = "squid3"; } $new = 0; if (defined($ENV{PATH_INFO})) { $branch = basename($ENV{PATH_INFO}); if ($branch =~ /.patch$/) { print "Content-Disposition: attachment; filename=\"$branch\"\n"; $branch =~ s/.patch$//; $type = "text/x-patch"; } if ($branch =~ /.diff$/) { print "Content-Disposition: attachment; filename=\"$branch\"\n"; $branch =~ s/.diff$//; $type = "text/x-diff"; } $base=$ARGV[0]; print "Content-Type: $type\n"; print "\n"; } else { if ($ARGV[0] eq "-new") { shift @ARGV; $new = 1; } if ( $module eq "" ) { if ( @ARGV != 3 ) { print STDERR "Usage: $0 module branch base\n"; exit(1); } $module = $ARGV[0]; shift @ARGV; } if ( @ARGV != 2 ) { print STDERR "Usage: $0 branch base\n"; exit(1); } $branch = $ARGV[0]; $base=$ARGV[1]; } $branch =~ s/\./_/g; $branch =~ s/[^a-zA-Z0-9-_]+//g; $base =~ s/\./_/g; $base =~ s/[^a-zA-Z0-9-_]+//g; $base = "HEAD" if $base eq ""; $ENV{HOME} = `pwd`; chomp $ENV{HOME}; $ENV{HOME} =~ s/\/[a-z-]+$//; $ENV{CVSROOT} = ":pserver:anonymous\@cvs1:/cvsroot/squid" if ( ! -f "CVS/Root" ); $|=1; if ($new) { open(STDOUT, ">${module}-${branch}-${base}.new") || die; print("This patch is generated from the $branch branch of $base in $module\n"); print scalar gmtime; print " GMT\n"; print "See http://devel.squid-cache.org/\n"; print "\n"; open(STDERR,">&STDOUT"); open(STDOUT,"|$top/cleanpatch"); system("cvs","-q","rdiff", "-kk", "-u", "-rZ-${branch}_merge_${base}", "-r${branch}","${module}"); if (-f "${module}-${branch}-${base}") { open(OLD,"${module}-${branch}-${base}.patch"); while () { chomp; last if (/^$/); } open(NEW,"${module}-${branch}-${base}.new"); while () { chomp; last if (/^$/); } $old = join("", ); $new = join("", ); unlink("${module}-${branch}-${base}.new") if ($old eq $new); } if (-f "${module}-${branch}-${base}.new") { rename("${module}-${branch}-${base}.new", "${module}-${branch}-${base}.patch"); } } else { if (open(PATCH, "<../htdocs/patches/${module}-${branch}-${base}.patch")) { while() { print; } close(PATCH); } else { print "Sorry, patch for $branch branch of $base in $module\n"; print "is not yet available. Please try again in a few hours\n"; print "If the problem persists write to squid-dev\@squid-cache.org\n"; } open(LOG, ">>../patches/log"); print LOG "$ENV{REMOTE_ADDR} ${file} ${branch} ${base}\n"; close(LOG); }