Search code examples
performancegitversion-control

What are some alternatives to git rev-list as this is sometimes slow?


I've got a tool in production which calls git rev-list on a single, large repo 10-30 times per minute. I'm seeing git response times vary widely, from around 1 second to as much as 50 seconds (before timeout mechanism abandons the git request).

git rev-list --pretty=raw 2ef9fa0d0fa4c34d57103a0545b3cc96c2552e6f..f5daa48ebcd3cc95a0df683f8c3a3ad64def4a6e

The goal is to see if the two commits are ancestors/descendants and if so, which of the two is the ancestor. I make this call once, if I get output I have my answer, if no output, I swap the commit positions and run again. If no output this time then they are not ancestors/descendants of one another.

Is there another, more efficient way, to find this information? If it comes to it, even suggestions on modeling the commit tree in some structure outside of git are appreciated.

Thanks.


Solution

  • Look at git merge-base first-sha1 second-sha1. If the result is a third sha1, they are not descendents. Otherwise, the result is the older ancestor.

    However, if you could describe at a higher level some of the work flow, there's probably an easier way and you may not have to rely on this. I wrote this article about Branch per Feature: http://dymitruk.com/blog/2012/02/05/branch-per-feature/ It may give you some ideas.