#!/bin/sh
set -e
tarf="$1"
test -s "$tarf"
for d in a b; do
	rm -rf $d
	mkdir -p $d
	tar -C $d --transform="s/bugzilla-[^\/]\+\///g" -xzf "$tarf"
done

if ! ./debian/maintenance/30_exit1onerror.sh b; then
	if find b -name "*.rej"; then
		meld a b
		if ! find b -name "*.rej"; then
			find b -name "*.orig" -exec rm {} \;
			diff -Naur a b >"$0.patch"
		fi
	fi
else
	rm -rf a b $0.patch
fi
