Re: RCS 5.8 complains about "junk at end of file"
Warren Jones <[email protected]> Wed, 30 Jan 2013 08:50:57 -0800
| Newsgroups | gmane.comp.gnu.rcs |
|---|---|
| Organization | Fluke Corporation |
| Message-ID | <[email protected]> |
--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
On Wed, Jan 16, 2013 at 10:14:49AM -0800, Paul Eggert wrote:
> I don't know of any systematic fix that we have for the
> problem. My guess is that your script is your best
> solution, but obviously you should save your old RCS
> files before applying it....
Thanks. I'm attaching a copy of the little cleanup script I wrote, in the hope that someone else will find it useful.
--
Warren Jones
Fluke Corporation
Software Engineering Support Group
--k+w/mQv8wyuph6w0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: attachment; filename="trimrcs"
#! /usr/bin/perl
#
# trimrcs -- clean up trailing junk in RCS files
#
# Usage: trimrcs [-n] [-v] file [ file ...]
#
# Options:
#
# -n no-op (don't modify any files)
# -v verbose
#
# The simplest usage is: trimrcs -v RCS/*,v
#
# Earlier versions of RCS (up throught 5.7) would sometimes leave
# trailing junk in a file when revisions were deleted with "rcs -o".
# This junk was silently ignored until RCS 5.8, which does more
# thorough validation, and will die with a warning like:
#
# co: RCS/file.txt,v:783: junk at end of file: '1'
#
# This script will clean up trailing junk in RCS files.
# The original file is saved as "file,v.orig".
# This script requires RCS v5.8.
#
# $Id: trimrcs 5492 2013-01-17 21:20:04Z wjones $
# $URL: https://engsvnhost.tc.fluke.com/repos/sesg/linux/branches/SUSE_12_2/local/bin/trimrcs $
use strict;
use warnings;
use Getopt::Std;
use subs qw( trim_junk fatal usage );
$ENV{PATH} = '/bin:/usr/bin';
my %opts;
getopts( 'hnv', \%opts );
my $noop = $opts{n} || 0;
my $verbose = $opts{v} || 0;
my $version = `rlog -V 2>&1`;
fatal "requires RCS version 5.8"
unless $version =~ /^rlog \(GNU RCS\) 5.8/;
if ( ! @ARGV || $opts{h} ) {
usage;
exit;
}
foreach my $name ( @ARGV ) {
my $rlog = `rlog -R $name 2>&1`;
if ( $? == 0 ) {
print "$name: OK\n" if $verbose;
}
elsif ( $rlog =~ m{^rlog: (.*,v):(\d+): junk at end of file:}m ) {
printf "%s: truncate at line %d\n", $1, $2 if $verbose;
trim_junk( $1, $2-1 ) unless $noop;
}
else {
fatal $rlog;
}
}
sub trim_junk {
my ( $file, $last_line ) = @_;
my $new = "$file.new";
my $orig = "$file.orig";
fatal "$orig already exists" if -e $orig;
open( FILE, '<', $file ) || fatal "cannot open $file.";
open( NEW, '>', $new ) || fatal "cannot create $new.";
while ( <FILE> ) {
print NEW;
last if $. == $last_line;
}
close FILE;
close NEW;
rename( $file, $orig ) || fatal "cannot rename $file.";
rename( $new, $file ) || fatal "cannot rename $new.";
my $perm = (stat $orig)[2] & 07777;
chmod $perm, $file;
}
sub fatal {
$_ = $0;
s|.*/||;
die "$_: @_\n";
}
sub usage {
print <<"USAGE";
Usage: trimrcs [-h] [-n] [-v] file [file ...]
Options:
-h help (this message)
-n no-op
-v verbose
USAGE
}
--k+w/mQv8wyuph6w0--