Skip to content

Commit 5330f55

Browse files
committed
ENH: make test-compare-two-versions take any two worktrees, and just show diff if results already known
1 parent 135ccb9 commit 5330f55

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

utils/test-compare-two-versions.sh

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,71 @@
11
#!/bin/bash
22
# A script which is for now very ad-hoc and to be ran outside of this codebase and
3-
# assumes having two repos of heudiconv -- one under heudiconv and another heudiconv-master
4-
# with virtualenvs setup inside under venvs/dev.
3+
# be provided with two repos of heudiconv,
4+
# with virtualenvs setup inside under venvs/dev3.
55
# Was used for https://github.com/nipy/heudiconv/pull/129
6+
#
7+
# Sample invocation
8+
# $> datalad install -g ///dicoms/dartmouth-phantoms/bids_test4-20161014/phantom-1
9+
# $> heudiconv/utils/test-compare-two-versions.sh heudiconv-{0.5.x,master} --bids -f reproin --files dartmouth-phantoms/bids_test4-20161014/phantom-1
10+
# where heudiconv-0.5.x and heudiconv-master have two worktrees with different
11+
# branches checked out and envs/dev3 environments in each
612

713
PS1=+
814
set -eu
915

1016
outdir=${OUTDIR:=compare-versions}
1117

1218
RUN=echo
13-
RUN=
19+
RUN=time
1420

15-
#if [ -e $outdir ]; then
16-
# # just fail if exists already
17-
# echo "$outdir exists already -- remove if you want to run the comparison" >&2
18-
# exit 1
19-
#fi
20-
21-
mkdir -p $outdir
2221

2322
function run() {
2423
heudiconvdir="$1"
2524
out=$outdir/$2
2625
shift
2726
shift
28-
source $heudiconvdir/venvs/dev/bin/activate
27+
source $heudiconvdir/venvs/dev3/bin/activate
2928
whichheudiconv=$(which heudiconv)
3029

31-
# just do full conversion
32-
echo "Running $whichheudiconv with log in $out.log"
33-
$RUN heudiconv --random-seed 1 -c dcm2niix -o $out --datalad --bids "$@" >| $out.log 2>&1
30+
if [ ! -e "$out" ]; then
31+
# just do full conversion
32+
echo "Running $whichheudiconv with log in $out.log"
33+
$RUN heudiconv --random-seed 1 -o $out "$@" >| $out.log 2>&1 \
34+
|| {
35+
echo "Exited with $? Check $out.log" >&2
36+
exit $?
37+
}
38+
else
39+
echo "Not running heudiconv since $out already exists"
40+
fi
3441
}
3542

36-
other=other
37-
run heudiconv $other "$@"
38-
run heudiconv-master master "$@"
39-
40-
cd $outdir
41-
#git remote add rolando "$outdir/rolando"
42-
#git fetch rolando
43-
# git diff --stat rolando/master..
44-
if diff -Naur --exclude=.git --ignore-matching-lines='^\s*id\s*=.*' $other master >| diff.patch; then
45-
echo "Results are identical"
46-
else
47-
echo "Results differ: $PWD/diff.patch"
48-
cat diff.patch | diffstat
43+
d1=$1; v1=$(git -C "$d1" describe); shift
44+
d2=$1; v2=$(git -C "$d2" describe); shift
45+
diff="$v1-$v2.diff"
46+
47+
function show_diff() {
48+
cd $outdir
49+
diff_full="$PWD/$diff"
50+
#git remote add rolando "$outdir/rolando"
51+
#git fetch rolando
52+
# git diff --stat rolando/master..
53+
if diff -Naur --exclude=.git --ignore-matching-lines='^\s*id\s*=.*' "$v1" "$v2" >| "$diff_full"; then
54+
echo "Results are identical"
55+
else
56+
echo "Results differ: $diff_full"
57+
cat "$diff_full" | diffstat
58+
fi
59+
if hash xsel; then
60+
echo "$diff_full" | xsel -i
61+
fi
62+
}
63+
64+
mkdir -p $outdir
65+
66+
if [ ! -e "$outdir/$diff" ]; then
67+
run "$d1" "$v1" "$@"
68+
run "$d2" "$v2" "$@"
4969
fi
5070

71+
show_diff

0 commit comments

Comments
 (0)