#!/bin/bash
#
# convert-check - compare reposurgeon and git-svn lifts of a Subversion dump
#
# The -v option undoes the suppression of progress messages.
# 
sink=/dev/null
while getopts v opt
do
    case $opt in
	v) sink=/dev/stdout 
    esac
done
shift $(($OPTIND - 1))

if [ -z "$1" ]
then
    echo "convert-check: an argument file (a Subversion dump) is required."
    exit 1
fi

stem=cc$$
trap "rm -fr ${stem}-repo ${stem}-svn ${stem}-git ${stem}*~ ${stem}.fo" 0

# Build a Subversion repo from a dump on standard input
svnadmin create ${stem}-repo
if svnadmin ${svnadminquiet} load ${stem}-repo <$1 >${sink}
then
    :
else
    echo "convert-check: repository load failure."
    exit 1
fi

# Make a git repo from the Subversion repo using git-svn
git svn ${gitsvnquiet} --stdlayout --no-metadata clone file://${PWD}/${stem}-repo ${stem}-svn >$sink 2>$sink

# Now make a git repo directly from the dump using reposurgeon
reposurgeon "set svn_use_uuid" "read $1" "prefer git" "legacy write >${stem}.fo" "rebuild ${stem}-git"

# Diff the two repos. We need the ignore because git-svn doesn't lift ignores
repodiffer -q --ignore="gitignore" --tree-diff --legacy-map=${stem}.fo ${stem}-git ${stem}-svn
exit $?

# end
