[Toybox] toybox git: Seeking advise to refactor some functionality into lib.c

Moritz Christian Weber mo.c.weber at gmail.com
Sat Apr 9 09:36:30 PDT 2022


Hi,
the previous mention git (clone) toy is making progress, even as I
struggled a lot with my bad C knowledge. I have a 300 LOC multi-command
scaffold, which works in most parts. It supports also git pack indexing as
it make things easier to handle, safes the lifetime of SDCards on embedded
systems (to avoid a decompression of all pack objects and then removing all
objects, which are not touched by checkout) and opens the option to extend
the toy for further commands.

Anyways, I am a little stuck now in the progress due to 3 mandatory library
refactorings for git fetch:

1) zlib inflate() is my biggest pain point. The git pack format indicates
the length of each zlib compressed object in the pack file by the size of
UNCOMPRESSED chars after decompression. Consequently, git fetch expects to
read a zlib compressed object as long as it did not read more than the
announced number of uncompressed char and then expects feedback from
inflate up to which compressed char/position/offset it read (file
pointer/position/offset). After that it reads the next object type,
uncompressed object length and compressed objects data and so on. I guess
it is some optimization for sequential write of the pack format, when
compressing.

I am not sure, if I can get this behavior out of inflate() in deflate.c by
initializing deflate and bitbuf in a special way. Or if I need another
inflate function signature. Any kind of advise would be helpful.

2) sha1sum(): I need a sha1sum() to hash decompressed git objects for
indexing. md5sum.c seems to have the functionality, but again with focus to
file descriptors. Any indication how to reuse sha1sum in another toy?

3) wget_main(): I currently use execv()  both required git fetch http
requests wget.c and read the files afterwards. It works (except from the
fact that file contains 8 char of git protocol response too), but I would
be more elegant to have parts of wget_main() in the library for reusage.
Piping would be also an option, but less elegant than a function. Any
indication which parts and function signature for wget.c could/should be
refactored to the library? I would like to http get/post and get a response
buffer/char* back.

Best regards,
Moritz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20220409/1ec35c22/attachment.html>


More information about the Toybox mailing list