There must be a simpler way of doing this. I accidentally committed some files in CVS which I shouldn't have. I needed to revert them to the previous version, but doing this for each file by hand would be tedious, so I wrote the following:
#!/usr/bin/perl
use strict;
use warnings;
my $file = shift or die "usage: $0 filename";
unless ( -f $file ) {
die "($file) does not appear to be a file";
}
my $log = qx{/usr/bin/cvs log $file};
my @versions = $log =~ m{
\n-{28}\n
revision\ (\d+\.\d+)\s*\n
date:\ \d\d\d\d/\d\d/\d\d
}gx;
my ( $current, $previous ) = @versions[ 0, 1 ];
unless ( $current && $previous ) {
die
"Could not determine current ($current) or previous ($previous) versions";
}
`/usr/bin/cvs diff -r$current -r$previous $file | patch --unified`;
What's the easy/correct way to do this?
-j ("join") option to update to revert:
cvs update -j after_change -j before_change filename.pl
(then commit and tag again, obviously).
You can still do this in your code sample (using the after- and before revision numbers, rather than tags), which would eliminate the pipe to patch.