如果一个在代码仓库中发现了一个bug,如果能够将其定位到是某一次提交(commit)引起的,然后再来fix这个bug就会比较容易了。基本上可以说,定位到具体的问题点,就可以算解决了一半问题了。
在GIT、Mercurial(hg)等SCM工具中,提供了bisect命令用于二分查找(binary section search),只需要通过命令告诉GIT或Mercurial工具就可自动帮我们checkout到对应的中间版本之下,然后通过自己试验,循环地运行bisect命令,即可较快地找到哪个commit引入的bug(或者fix了某个bug)。
今天刚好就通过Mercurial (hg)的 “hg bisect”命令查找到了一个commit,它修复Xen-unstable tree里面的nested virtualization中L2 guest的AVX指令不能正常执行的bug。 BTW,这个changeset是:changeset 25789:825f78461622
可以通过 “man hg”命令,然后找到bisect命令的解释,使用起来非常方便的。
下面是使用hg bisect命令进行二分查找的过程示例:
# better to have a reset to make the repo clean
[root@vt-snb7 xen-unstable.hg]# hg bisect -r
[root@vt-snb7 xen-unstable.hg]# hg bisect -b 25765
[root@vt-snb7 xen-unstable.hg]# hg bisect -g 26319
Testing changeset 26042:3696dd6a7836 (554 changesets remaining, ~9 tests)
462 files updated, 0 files merged, 39 files removed, 0 files unresolved
# just have a double check 'hg bisect' did the right thing.
# 'do not' use 'hg log' for this usage
[root@vt-snb7 xen-unstable.hg]# hg parent
changeset: 26042:3696dd6a7836
user: Ian Jackson
date: Tue Oct 09 18:00:00 2012 +0100
summary: docs, build: Do not ignore install-docs errors
[root@vt-snb7 xen-unstable.hg]# hg bisect -g
Testing changeset 25903:5e4a00b4114c (277 changesets remaining, ~8 tests)
239 files updated, 0 files merged, 23 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -b
Testing changeset 25972:16aaeaa66ef9 (139 changesets remaining, ~7 tests)
175 files updated, 0 files merged, 3 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -g
Testing changeset 25937:32187301ecc5 (69 changesets remaining, ~6 tests)
66 files updated, 0 files merged, 6 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -b
Testing changeset 25954:8f8fabafec86 (35 changesets remaining, ~5 tests)
43 files updated, 0 files merged, 0 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -g
Testing changeset 25945:0604d4676c6b (17 changesets remaining, ~4 tests)
17 files updated, 0 files merged, 2 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -g
Testing changeset 25941:795c493fe561 (8 changesets remaining, ~3 tests)
6 files updated, 0 files merged, 1 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -g
Testing changeset 25939:b49f7bf52fa9 (4 changesets remaining, ~2 tests)
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -g
Testing changeset 25938:8f658b463b78 (2 changesets remaining, ~1 tests)
4 files updated, 0 files merged, 0 files removed, 0 files unresolved
[root@vt-snb7 xen-unstable.hg]# hg bisect -g
The first good revision is:
changeset: 25938:8f658b463b78
user: Jan Beulich
date: Fri Sep 21 17:02:46 2012 +0200
summary: x86: enable VIA CPU support