Bisect: teach "bisect start" to optionally use one bad and many good revs.
One bad commit is fundamentally needed for bisect to run, and if we beforehand know more good commits, we can narrow the bisect space down without doing the whole tree checkout every time we give good commits. This patch implements: git bisect start [<bad> [<good>...]] [--] [<pathspec>...] as a short-hand for this command sequence: git bisect start git bisect bad $bad git bisect good $good1 $good2... On the other hand, there may be some confusion between revs (<bad> and <good>...) and <pathspec>... if -- is not used and if an invalid rev or a pathspec that looks like a rev is given. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Christian Couder committed
Apr 4, 2007 at 07:12 UTC
38a47fd6e316030ba1e72ea447243cb47adf2505
2 files changed
+99
-26
git-bisect.sh
+82
-23
@@ -1,15 +1,24 @@
1
#!/bin/sh
2
3
USAGE='[start|bad|good|next|reset|visualize|replay|log|run]'
4
-LONG_USAGE='git bisect start [<pathspec>] reset bisect state and start bisection.
5
-git bisect bad [<rev>] mark <rev> a known-bad revision.
6
-git bisect good [<rev>...] mark <rev>... known-good revisions.
7
-git bisect next find next bisection to test and check it out.
8
-git bisect reset [<branch>] finish bisection search and go back to branch.
9
-git bisect visualize show bisect status in gitk.
10
-git bisect replay <logfile> replay bisection log.
11
-git bisect log show bisect log.
12
-git bisect run <cmd>... use <cmd>... to automatically bisect.'
4
+LONG_USAGE='git bisect start [<bad> [<good>...]] [--] [<pathspec>...]
5
+ reset bisect state and start bisection.
6
+git bisect bad [<rev>]
7
+ mark <rev> a known-bad revision.
8
+git bisect good [<rev>...]
9
+ mark <rev>... known-good revisions.
10
+git bisect next
11
+ find next bisection to test and check it out.
12
+git bisect reset [<branch>]
13
+ finish bisection search and go back to branch.
14
+git bisect visualize
15
+ show bisect status in gitk.
16
+git bisect replay <logfile>
17
+ replay bisection log.
18
+git bisect log
19
+ show bisect log.
20
+git bisect run <cmd>...
21
+ use <cmd>... to automatically bisect.'
22
23
. git-sh-setup
24
require_work_tree
@@ -70,14 +79,48 @@ bisect_start() {
79
#
80
# Get rid of any old bisect state
81
#
73
- rm -f "$GIT_DIR/refs/heads/bisect"
74
- rm -rf "$GIT_DIR/refs/bisect/"
82
+ bisect_clean_state
83
mkdir "$GIT_DIR/refs/bisect"
84
+
85
+ #
86
+ # Check for one bad and then some good revisions.
87
+ #
88
+ has_double_dash=0
89
+ for arg; do
90
+ case "$arg" in --) has_double_dash=1; break ;; esac
91
+ done
92
+ orig_args=$(sq "$@")
93
+ bad_seen=0
94
+ while [ $# -gt 0 ]; do
95
+ arg="$1"
96
+ case "$arg" in
97
+ --)
98
+ shift
99
+ break
100
+ ;;
101
+ *)
102
+ rev=$(git-rev-parse --verify "$arg^{commit}" 2>/dev/null) || {
103
+ test $has_double_dash -eq 1 &&
104
+ die "'$arg' does not appear to be a valid revision"
105
+ break
106
+ }
107
+ if [ $bad_seen -eq 0 ]; then
108
+ bad_seen=1
109
+ bisect_write_bad "$rev"
110
+ else
111
+ bisect_write_good "$rev"
112
+ fi
113
+ shift
114
+ ;;
115
+ esac
116
+ done
117
+
118
+ sq "$@" >"$GIT_DIR/BISECT_NAMES"
119
{
120
printf "git-bisect start"
78
- sq "$@"
79
- } >"$GIT_DIR/BISECT_LOG"
80
- sq "$@" >"$GIT_DIR/BISECT_NAMES"
121
+ echo "$orig_args"
122
+ } >>"$GIT_DIR/BISECT_LOG"
123
+ bisect_auto_next
124
}
125
126
bisect_bad() {
@@ -90,12 +133,17 @@ bisect_bad() {
133
*)
134
usage ;;
135
esac || exit
93
- echo "$rev" >"$GIT_DIR/refs/bisect/bad"
94
- echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
136
+ bisect_write_bad "$rev"
137
echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
138
bisect_auto_next
139
}
140
141
+bisect_write_bad() {
142
+ rev="$1"
143
+ echo "$rev" >"$GIT_DIR/refs/bisect/bad"
144
+ echo "# bad: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
145
+}
146
+
147
bisect_good() {
148
bisect_autostart
149
case "$#" in
@@ -106,13 +154,19 @@ bisect_good() {
154
for rev in $revs
155
do
156
rev=$(git-rev-parse --verify "$rev^{commit}") || exit
109
- echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
110
- echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
157
+ bisect_write_good "$rev"
158
echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
159
+
160
done
161
bisect_auto_next
162
}
163
164
+bisect_write_good() {
165
+ rev="$1"
166
+ echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
167
+ echo "# good: "$(git-show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
168
+}
169
+
170
bisect_next_check() {
171
next_ok=no
172
test -f "$GIT_DIR/refs/bisect/bad" &&
@@ -190,14 +244,19 @@ bisect_reset() {
244
usage ;;
245
esac
246
if git checkout "$branch"; then
193
- rm -fr "$GIT_DIR/refs/bisect"
194
- rm -f "$GIT_DIR/refs/heads/bisect" "$GIT_DIR/head-name"
195
- rm -f "$GIT_DIR/BISECT_LOG"
196
- rm -f "$GIT_DIR/BISECT_NAMES"
197
- rm -f "$GIT_DIR/BISECT_RUN"
247
+ rm -f "$GIT_DIR/head-name"
248
+ bisect_clean_state
249
fi
250
}
251
252
+bisect_clean_state() {
253
+ rm -fr "$GIT_DIR/refs/bisect"
254
+ rm -f "$GIT_DIR/refs/heads/bisect"
255
+ rm -f "$GIT_DIR/BISECT_LOG"
256
+ rm -f "$GIT_DIR/BISECT_NAMES"
257
+ rm -f "$GIT_DIR/BISECT_RUN"
258
+}
259
+
260
bisect_replay () {
261
test -r "$1" || {
262
echo >&2 "cannot read $1 for replaying"
t/t6030-bisect-run.sh
+17
-3
@@ -40,8 +40,8 @@ test_expect_success \
40
# We want to automatically find the commit that
41
# introduced "Another" into hello.
42
test_expect_success \
43
- 'git bisect run simple case' \
44
- 'echo "#!/bin/sh" > test_script.sh &&
43
+ '"git bisect run" simple case' \
44
+ 'echo "#"\!"/bin/sh" > test_script.sh &&
45
echo "grep Another hello > /dev/null" >> test_script.sh &&
46
echo "test \$? -ne 0" >> test_script.sh &&
47
chmod +x test_script.sh &&
@@ -49,7 +49,21 @@ test_expect_success \
49
git bisect good $HASH1 &&
50
git bisect bad $HASH4 &&
51
git bisect run ./test_script.sh > my_bisect_log.txt &&
52
- grep "$HASH3 is first bad commit" my_bisect_log.txt'
52
+ grep "$HASH3 is first bad commit" my_bisect_log.txt &&
53
+ git bisect reset'
54
+
55
+# We want to automatically find the commit that
56
+# introduced "Ciao" into hello.
57
+test_expect_success \
58
+ '"git bisect run" with more complex "git bisect start"' \
59
+ 'echo "#"\!"/bin/sh" > test_script.sh &&
60
+ echo "grep Ciao hello > /dev/null" >> test_script.sh &&
61
+ echo "test \$? -ne 0" >> test_script.sh &&
62
+ chmod +x test_script.sh &&
63
+ git bisect start $HASH4 $HASH1 &&
64
+ git bisect run ./test_script.sh > my_bisect_log.txt &&
65
+ grep "$HASH4 is first bad commit" my_bisect_log.txt &&
66
+ git bisect reset'
67
68
#
69
#