#!/usr/bin/perl -w # # cvsrestore: undo an accidental update that toasted some file. # # Written 2007-06-06 by Steven J. DeRose, sderose@acm.org # # To do: # Add -r option to search whole subtree for .\# files and do them. # Is there any way to get cvs it's a merge, again? use strict; my $version = "2010-09-12"; if ($ARGV[0] eq "-h") { showUsage(); exit; } (-d "CVS") || warn "You don't seem to be in a CVS directory....\n"; ############################################################################### while ($ARGV[0] ne "") { my $file = $ARGV[0]; (-f $file) || die "Can't find file '$file'.\n"; (substr($file,0,2) eq ".\#") || die "Must specify a file starting with '.\#'.\n"; my $pfile = substr($file,2); # without the prefix $pfile =~ s|\.[0-9]+\.[0-9]+$||; # without the version number (-f $pfile) || die "Can't find conflicts file '$pfile'.\n"; system "mv $pfile $pfile.conflicts"; system "mv $file $pfile"; my $isotime = getTimeData(); system "echo '$isotime: need to merge $ENV{PWD}, $pfile.' >>~/tomerge"; warn "'$file' done. Also logged in ~/tomerge.\n"; shift; } exit; ############################################################################### sub getTimeData() { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $year+=1900; my @mons = split(/\s+/,"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"); my $monname = $mons[$mon]; $mon+=1; my @wdays = split(/\s+/, "Monday Tuesday Wednesday Thursday Friday Saturday"); my $dayname = $wdays[$mon]; ($mon<10) && ($mon = "0$mon"); ($mday<10) && ($mday = "0$mday"); ($hour<10) && ($hour = "0$hour"); ($min<10) && ($min = "0$min"); ($sec<10) && ($sec = "0$sec"); my $isotime = "$year-$mon-$mday\@$hour:$min:$sec"; return($isotime); } ############################################################################### sub showUsage { print " =head1 Usage cvsrestore [.\#filename] Moves the regularly-named cvs file to filename.conflicts, then puts the .\# file into its place. This is to undo what happens if you mistakenly do a 'cvs update' when a patch is needed. It also appends a reminder line to ~/tomerge, because the file will now show up as 'locally modified' instead of 'needs merge' when checked with cvs status. =head1 Options =over =item * B<-h> Display this help and exit. =item * B<-version> Show version info and exit. "; }