Stories
Slash Boxes
Comments

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday June 04, 2007
09:59 AM

Reverting to a previous CVS version

[ #33421 ]

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?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • If I recall correctly use can use -D to select relevant diff by date range.
    --

    Ilya Martynov (http://martynov.org/ [martynov.org])

  • It's too late for this now, but good practice is to tag your files before and after a commit. That way you can use the -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.