Blocked at parsing packfile for git-clone

I’m stuck on the last stage of recreating git, I got to the point where the server responds with the packfile. However I don’t understand how I’m supposed to parse it when there are multiple objects, as the size that is given is the uncompressed size. I know one solution is with the idx files as mentioned Unpacking Git packfiles , and I think I understand how to use them; the problem is that I don’t know how to obtain such idx file. Since I believe the server only responsds with the packfile data, nothing more.

Hey @Rico-CHEH, you don’t need an .idx file to read a packfile.

Each compressed object is stored as its own zlib stream, and since zlib streams are self-terminating, you can just feed bytes into a zlib decompressor/inflator. It will stop exactly at the end of the compressed object.

Let me know if you’d like further clarification!

Yes you’re absolutely right, it’s just that the site I linked earlier said you couldn’t do that and you definitely can. However right now I am finding that after reading a certain amount of commit objects correctly, I find an object header with byte type 111, I am guessing that this is caused by a misalignment from the reader. But it is really weird how it appears.

Here is some of my own debug output:

There is more output that is correct before this, however it stops right after it cause it cant convert to a zlib reader.

@Rico-CHEH 0b111 = 7 = OBJ_REF_DELTA. That is a valid object type:

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.