gc.sh: improve loose object handling