#! /bin/sh
# gitlist: list some git objects/types
# (by selected target type: blob, tree, commit, all)

target=$1
if [ -z "$target" ]; then
	echo "usage: gitlist type {blob, tree, commit, or all}"
	exit 1
fi


subdir=.dircache/objects/

for high in 0 1 2 3 4 5 6 7 8 9 a b c d e f ; do
    for low in 0 1 2 3 4 5 6 7 8 9 a b c d e f ; do
	top=$high$low

	for f in $subdir/$top/* ; do
		if [ ! -r $f ]; then
			continue
		fi
		base=`basename $f`
		type=`cat-file -t $top$base`
		if [ $target == "all" -o $target == $type ]; then
			echo $top$base : $type 
		fi
	done
    done
done
