#!/usr/bin/perl ########################################### # updcvs -- Update a CVS project with a dist tarball # Mike Schilli, 2002 (m@perlmeister.com) ########################################### use warnings; use strict; use Archive::Tar; use Pod::Usage; use File::Copy; use File::Path; my $VERSION = "0.01"; our $CVSVERSION = '$Revision: 1.3 $'; my $TAR = "tar"; my ($TARFILE) = @ARGV; pod2usage "No tarfile specified" if not defined $TARFILE; my($project) = ($TARFILE =~ /(.*)-\d+\.\d+.*/); my $tar = Archive::Tar->new(); $tar->read($TARFILE, 1) or die "$TARFILE doesn't seem to be in tar format"; my @files = $tar->list_files(); pod2usage "Tar file empty" unless @files; # Check if they have a common subdirectory my($dir) = ($files[0] =~ m#([^/]+)/#); if(grep { ! /^$dir/ } @files) { pod2usage "$TARFILE has more than one subdirectory"; } # Extract tarfile if(-e $dir) { pod2usage "$dir already exists. Please delete it."; } $tar->extract(@files) or die "Cannot extract $TARFILE"; # Move original CVS hierarchy to distname.CVS if(-e "$project.CVS") { pod2usage "$project.CVS already exists. Please delete it."; } move $project, "$project.CVS" or die "Cannot move $project to $project.CVS ($!)"; move $dir, $project or die "Cannot move $dir $project ($!)"; # Re-pack distfile, this time without version number system("$TAR zcf $project.tgz $project"); rmtree $project or die "Cannot delete $project"; move "$project.CVS", $project or die "Cannot move $project.CVS to $project ($!)"; # Unpack distfile over CVS dir system("$TAR zxf $project.tgz $project"); unlink "$project.tgz" or die "Cannot delete $project.tgz"; __END__ =head1 NAME updcvs - Update the CVS working tree with a *.tgz file =head1 DOWNLOAD _SRC_HERE_ =head1 SYNOPSIS updcvs tarfile =head1 DESCRIPTION If you have a project C in CVS, there might be times when you want to update it with a distribution tarball, because you might have checked it in somewhere else and updated it there. So, you'll obtain C from somewhere, which will contain the subdirectory C, which in turn contains all the project files. In order to update your CVS dir, you will have to =over 4 =item * Rename your CVS dir C to C =item * Untar the tarfile, which will result in a directory C. =item * Rename C to C =item * Tar up C to C. =item * Delete the now obsolete directory C. =item * Rename C back to C. =item * Untar C to update all files in C with the latest versions from the distribution. =back This script will make it easier for you. All you have to do is go to the directory which contains the project directory and call C with the distribution tarball's name: updcvs project-dir-1.42.tgz and the steps listed above will be performed automatically. =head1 LEGALESE Copyright 2002 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Mike Schilli Em@perlmeister.comE