#!/bin/bash
# Copyright (c) 2011, Perforce Software, Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE
# SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
# This shell script will check to see that the contents were preserved
# by the conversion from Subversion to Perforce
#
# audit.txt is generated by p4convert.svn Java
# SET P4PORT for the Perforce Server used in conversion
P4PORT=:4448
# SET REPO to the path to the Subversion repository
REPO=/home/nmorse/projects/freebsd/svndepot
#### The following are derived directly from the View line of the
#### Client spec being used for the conversion, the examples are
#### based of a client view of: (DEPOT=import/svn, WORK=history/svn)
#### View: //import/svn/... //my-client/history/svn
#### A more typical view would be (DEPOT=depot, WORK=svn)
#### View: //depot/... //my-client/svn
# Set to DEPOT (typically this is 'depot')
DEPOT=import
# Set to Failure number to stop at, 0 disables this.
STOPCOUNT=0
# Set starting offset into audit.log
START=0
#####################
if [ "$P4PORT" == "" ]; then
echo "Please edit $0 and set P4PORT appropriately"
exit
fi
if [ "$REPO" == "" ]; then
echo "Please edit $0 and set REPO appropriately"
exit
fi
if [ "$1" == "" ]; then
MD5FILE=audit.log
else
MD5FILE=$1
fi
if [ -f $MD5FILE ]; then
echo "Using: $MD5FILE"
else
echo "Cannot find audit file: $MD5FILE"
exit
fi
if [ ! -d "validate" ]; then
mkdir validate
fi
if [ ! -d "validate/subversion" ]; then
mkdir validate/subversion
fi
if [ ! -d "validate/perforce" ]; then
mkdir validate/perforce
fi
if [ -f validate/fail.log ]; then
echo "Please delete 'validate/fail.log' before running"
exit
fi
if [ ! -d "/tmp" ]; then
mkdir /tmp
fi
# Write the header of fail.log
echo "# validation run " `date` >> validate/fail.log
echo "# line failure : svn p4 hash path" >> validate/fail.log
lines=`wc -l $MD5FILE | awk '{ print $1; }' `
currev=0
change=0
tagged=0
rev=0
cnt=0
failcnt=0
filecnt=0
rundos2unix=1 # set to '1' to use dos2unix to attempt md5 matching.
echo "0 0" `date`
cat $MD5FILE | for (( x=0; x < $lines; x++ )) ; do
IFS=$','
read path rev change hash
unset IFS
path=${path# }
rev=${rev# }
change=${change# }
if [ "$x" -lt "$START" ]; then
continue;
fi
if [ "$x" == "0" ]; then
continue;
fi
echo "$x $path $rev $change $hash"
if [ "$currev" != "$rev" ]; then
currev=$rev
tagged=0
cnt=$(( $cnt + 1 ))
fi
p4path=`echo $path | sed -e "s/%/%25/g" -e "s/@/%40/g" -e "s/#/%23/g" -e 's/[*]/%2a/g'`
# echo "p4 -p $P4PORT fstat -Ol -T digest \"//$DEPOT/$p4path@$change\" | awk '{ print $3; }'"
p4hash=`p4 -p $P4PORT fstat -Ol -T digest "//$DEPOT/$p4path@$change" | awk '{ print $3; }'`
if [ "$p4hash" != "$hash" ]; then
# recompute checksums after stripping keyword expansions
filecnt=$(( failcnt + 1 ))
if [ "$p4hash" != "$svnhash" ]; then
svnrehash=`svnlook cat -r "$rev" "$REPO" "$path" | ./zapkeywords.sh | tee validate/subversion/file${filecnt} | md5sum | awk '{ print $1; }' | tr "[:lower:]" "[:upper:]" `
p4rehash=`p4 -p "$P4PORT" print -q -o - "//$DEPOT/$p4path@$change" | ./zapkeywords.sh | tee validate/perforce/file${filecnt} | md5sum | awk '{ print $1; }' | tr "[:lower:]" "[:upper:]" `
if [ "$p4rehash" != "$svnrehash" ]; then
if [ "$rundos2unix" != "0" ]; then
# try dos2unix on the svn file to see if we can get a "unix line ending" md5
cp validate/subversion/file${filecnt} /tmp/foo
svnrehash1=`cat /tmp/foo | dos2unix | tee validate/subversion/file${filecnt} | md5sum | awk '{ print $1; }' | tr "[:lower:]" "[:upper:]" `
# echo "testing: $p4rehash != $svnrehash1"
if [ "$p4rehash" != "$svnrehash1" ]; then
(( failcnt ++ ))
echo "FAIL($failcnt): $path@$change ($rev) $hash != $p4hash"
echo "$x $failcnt : $rev $change $hash $path" >> validate/fail.log
if [ "$failcnt" == "$STOPCOUNT" ]; then
exit
fi
fi
else
(( failcnt ++ ))
echo "FAIL($failcnt): $path@$change ($rev) $hash != $p4hash"
echo "$x $failcnt : $rev $change $hash $path#$rev" >> validate/fail.log
if [ "$failcnt" == "$STOPCOUNT" ]; then
exit
fi
fi
fi
fi
fi
tag=$(( $cnt % 5 ))
if [ $tag -eq 0 ]; then
if [ $tagged -eq 0 ]; then
echo "$rev ($change)" `date`
tagged=1
fi
fi
done