git bisect – bug hunting made easy
While developing the script to integrate CJK fonts into GhostScript, we found a strange discrepancy between different versions of GhostScript. With the Yu fonts as distributed with OSX, newer versions of GhostScript crash, while my relatively old version on Debian worked without a problem.
The obvious solution: git bisect!
Fortunately GhostScript is developed in a git repository, so I dived into a git bisect session. For those who don’t know it, git is a distributed, no – it is the distributed revision control system, and adopted more or less by any mayor development team.
To find a problematic commit, git bisect does a binary search through the commits. In my case I had to start between the tags ghostscript-9.06 and HEAD, with a difference of 2099 commits. Binary search reduced this to 9 iterations to find the problematic commit, which took about a bit more than an hour, where I was doing other stuff.
I am very grateful to git bisect for this feature. Big thanks!
Warning This is only a quick intro, and you should definitely read the manual of git bisect.
What I was doing to find the bug in GhostScript is described below. Assuming we have verified that building from HEAD gives us a crashing program, and building from tag ghostscript-9.06 a working program, we did:
- First you start the bisect: git bisect start
- Then you mark HEAD as bad: git bisect bad HEAD
- Then you mark a good commit with git bisect good COMMIT. The COMMIT can be anything commitish, so also a tag. In my case it was git bisect good ghostscript-9.06.
After that git will tell you how many commits, and approximately how many steps. You just rebuild and test. And if it is working you do git bisect good, otherwise git bisect bad. That’s all. At the end you are left with one bad commit (hopefully).
I did a double check by reverting the commit on top of HEAD, which worked out (not always the case), rebuild, and confirmed that the bug was gone.
After confirming the bug on MacOSX, too, I have reported the bug to GhostScript.
Where would we be without git?