• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env bash
2# shellcheck disable=SC2086 # we want word splitting
3# shellcheck disable=SC2155
4
5FOSSILS_SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
6FOSSILS_YAML="$(readlink -f "$1")"
7FOSSILS_RESULTS="$2"
8
9clone_fossils_db()
10{
11    local repo="$1"
12    local commit="$2"
13    rm -rf fossils-db
14    git clone --no-checkout "$repo" fossils-db
15    (cd fossils-db || return; git reset "$commit" || git reset "origin/$commit")
16}
17
18query_fossils_yaml()
19{
20    python3 "$FOSSILS_SCRIPT_DIR/query_fossils_yaml.py" \
21        --file "$FOSSILS_YAML" "$@"
22}
23
24create_clean_git()
25{
26    rm -rf .clean_git
27    cp -R .git .clean_git
28}
29
30restore_clean_git()
31{
32    rm -rf .git
33    cp -R .clean_git .git
34}
35
36fetch_fossil()
37{
38    local fossil="${1//,/?}"
39    echo -n "[fetch_fossil] Fetching $1... "
40    local output=$(git lfs pull -I "$fossil" 2>&1)
41    local ret=0
42    if [[ $? -ne 0 || ! -f "$1" ]]; then
43        echo "ERROR"
44        echo "$output"
45        ret=1
46    else
47        echo "OK"
48    fi
49    restore_clean_git
50    return $ret
51}
52
53if [[ -n "$(query_fossils_yaml fossils_db_repo)" ]]; then
54    clone_fossils_db "$(query_fossils_yaml fossils_db_repo)" \
55                     "$(query_fossils_yaml fossils_db_commit)"
56    cd fossils-db || return
57else
58    echo "Warning: No fossils-db entry in $FOSSILS_YAML, assuming fossils-db is current directory"
59fi
60
61# During git operations various git objects get created which
62# may take up significant space. Store a clean .git instance,
63# which we restore after various git operations to keep our
64# storage consumption low.
65create_clean_git
66
67for fossil in $(query_fossils_yaml fossils)
68do
69    fetch_fossil "$fossil" || exit $?
70    if ! fossilize-replay --num-threads 4 $fossil 1>&2 2> $FOSSILS_RESULTS/fossil_replay.txt;
71    then
72        echo "Replay of $fossil failed"
73        grep "pipeline crashed or hung" $FOSSILS_RESULTS/fossil_replay.txt
74        exit 1
75    fi
76    rm $fossil
77done
78
79exit $ret
80