How to get a list of Ostream or Oinfo in a variable from a repository path in gitpython?

大兔子大兔子 提交于 2019-12-10 15:18:47

问题


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 repackcommand.

I took a look at the error, and it’s linked to the C nature of the official git project (fixing would require changing corestructdefinitions) 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!