17ec681f3Smrg#!/usr/bin/env bash 27ec681f3Smrg 37ec681f3SmrgFOSSILS_SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" 47ec681f3SmrgFOSSILS_YAML="$(readlink -f "$1")" 57ec681f3SmrgFOSSILS_RESULTS="$2" 67ec681f3Smrg 77ec681f3Smrgclone_fossils_db() 87ec681f3Smrg{ 97ec681f3Smrg local repo="$1" 107ec681f3Smrg local commit="$2" 117ec681f3Smrg rm -rf fossils-db 127ec681f3Smrg git clone --no-checkout "$repo" fossils-db 137ec681f3Smrg (cd fossils-db; git reset "$commit" || git reset "origin/$commit") 147ec681f3Smrg} 157ec681f3Smrg 167ec681f3Smrgquery_fossils_yaml() 177ec681f3Smrg{ 187ec681f3Smrg python3 "$FOSSILS_SCRIPT_DIR/query_fossils_yaml.py" \ 197ec681f3Smrg --file "$FOSSILS_YAML" "$@" 207ec681f3Smrg} 217ec681f3Smrg 227ec681f3Smrgcreate_clean_git() 237ec681f3Smrg{ 247ec681f3Smrg rm -rf .clean_git 257ec681f3Smrg cp -R .git .clean_git 267ec681f3Smrg} 277ec681f3Smrg 287ec681f3Smrgrestore_clean_git() 297ec681f3Smrg{ 307ec681f3Smrg rm -rf .git 317ec681f3Smrg cp -R .clean_git .git 327ec681f3Smrg} 337ec681f3Smrg 347ec681f3Smrgfetch_fossil() 357ec681f3Smrg{ 367ec681f3Smrg local fossil="${1//,/?}" 377ec681f3Smrg echo -n "[fetch_fossil] Fetching $1... " 387ec681f3Smrg local output=$(git lfs pull -I "$fossil" 2>&1) 397ec681f3Smrg local ret=0 407ec681f3Smrg if [[ $? -ne 0 || ! -f "$1" ]]; then 417ec681f3Smrg echo "ERROR" 427ec681f3Smrg echo "$output" 437ec681f3Smrg ret=1 447ec681f3Smrg else 457ec681f3Smrg echo "OK" 467ec681f3Smrg fi 477ec681f3Smrg restore_clean_git 487ec681f3Smrg return $ret 497ec681f3Smrg} 507ec681f3Smrg 517ec681f3Smrgif [[ -n "$(query_fossils_yaml fossils_db_repo)" ]]; then 527ec681f3Smrg clone_fossils_db "$(query_fossils_yaml fossils_db_repo)" \ 537ec681f3Smrg "$(query_fossils_yaml fossils_db_commit)" 547ec681f3Smrg cd fossils-db 557ec681f3Smrgelse 567ec681f3Smrg echo "Warning: No fossils-db entry in $FOSSILS_YAML, assuming fossils-db is current directory" 577ec681f3Smrgfi 587ec681f3Smrg 597ec681f3Smrg# During git operations various git objects get created which 607ec681f3Smrg# may take up significant space. Store a clean .git instance, 617ec681f3Smrg# which we restore after various git operations to keep our 627ec681f3Smrg# storage consumption low. 637ec681f3Smrgcreate_clean_git 647ec681f3Smrg 657ec681f3Smrgfor fossil in $(query_fossils_yaml fossils) 667ec681f3Smrgdo 677ec681f3Smrg fetch_fossil "$fossil" || exit $? 687ec681f3Smrg fossilize-replay --num-threads 4 $fossil 1>&2 2> $FOSSILS_RESULTS/fossil_replay.txt 697ec681f3Smrg if [ $? != 0 ]; then 707ec681f3Smrg echo "Replay of $fossil failed" 717ec681f3Smrg grep "pipeline crashed or hung" $FOSSILS_RESULTS/fossil_replay.txt 727ec681f3Smrg exit 1 737ec681f3Smrg fi 747ec681f3Smrg rm $fossil 757ec681f3Smrgdone 767ec681f3Smrg 777ec681f3Smrgexit $ret 78