#! /bin/sh
# gitwhat: what is that file

sha1=$1
if [ -z $sha1 ]; then
	echo "usage: gitwhat sha1"
	exit 1
fi

what=`cat-file -t $sha1`
if [ -z "$what" ]; then
	exit 1
fi
echo "type is: $what"

topdir=${sha1:0:2}
last=${sha1:2}
file=.dircache/objects/$topdir/$last

if [ -z $PAGER ]; then
	pager=more
else
	pager=$PAGER
fi

case $what in
blob)
	#head -10 $file
	#$pager $file
	cat-file blob $sha1 | $pager
	;;
tree)
	echo "cannot print binary tree"
	#cat-file tree $sha1 | $pager
	;;
commit)
	cat-file commit $sha1 | $pager
	;;
esac
