#!/bin/sh


# Switch to upstream branch, or start it from scratch
git checkout upstream -- || git symbolic-ref HEAD refs/heads/upstream


for i in $@; do
	echo "Import $(basename $i)."
	
	# Cleanup everything, including hidden files in the top directory
	find . -mindepth 1 -maxdepth 1 '!' -name '.git' -print0 | xargs -0 rm -rf

	# Import
	tar xf $i --strip 1
	git-add .
	git-commit -q -a -m "Import $(basename $i)."

	# Pristine-tar magic
	pristine-tar commit $i

	# Stats
	git gc
	echo "$(basename $i | sed 's/^.*_\(.*\)\.orig.*$/\1/') $(du -s .git | awk '{print $1}')" >> ../git-import-upstream.log
done
