0

I am trying to learn how to manipulate the dulwich repository and I can't find how to delete or unpack objects. For example, in the following code:

from dulwich import porcelain
from dulwich.repo import Repo
from dulwich.objects import Blob

myrepo = Repo.init_bare( 'dulwich_repo', mkdir=True)
myblob = Blob.from_string( b'This is my content.' )
myrepo.object_store.add_object(myblob)
porcelain.repack(myrepo)

Now my object folder only contains one pack and no loose objects. How can I "unpack" it? (meaning, recover the loose object in its respective folder and remove the '.pack' and '.idx' files) How can I then delete the now-loose-again object?

Nordico
  • 1,226
  • 2
  • 15
  • 31
  • 1
    Dulwich doesn't really provide a convenient way to do this, since there is generally no reason to split up pack files into separate loose objects. Can you provide some more background as to what you're trying to achieve? – jelmer Dec 30 '19 at 22:53
  • Thanks for the reply. Basically I'm interested in using the dulwich repo as an api to keep an object store for the files of a program. It naturally offers some convenient tools such as easily preventing content duplication and might eventually be interested in the push-pull tools to keep synchronicity in various machines. – Nordico Dec 31 '19 at 10:03
  • In particular for the unpacking, I am thinking in cases when I would need this to revert "bad packing": calling pack several times after small additions leading to packs that are bigger than the original content. Here I would like to be able to unpack this small packs and repack all together. More general, I'm developing for big file-bases where we are reaching the limit on the number of files before reaching the disk space limit, so we might need the versatility to pack and unpack depending on new file additions for better scaling. – Nordico Dec 31 '19 at 10:04
  • Repack should generally take care of that - i.e. packing smaller packs into bigger packs. You may be able to unpack files from packs in Dulwich, but that would require some poking at lower level functions. There is no higher level interface for this, since it's not a normal operation in Git repositories. – jelmer Dec 31 '19 at 17:20
  • You mean the method `porcelain.repack`? Whenever I use it, it just creates a new pack with all the loose objects, it does nothing to the already existing packs. Also, what about deleting objects? If I can't delete single objects, is there a way to easily keep track/list of the objects to keep and then activate the garbage collector or something like this? – Nordico Jan 03 '20 at 09:44
  • Unfortunately garbage collection is not yet implemented - help would be great. See https://github.com/dulwich/dulwich/issues/92 – jelmer Jan 04 '20 at 16:54

0 Answers0