How to get a list of Ostream or Oinfo in a variable from a repository path in gitpython?
Question: I currently have a valid git database with no packfile, but due to a bug
in`git-pack-objects` _(the process crashes with a stack dump file)_ I’m unable
to perform the`git repack`command.

I took a look at the error, and it’s linked to the C nature of the official
git project _(fixing would require changing core`struct`definitions)_ so, this
will takes a lot of time to fix.

The only alternative I found which don’t use C is gitdb _(part of gitpython)_.
However I wasn’t able to find how to use
the[`write_pack()`](http://gitdb.readthedocs.org/en/latest/api.html#gitdb.pack.PackEntity.write_pack)function.  
Or more exactly, I have no idea on how to build
the[`object_iter`](http://gitdb.readthedocs.org/en/latest/api.html#gitdb.pack.PackEntity.create)parameter
from the database path from loose objects.  
I don’t even know the exact class type used in
the[`object_iter`](http://gitdb.readthedocs.org/en/latest/api.html#gitdb.pack.PackEntity.create)list.

So, how to use gitdb for that purpose ?


Answer: Solved!

    
    
    #/usr/bin/python
    import os,sys,zlib,gitdb
    from gitdb.db import LooseObjectDB
    from gitdb.pack import PackEntity
    from gitdb.util import bin_to_hex,hex_to_bin
    
    ldb=LooseObjectDB(sys.argv[1]+'/.git/objects')
    PackEntity.create((ldb.stream(sha) for sha in ldb.sha_iter()),sys.argv[1]+'/.git/objects/pack',object_count=ldb.size(),zlib_compression=zlib.Z_BEST_COMPRESSION)
    

