Index: cvsdo.pl =================================================================== RCS file: /usr/local/cvs/cvsutils/cvsdo.pl,v retrieving revision 1.3 diff -u -r1.3 cvsdo.pl --- cvsdo.pl +++ cvsdo.pl @@ -8,7 +8,7 @@ use Getopt::Long; use strict; -use vars qw($force_mode $entries_tmp); +use vars qw($force_mode $entries_tmp $cvs_root $path); # Print message and exit (like "die", but without raising an exception). # Newline is added at the end. @@ -118,7 +118,14 @@ sub handle_added ($) { my $file = shift(@_); - open(DIFFOUT, "diff -u -L /dev/null -L $file /dev/null $file |") || + my $nullfile; + if ($^O =~ m!win|os/2!i) { + $nullfile = 'nul'; + } else { + $nullfile = '/dev/null'; + } + my $diff_opts = $ENV{'DIFFCMD'}||'-u'; + open(DIFFOUT, "diff $diff_opts -L $nullfile -L $file $nullfile $file |") || error ("Cannot read output of diff: $!"); unix_print ("Index: $file"); while () { @@ -161,10 +168,12 @@ # Lookup the original timestamp in CVS/Entries. open (ENTRIES, "< ${dir}CVS/Entries") || error ("couldn't open ${dir}CVS/Entries: $!"); + my $cvs_rev; my $date_str; while () { - if ( m{^/$short_file/[^/]*/([^/]+)/} ) { - $date_str = $1; + if ( m{^/$short_file/([^/]*)/([^/]+)/} ) { + $cvs_rev = $1; + $date_str = $2; last; } } @@ -173,6 +182,7 @@ } close (ENTRIES); + $date_str = 'Unk Jan 01 01:01:01 1970' if $date_str eq 'Result of merge'; unless ($date_str =~ m{^(...) (...) (..) (..):(..):(..) (....)$}) { error ("Invalid timestamp for $file: $date_str"); } @@ -195,11 +205,21 @@ closedir (DIR); unless (defined $backup_file) { - warning ("Backup file for $file not found"); - return; + my $cvs_rev2 = $cvs_rev; $cvs_rev2 =~ tr/\./_/; + if ($file eq $short_file) { + $backup_file = ".#$file.$cvs_rev2"; + } else { + $backup_file = "$dir.#$short_file.$cvs_rev2"; + } + if (-f $backup_file) { + warning ("Using $backup_file for $file"); + } else { + warning ("Backup file for $file not found; retrieving from cvs as $backup_file"); + `cvs up -p -r $cvs_rev $file 2>&1 > $backup_file`; + } } - my $diff_opts = "-u"; + my $diff_opts = $ENV{'DIFFCMD'}||'-u'; if ($short_file eq "ChangeLog") { $diff_opts = "-u1"; } @@ -208,6 +228,11 @@ "diff $diff_opts -L $file -L $file $backup_file $file |") || error ("Cannot read output of diff: $!"); unix_print ("Index: $file"); + unix_print ("==================================================================="); + unix_print ("RCS file: $cvs_root/$path/$file,v"); + unix_print ("retrieving revision $cvs_rev"); + unix_print ("diff $diff_opts -r$cvs_rev $file"); + while () { unix_print ($_); } @@ -216,21 +241,41 @@ # Handle `diff' command. sub handle_diff () { + my %file_list; if ($#ARGV >= 0) { - usage (); + usage () if $ARGV[0] eq '--help'; + $file_list{$_}=1 foreach (@ARGV); } - open(CVSADM, "cvsu --ignore --types AMRO |") || + # Lookup the cvsroot in CVS/Root. + open (ROOT, "< CVS/Root") + || error ("couldn't open CVS/Root: $!"); + =~ m!:([^:]+?)\n?$!; $cvs_root=$1; + close(ROOT); + + # Lookup the path in CVS/Repository. + open (REPOSITORY, "< CVS/Repository") + || error ("couldn't open CVS/Repository: $!"); + =~ m|(\S+)|; $path = $1; + close(REPOSITORY); + + open(CVSADM, "cvsu --ignore --types AMROG |") || error ("Cannot read output of cvsu: $!"); while () { chomp; - if ($_ !~ m{^([AMRO]) (.*)$}) { + if ($_ !~ m{^([AMROG]) (.*)$}) { error ("Unrecognized output from cvsu"); } my $type = $1; my $file = $2; + + if ($#ARGV >= 0) { + next unless $file_list{$file}; + delete $file_list{$file}; + } + if ($type eq "A") { handle_added ($file); }