#! /bin/sh
# run in a tla working dir to view diff between two revisions on command line
# uses ~/tmp as a directory for temporary files
#
# usage:
#   tla-diffrevs [-d linux] patch-42 patch-43
# 

subdir=
if test "$1" = "-d"; then
	subdir=$2
	shift
	shift
fi
a=${1?}
b=${2?}
d="$HOME/tmp/`basename $0`"
set -e
v="`tla tree-version`"
rm -rf "$d"
mkdir -p "$d"
cd "$d"

tla get -s "$v"--$a wd-a && sh -c "cd wd-a && tla-export ../a-exp"
tla get -s "$v"--$b wd-b && sh -c "cd wd-b && tla-export ../b-exp"
#tla changeset wd-a wd-b changes
#tla show-changeset --diffs changes
#true "the changeset is in `pwd`/changes"

# maybe use just a subdirectory
a=a-exp
b=b-exp
if test "$subdir"; then
	sub=`basename $subdir`
	mv $a/$subdir $sub-a
	mv $b/$subdir $sub-b
	rm -rf $a $b
	a=$sub-a
	b=$sub-b
fi

diff -urNp $a $b
