1999-12-23 10:34:45 -05:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# Name: difflast.pl
|
|
|
|
# Purpose: Shows the difference between the current local version of the file
|
|
|
|
# and the last cvs revision
|
|
|
|
# Version: $Id$
|
|
|
|
# Author: VZ
|
|
|
|
# Created: 23.12.99
|
|
|
|
# Copyright:(c) Vadim Zeitlin 1999
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $CVS = "cvs -z3"; # the cvs command
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
# the regexp for cvs revision number
|
|
|
|
my $RE_CVS_REV = "\\d+(?:\\.\\d+)+";
|
|
|
|
|
1999-12-23 10:34:45 -05:00
|
|
|
sub dec_rev($)
|
|
|
|
{
|
|
|
|
my $rev = $_[0];
|
|
|
|
|
|
|
|
# decrement the revision number to get the previos one
|
2000-07-15 15:51:35 -04:00
|
|
|
$rev =~ s/(\d+)$/$1 - 1/e;
|
1999-12-23 10:34:45 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
return $rev;
|
1999-12-23 10:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
sub get_last_rev($)
|
|
|
|
{
|
|
|
|
my $file = $_[0];
|
|
|
|
|
|
|
|
my $basename = $file;
|
2000-03-16 11:30:14 -05:00
|
|
|
$basename =~ s@^.*/@@;
|
1999-12-23 10:34:45 -05:00
|
|
|
|
|
|
|
# first get the current version: try the Id RCS tag in the file itself
|
|
|
|
# first, use "cvs status" if this fails
|
|
|
|
if ( open(INPUT, $file) ) {
|
|
|
|
while (<INPUT>) {
|
1999-12-23 10:40:18 -05:00
|
|
|
# notice that we shouldn't have '$' followed by 'Id' or cvs will
|
|
|
|
# substitute it!
|
2000-07-15 15:51:35 -04:00
|
|
|
if ( /\$(Id): $basename,v ($RE_CVS_REV)/ ) {
|
1999-12-23 10:40:18 -05:00
|
|
|
return &dec_rev($2);
|
1999-12-23 10:34:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
open(INPUT, "$CVS -q status $file |") or return 0;
|
|
|
|
|
|
|
|
while (<INPUT>) {
|
2000-07-15 15:51:35 -04:00
|
|
|
if ( /Working revision:\s+($RE_CVS_REV)/ ) {
|
1999-12-23 10:34:45 -05:00
|
|
|
return &dec_rev($1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub process_file($)
|
|
|
|
{
|
|
|
|
my $file = $_[0];
|
|
|
|
my $revlast = &get_last_rev($file);
|
|
|
|
|
|
|
|
if ( !$revlast ) {
|
|
|
|
warn "Failed to get the last revision for $file, skipping.\n"
|
|
|
|
}
|
2000-03-16 11:30:14 -05:00
|
|
|
elsif ( $revlast =~ '\.0' ) {
|
1999-12-23 10:40:18 -05:00
|
|
|
warn "No previous revision of the file $file.\n"
|
|
|
|
}
|
1999-12-23 10:34:45 -05:00
|
|
|
else {
|
|
|
|
print `$CVS diff -b -kk -r $revlast $file`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# entry point
|
|
|
|
|
|
|
|
die "Usage: $0 <filenames...>\n" if ( $#ARGV == -1 );
|
|
|
|
|
|
|
|
foreach my $file (@ARGV) { process_file($file); }
|
|
|
|
|
|
|
|
exit 0;
|