How does git file log internally works?
I am very interested how git log -- filename
works internally.
Does this go through all tree-objects in the repository, search for the filename-string and then returns all log-messages from the commit-objects that uses different blob-ids? (开发者_StackOverflowI cannot imagine this works for large repositories.)
Background:
I have to index the whole content of git repositories with Apache Lucene and need fast file histories. When git log --filename
is a slow command, maybe it's better to add all blob-IDs of a commit into a Lucene-Commit-document to get fast file histories?
That's pretty much what it does, and it's a fairly fast operation. Plain ol' git log
walks the whole commit tree, so that work is a given. In order to select only the commits which touch a file, all it has to do is read each commit object, take their tree, read that tree, and so on down until it reaches the file in question, and get the SHA1 of the blob. It can then just check if the SHA1 is the same as in the previous commit.
It certainly doesn't have to go through all trees, just the ones necessary to check on that blob, and "search for the filename-string" is a bit misleading - the tree data is in a known format.
So sure, it takes a bit longer than just traversing the history, but not a ton. Just a few extra reads per commit, not an increase in algorithmic complexity.
精彩评论