Closed cryptix closed 9 years ago
I think we can probably read the idx files in go. surely someone's written a format reader.
List the refs available at .git/HEAD
and .git/refs/*
(anything else?
- to fetch $sha1, we try either:
- look for it in ".git/objects/substr($sha1, 0, 2)/substr($sha, 2)"
- if found, download it and put it in place. (there may be a command for this)
- done \o/
- look for it in packfiles by fetching ".git/objects/pack/*.idx" and looking at each idx with
cat <idx> | git show-index (alternatively can learn to read the format in go)
- if found in an <idx>, download the relevant .pack file, and feed it into
`git index-pack --stdin --fix-thin` which will put it into place.
- done \o/
- else not found <o>
Also:
<cjb> instead of calling index-pack, you could call git unpack-objects, both work
4f3e24cb11bdcd90dc20b8f362d08ffdd2ec860b implements both of @jbenet's purposed techniques to answer fetch commands and you get a working git repo in the end.
Sorry, I got carried away. I only implemented the 2nd (unpack from packed objects).
I need a test repo for the first one.
@cryptix you can get a repo with unpack objects from a repo with packed objects by calling git unpack-objects <PACKFILE
where PACKFILE is a pack file that has been moved away from its original location (see git help unpack-objects).
I'm having some problem with the first method, basically I don't want to implement parsing the index to see which other objects are needed to reconstruct a commit.
Maybe I'm just missing something but I'll leave it as an exercise for another fellow hacker for now and look into pushing.
Some more 'notes':
15:07 <@jbenet> cryptix: have you worked on that git protocol hack?
15:07 <@jbenet> what was missing on it?
15:08 < cryptix> jbenet: i got derailed on the '2nd method to fetch objects'
15:08 <@jbenet> (as a community, we should endeavor to finish the many hacks we have in-flight instead of context switching so much)
15:08 <@jbenet> what was the 2nd method to fetch objects?
15:08 < cryptix> i need to get back into it but you basically need to handle the dependency graph of unpacked objects.. which is quite a mouthfull...
15:09 < cryptix> jbenet: packed vs unpacked objects
15:09 < cryptix> i think i'll scratch that stuff until somebod needs it
15:09 < cryptix> and focus on pushing
15:09 < cryptix> otherwise i need a libgit to handle parsing the objects trees
15:10 < cryptix> cloining from packed is easy and works
15:10 < cryptix> (re meta: totally.)
15:11 <@whyrusleeping> jbenet: i updated rabin
15:11 <@whyrusleeping> btw
15:14 <@jbenet> cryptix https://github.com/libgit2/git2go ?
15:14 <@jbenet> whyrusleeping cool i'll CR in a bit
15:14 <@jbenet> cryptix: i need it :D
15:14 < cryptix> jbenet: yea.. i hope not. those are cgo libgit2 bindings
15:15 < cryptix> jbenet: i think i can pull of push without full fledged git bindings
15:15 <@jbenet> reming me why cgo matters?
15:16 < cryptix> well.. i fear it does all the os.Open stuff in c land
15:16 < cryptix> thus making it hard to port to vfs/ipfs
15:16 < cryptix> if needed we can go through >clone to /tmp and work there> back but id like to make it sexy :))
15:17 < cryptix> and again. i dont think this 2nd method for clone is actually needed if with do the ipfs-git-rehost dance with packed objects for now
15:17 <@jbenet> yeah though non-existent is worse
15:17 < cryptix> if it makes more sense (dedup wise) to store them unpacked id like to discuss that with somebody more familiar with the process
15:18 <@whyrusleeping> implementing the git object format stuff is pretty simple
15:18 < cryptix> or hand it over all together
15:18 <@whyrusleeping> linus wrote some pretty basic formats
15:18 < cryptix> yea the pack format sure
15:19 < cryptix> but then it goes into 'client ask s for hash x' you can just give it the object for that hash but to reconstruct the commit you need all the objects that
it points to, too
15:19 < cryptix> thus you need an index of how they all fit together
15:19 < cryptix> basically you end up doing all the work that a packed repo already did for you
15:19 < cryptix> and i dont want to duplicate that right now
15:20 < cryptix> and again: not necessary for push at all
My last assertion was wrong. For the 'unpacked' repo, the root commit object, unfolds like a tree (DAGs, fuck yea!). Just need to implement basic git object parsing.
@cryptix did you have a look at: https://github.com/ChimeraCoder/gitgo/
tl;dr: the initial git stdio interface is there but i need some feedback on git internals
cc @jbenet @whyrusleeping @chriscool @cjb