Reputation: 689
wanted to get to know how to go through list of all commits (or all from single branch) in git. How does git log
do this (pointers to part of codes would be cool too, I just don't really know where to start)? Can I do it on raw filesystem somehow?
Reasoning is: need to write tool in other language that doesn't need to call system command.
UPDATE: I've read Git internals: Git objects (and following chapters), I do understand that there are also packfiles. Main problem I have is to understand what's going on when we run: git rev-list --all
. Or - for single branch - same command without --all
flag. Is git figures out the head, pulls it from it's object store, checks for parents' shas, pulls those from object store and so one? Or is there some other, faster method?
Upvotes: 1
Views: 650
Reputation: 28981
The branches are mere files in a .git/refs
folder, each file contains a sha1 for a current branch tip. Also, after git gc
all refs could be collected in the .git/packed-refs
file.
Upvotes: 0
Reputation: 2597
Not sure if you have already come across this: LibGit2 : https://github.com/libgit2/libgit2
libgit2 is a portable, pure C implementation of the Git core methods provided as a re-entrant linkable library with a solid API, allowing you to write native speed custom Git applications in any language with bindings.
Its an open source, browsing through the code, should give you some valuable inputs.. E.g: Commit.c
Upvotes: 2