问题
I currently have a valid git database with no packfile, but due to a bug ingit-pack-objects
(the process crashes with a stack dump file) I’m unable to perform thegit 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 corestruct
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 thewrite_pack()function.
Or more exactly, I have no idea on how to build theobject_iterparameter from the database path from loose objects.
I don’t even know the exact class type used in theobject_iterlist.
So, how to use gitdb for that purpose ?
回答1:
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)
来源:https://stackoverflow.com/questions/33565280/how-to-get-a-list-of-ostream-or-oinfo-in-a-variable-from-a-repository-path-in-gi