forked from nipy/heudiconv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-compare-two-versions.sh
executable file
·75 lines (63 loc) · 2 KB
/
test-compare-two-versions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# A script which is for now very ad-hoc and to be ran outside of this codebase and
# be provided with two repos of heudiconv,
# with virtualenvs setup inside under venvs/dev3.
# Was used for https://github.com/nipy/heudiconv/pull/129
#
# Sample invocation
# $> datalad install -g ///dicoms/dartmouth-phantoms/bids_test4-20161014/phantom-1
# $> heudiconv/utils/test-compare-two-versions.sh heudiconv-{0.5.x,master} --bids -f reproin --files dartmouth-phantoms/bids_test4-20161014/phantom-1
# where heudiconv-0.5.x and heudiconv-master have two worktrees with different
# branches checked out and envs/dev3 environments in each
PS1=+
set -eu
outdir=${OUTDIR:=compare-versions}
RUN=echo
RUN=time
function run() {
heudiconvdir="$1"
out=$outdir/$2
shift
shift
source $heudiconvdir/venvs/dev3/bin/activate
whichheudiconv=$(which heudiconv)
# to get "reproducible" dataset UUIDs (might be detrimental if we had multiple datalad calls
# but since we use python API for datalad, should be Ok)
export DATALAD_SEED=1
if [ ! -e "$out" ]; then
# just do full conversion
echo "Running $whichheudiconv with log in $out.log"
$RUN heudiconv --random-seed 1 -o $out "$@" >| $out.log 2>&1 \
|| {
echo "Exited with $? Check $out.log" >&2
exit $?
}
else
echo "Not running heudiconv since $out already exists"
fi
}
d1=$1; v1=$(git -C "$d1" describe); shift
d2=$1; v2=$(git -C "$d2" describe); shift
diff="$v1-$v2.diff"
function show_diff() {
cd $outdir
diff_full="$PWD/$diff"
#git remote add rolando "$outdir/rolando"
#git fetch rolando
# git diff --stat rolando/master..
if diff -Naur --exclude=.git --ignore-matching-lines='^\s*\(id\s*=.*\|"HeudiconvVersion": \)' "$v1" "$v2" >| "$diff_full"; then
echo "Results are identical"
else
echo "Results differ: $diff_full"
cat "$diff_full" | diffstat
fi
if hash xsel; then
echo "$diff_full" | xsel -i
fi
}
mkdir -p $outdir
if [ ! -e "$outdir/$diff" ]; then
run "$d1" "$v1" "$@"
run "$d2" "$v2" "$@"
fi
show_diff