#!/usr/local/bin/perl my( $verbose, $veroffset ); $USAGE = ' USAGE: cvs-ver [OPTIONS] [FILE_REGEXP] SYNOPSIS: show cvs version of files, with -N show older versions. AUTHOR: GPL(C) Mohsin Ahmed, http://www.cs.albany.edu/~mosh REGEXP: Print only matching lines. OPTIONS: -+N Add N to old version, or --N Subtract N from version of file, and prints cvs diff -r old -r new file cvs update -r old -p file > file.old -v verbose .. not used. -w Run windiff. NOTES: Reads ./CVS/Tag and ./CVS/Entries. EXAMPLES: > cvs-ver .. Show version of files in current dir. > cvs-ver --1 Makefile .. Show how to get Makefile-(version-1) > cvs-ver -+1 Makefile .. Show how to get Makefile-(version+1) > cvs-ver --0 file.c .. Show how to see your edits in windiff. > cvs-ver -w file.c .. See your changes in windiff. '; while( $_ = $ARGV[0], m/^-/ ){ shift; last if /^--$/; if( m/^-v/ ){ $verbose++; next; } if( m/^-([-+]?\d+)/ ){ $veroffset = $1; next; } if( m/^-w/ ){ $runwindiff++; $veroffset = 0; next; } die $USAGE if m/^-[h?]/; } my $regexp = shift || ''; warn "# cvs-ver m/$regexp/, veroffset='$veroffset'\n"; unless( -d "CVS" ){ die "Need ./CVS dir in pwd to get info\n"; } if( -r 'CVS/Tag' ){ $atag = `cat CVS/Tag`; $atag =~ s/^T//; $atag =~ s/\n//; }else{ warn "Cannot read CVS/Tag\n"; } my( @cvsdiff, @cvsrev, @cvswindiff ); open( CVSENTRIES, "< CVS/Entries" ) or die "Cannot open('CVS/Entries')\n"; LINE: while( ){ chomp; my ($dummy, $file,$ver,$date,$tag) = split( '\/+' ); # Tue Dec 21 17:41:15 1999 $date =~ s/^\s*[A-Z][a-z][a-z]\s+//; # No Sat/Sun $date =~ s/\d\d:\d\d:\d\d //; # No time $date =~ s/\s+/-/g; # Space to dash. $tag =~ s/^T//; # Tags begin with CapT. next LINE unless $file =~ m/\S/; # Skip blank lines. my $out = sprintf( "# %-18s %-18s %-12s %-10s\n" ,$ver ,$file ,$date ,$tag || $atag ); next LINE if $regexp and $out !~ m/$regexp/o; print $out; next LINE unless defined $veroffset; my $newver = $ver; $newver =~ s/\.(\d+)$/sprintf(".%s",$1+$veroffset)/e; # 7.4.2-1 => 7.4.1 my $newfile = "$file-v$newver"; push(@cvsdiff,sprintf("cvs diff -r %-8s -r %-8s %s\n", $newver,$ver, $file)) if $veroffset != 0; my $cmd1 = "cvs up -p -r $newver $file > $newfile\n"; my $cmd2 = "windiff $file $newfile\n"; push(@cvsrev , $cmd1 ); push(@cvswindiff , $cmd2 ); if( $runwindiff ){ my $cmd3 = "rm -v $newfile\n"; print "system: $cmd1"; system($cmd1); print "system: $cmd2"; system($cmd2); print "system: $cmd3"; system($cmd3); die "\n"; } } close CVSENTRIES; if( $veroffset ){ print @cvsdiff; print @cvsrev; print @cvswindiff; } # EOF