#!/bin/bash
-LOG_FILE="../merge.log"
-SHA1_FILE="../SHA1s"
-build_host="ka2"
-build_dir="/scratch/sfr/next"
-build_cmd="bin/build_next"
-[ "$NEXT_BUILD_HOST" ] && build_host="$NEXT_BUILD_HOST"
-[ "$NEXT_BUILD_DIR" ] && build_dir="$NEXT_BUILD_DIR"
-
no_build=false
[ "$1" = "-n" ] && {
shift
no_build=true
}
-tree=$1
-ver=$2
-
-rev=$(git show next-${ver}:Next/SHA1s | sed -n "s/^$tree\t\t*//p")
-[ "$rev" ] || {
- echo "No such tree/date" 1>&2
- exit 1
-}
-
-[ -n "$3" ] && {
- build_host="$3"
+if [ "$1" ]; then
+ tree=$1
shift
-}
-[ -n "$3" ] && {
- build_dir="$3"
+else
+ tree=
+fi
+if [ "$1" ]; then
+ ver="next-${1#next-}"
shift
-}
+else
+ ver=$(git tag -l next-\* | sort | tail -n 1)
+fi
-export NEXT_BUILD_HOST="$build_host"
-export NEXT_BUILD_DIR="$build_dir"
+. "$(dirname $0)/common.sh"
log()
{
return ${PIPESTATUS[0]}
}
+line="$(tail -n 1 $SHA1_FILE)"
+
+# strip everything after the first tab character
+stree=${line%% *}
+if [ "$tree" ]; then
+ [ "$tree" = "$stree" ] || {
+ echo "That is not the last tree merged ($tree v $stree)" 1>&2
+ exit 1
+ }
+else
+ tree="$stree"
+fi
+
+rev=$(git show ${ver}:Next/SHA1s | sed -n "s/^$tree\t\t*//p")
+[ "$rev" ] || {
+ echo "No previous tree/date ($tree/$ver)" 1>&2
+ exit 1
+}
+
bad_rev=$(git rev-parse --verify 'HEAD^2')
-line="$(tail -n 1 $SHA1_FILE)"
tab="\t"
[ $(echo "$tree" | wc -c) -le 8 ] && tab="\t\t"
-expected=$(printf "%s$tab%s" $tree $bad_rev)
-[ "$line" = "$expected" ] || {
+
+# strip evrything up to the last tab character
+srev=${line##* }
+[ "$bad_rev" = "$srev" ] || {
echo "bad last line in $SHA1_FILE" 1>&2
exit 1
}
$no_build && exit 0
-git push -f "$build_host":"$build_dir" master:refs/heads/next || {
+git push -f "${build_host}${build_host:+:}${build_dir}" master:refs/heads/next || {
echo git push failed 1>&2
bash -i || exit
}
-echo "Building using $build_cmd on $build_host"
-ssh "$build_host" "$build_cmd" || {
+"$bin_dir/do_build" "$tree" || {
echo Build failed 1>&2
bash -i || exit
}