The bisect
command helps you find the changeset that introduced a bug. It often happens that you realize that something is broken and that it has been broken for a while. With hg bisect
, you can figure out exactly when it became broken.
It works like this. You start by marking the current revision as bad since it contains the bug:
$ hg bisect --bad
You then jump back in history to a point where you hope the bug is not present:
$ hg update -r -100
89 files updated, 0 files merged, 30 files removed, 0 files unresolved
You have to test your software at this revision and if the bug is not present, then you can mark it as good:
$ hg bisect --good
Testing changeset 11964:79bd860b8eb7 (81 changesets remaining, ~6 tests)
36 files updated, 0 files merged, 22 files removed, 0 files unresolved
When you marked it as good, Mercurial updated your working copy to a place roughly in the middle between the good and bad changesets. You now have to test this changeset and mark it good/bad.
$ hg bisect --good
Testing changeset 11985:81edef14922e (41 changesets remaining, ~5 tests)
23 files updated, 0 files merged, 26 files removed, 0 files unresolved
I continue like this until Mercurial has narrowed the search down to a single changeset:
$ hg bisect --bad
Testing changeset 11975:21884b433c51 (20 changesets remaining, ~4 tests)
18 files updated, 0 files merged, 8 files removed, 0 files unresolved
$ hg bisect --good
Testing changeset 11980:c443e95d295b (10 changesets remaining, ~3 tests)
5 files updated, 0 files merged, 10 files removed, 0 files unresolved
$ hg bisect --good
Testing changeset 11982:56d9b73487ff (5 changesets remaining, ~2 tests)
2 files updated, 0 files merged, 4 files removed, 0 files unresolved
$ hg bisect --bad
Testing changeset 11981:518b90d66fad (2 changesets remaining, ~1 tests)
2 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ hg bisect --bad
The first bad revision is:
changeset: 11981:518b90d66fad
user: Pradeepkumar Gayam <[email protected]>
date: Wed Aug 18 05:55:56 2010 +0530
summary: tests: unify test-merge8
You still have to do the debugging yourself, but using hg bisect
saves you from keeping track of which changesets you have already tested and which you still need to test. You could use a bunch of postit notes for this, but it's much nicer to let Mercurial do it. This is especially true when the changeset graph is is non-linear because of merges.
So all in all, hg bisect
helps you do a search for a faulty changeset in logarithmic time, without you having to keep track of where you are in the search.