#!/usr/bin/perl -w # # PVCS to Perforce converter, phase V: verify Perforce depot # # Copyright 1998 Perforce Software. All rights reserved. # Written by James Strickland, March 1998 # # This script uses the metadata produced by earlier phases to direct a loop # which extracts PVCS revisions and verifies that the Perforce version # stores the same information. require 5.0; use strict; use integer; use lib '.'; use convert; use Change; $ENV{P4CLIENT} = 'pvcs' unless defined($ENV{P4CLIENT}); $ENV{P4USER} = 'pvcs' unless defined($ENV{P4USER}) or defined($ENV{USER}) or defined($ENV{USERNAME}); my $last_change = convert::run("p4 changes -m 1"); die "Didn't recognize the output of p4 changes: $last_change" unless($last_change =~ /^Change\s+(\d+)/); $last_change=$1; print "There are $last_change changes in the depot.\n"; # open all our input files open(MAPPING, "$convert::metadata_dir/mapping.ns") or die "can't open: $!"; # overwrite client files with revisions from PVCS, then use p4 diff # to verify that the file is the same as the version in the depot my $failed=0; my $prev_change_number=1; while() { chomp; my ($archive,$revision,$change_number,$depot_file)=split(/#/); my ($client_file,$filetype); my $fstat = convert::run("p4 fstat \"$depot_file\@$change_number\""); if( $fstat =~ /clientfile (.*)\n/im ) { $client_file = convert::forward_slash($1); } else { $failed=$change_number; next; } unlink($client_file); convert::run("get -y -q -r$revision \"$archive($client_file)\""); if(convert::run("p4 diff -f -se \"$depot_file\@$change_number\"")) { # it may have failed because of keyword expansion if( $fstat =~ /headtype (.*)\n/im ) { if($1 eq 'ktext' || $1 eq 'kxtext') { # ok, now do replacement for $Id$ and $Header$ and try again # note: this also has to strip off the stupid ^Zs at the end, if any # (1998 and we're steal dealing with the legacy of CP/M...sigh) $fstat =~ /headrev (.*)\n/im or die "no headrev in fstat"; my $depot_rev = $1; unlink("$client_file.tmp"); rename($client_file,"$client_file.tmp") or die "can't rename"; open(ORIGINAL,"<$client_file.tmp") or die "can't open original"; open(KEYWORDS_EXPANDED,">$client_file") or die "can't open ke"; while() { s%\$Id[^\$]*\$%\$Id: $depot_file#$depot_rev \$%; s%\$Header[^\$]*\$%\$Header: $depot_file#$depot_rev \$%; print KEYWORDS_EXPANDED $_; } close(ORIGINAL); close(KEYWORDS_EXPANDED); unlink("$client_file.tmp"); if(!convert::run("p4 diff -f -se \"$depot_file\@$change_number\"")) { next; } } } # ok, it definitely failed $failed=$change_number; print "$depot_file\@$change_number differs from PVCS file $archive revision $revision\n"; print convert::run("p4 diff -f \"$depot_file\@$change_number\""); print "\n"; next; } if($change_number!=$prev_change_number) { print "Change $prev_change_number ok.\r" unless($failed == $prev_change_number); $prev_change_number=$change_number; } } if($failed) { print "VERIFY FAILED! The most common reason for this is files being submitted as text on Windows when they are actually binary. The best way to solve this problem is to alter the PVCS archive(s) to be binary (use vcs -pg -pk archivefile) or define files of that extension to be binary in the config file, then run the converter again."; } else { print "Verify succeeded - all file revisions in Perforce match those in PVCS.\n"; }