Bisect: implement "bisect skip" to mark untestable revisions.
When there are some "skip"ped revisions, we add the '--bisect-all' option to "git rev-list --bisect-vars". Then we filter out the "skip"ped revisions from the result of the rev-list command, and we modify the "bisect_rev" var accordingly. We don't always use "--bisect-all" because it is slower than "--bisect-vars" or "--bisect". When we cannot find for sure the first bad commit because of "skip"ped commits, we print the hash of each possible first bad commit and then we exit with code 2. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Christian Couder committed
Oct 22, 2007 at 07:48 UTC
97e1c51e15d94f523c67a499ecb633b0e20324cb
2 files changed
+190
-6
git-bisect.sh
+119
-6
@@ -17,6 +17,8 @@ git bisect replay <logfile>
17
replay bisection log.
18
git bisect log
19
show bisect log.
20
+git bisect skip [<rev>...]
21
+ mark <rev>... untestable revisions.
22
git bisect run <cmd>...
23
use <cmd>... to automatically bisect.'
24
@@ -163,6 +165,28 @@ bisect_write_good() {
165
echo "# good: "$(git show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
166
}
167
168
+bisect_skip() {
169
+ bisect_autostart
170
+ case "$#" in
171
+ 0) revs=$(git rev-parse --verify HEAD) || exit ;;
172
+ *) revs=$(git rev-parse --revs-only --no-flags "$@") &&
173
+ test '' != "$revs" || die "Bad rev input: $@" ;;
174
+ esac
175
+ for rev in $revs
176
+ do
177
+ rev=$(git rev-parse --verify "$rev^{commit}") || exit
178
+ bisect_write_skip "$rev"
179
+ echo "git-bisect skip $rev" >>"$GIT_DIR/BISECT_LOG"
180
+ done
181
+ bisect_auto_next
182
+}
183
+
184
+bisect_write_skip() {
185
+ rev="$1"
186
+ echo "$rev" >"$GIT_DIR/refs/bisect/skip-$rev"
187
+ echo "# skip: "$(git show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
188
+}
189
+
190
bisect_next_check() {
191
missing_good= missing_bad=
192
git show-ref -q --verify refs/bisect/bad || missing_bad=t
@@ -205,17 +229,97 @@ bisect_auto_next() {
229
bisect_next_check && bisect_next || :
230
}
231
232
+filter_skipped() {
233
+ _eval="$1"
234
+ _skip="$2"
235
+
236
+ if [ -z "$_skip" ]; then
237
+ eval $_eval
238
+ return
239
+ fi
240
+
241
+ # Let's parse the output of:
242
+ # "git rev-list --bisect-vars --bisect-all ..."
243
+ eval $_eval | while read hash line
244
+ do
245
+ case "$VARS,$FOUND,$TRIED,$hash" in
246
+ # We display some vars.
247
+ 1,*,*,*) echo "$hash $line" ;;
248
+
249
+ # Split line.
250
+ ,*,*,---*) ;;
251
+
252
+ # We had nothing to search.
253
+ ,,,bisect_rev*)
254
+ echo "bisect_rev="
255
+ VARS=1
256
+ ;;
257
+
258
+ # We did not find a good bisect rev.
259
+ # This should happen only if the "bad"
260
+ # commit is also a "skip" commit.
261
+ ,,*,bisect_rev*)
262
+ echo "bisect_rev=$TRIED"
263
+ VARS=1
264
+ ;;
265
+
266
+ # We are searching.
267
+ ,,*,*)
268
+ TRIED="${TRIED:+$TRIED|}$hash"
269
+ case "$_skip" in
270
+ *$hash*) ;;
271
+ *)
272
+ echo "bisect_rev=$hash"
273
+ echo "bisect_tried=\"$TRIED\""
274
+ FOUND=1
275
+ ;;
276
+ esac
277
+ ;;
278
+
279
+ # We have already found a rev to be tested.
280
+ ,1,*,bisect_rev*) VARS=1 ;;
281
+ ,1,*,*) ;;
282
+
283
+ # ???
284
+ *) die "filter_skipped error " \
285
+ "VARS: '$VARS' " \
286
+ "FOUND: '$FOUND' " \
287
+ "TRIED: '$TRIED' " \
288
+ "hash: '$hash' " \
289
+ "line: '$line'"
290
+ ;;
291
+ esac
292
+ done
293
+}
294
+
295
+exit_if_skipped_commits () {
296
+ _tried=$1
297
+ if expr "$_tried" : ".*[|].*" > /dev/null ; then
298
+ echo "There are only 'skip'ped commit left to test."
299
+ echo "The first bad commit could be any of:"
300
+ echo "$_tried" | sed -e 's/[|]/\n/g'
301
+ echo "We cannot bisect more!"
302
+ exit 2
303
+ fi
304
+}
305
+
306
bisect_next() {
307
case "$#" in 0) ;; *) usage ;; esac
308
bisect_autostart
309
bisect_next_check good
310
311
+ skip=$(git for-each-ref --format='%(objectname)' \
312
+ "refs/bisect/skip-*" | tr '[\012]' ' ') || exit
313
+
314
+ BISECT_OPT=''
315
+ test -n "$skip" && BISECT_OPT='--bisect-all'
316
+
317
bad=$(git rev-parse --verify refs/bisect/bad) &&
318
good=$(git for-each-ref --format='^%(objectname)' \
319
"refs/bisect/good-*" | tr '[\012]' ' ') &&
216
- eval="git rev-list --bisect-vars $good $bad --" &&
320
+ eval="git rev-list --bisect-vars $BISECT_OPT $good $bad --" &&
321
eval="$eval $(cat "$GIT_DIR/BISECT_NAMES")" &&
218
- eval=$(eval "$eval") &&
322
+ eval=$(filter_skipped "$eval" "$skip") &&
323
eval "$eval" || exit
324
325
if [ -z "$bisect_rev" ]; then
@@ -223,11 +327,16 @@ bisect_next() {
327
exit 1
328
fi
329
if [ "$bisect_rev" = "$bad" ]; then
330
+ exit_if_skipped_commits "$bisect_tried"
331
echo "$bisect_rev is first bad commit"
332
git diff-tree --pretty $bisect_rev
333
exit 0
334
fi
335
336
+ # We should exit here only if the "bad"
337
+ # commit is also a "skip" commit (see above).
338
+ exit_if_skipped_commits "$bisect_rev"
339
+
340
echo "Bisecting: $bisect_nr revisions left to test after this"
341
echo "$bisect_rev" >"$GIT_DIR/refs/heads/new-bisect"
342
git checkout -q new-bisect || exit
@@ -286,15 +395,17 @@ bisect_replay () {
395
eval "$cmd"
396
;;
397
good)
289
- echo "$rev" >"$GIT_DIR/refs/bisect/good-$rev"
290
- echo "# good: "$(git show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
398
+ bisect_write_good "$rev"
399
echo "git-bisect good $rev" >>"$GIT_DIR/BISECT_LOG"
400
;;
401
bad)
294
- echo "$rev" >"$GIT_DIR/refs/bisect/bad"
295
- echo "# bad: "$(git show-branch $rev) >>"$GIT_DIR/BISECT_LOG"
402
+ bisect_write_bad "$rev"
403
echo "git-bisect bad $rev" >>"$GIT_DIR/BISECT_LOG"
404
;;
405
+ skip)
406
+ bisect_write_skip "$rev"
407
+ echo "git-bisect skip $rev" >>"$GIT_DIR/BISECT_LOG"
408
+ ;;
409
*)
410
echo >&2 "?? what are you talking about?"
411
exit 1 ;;
@@ -362,6 +473,8 @@ case "$#" in
473
bisect_bad "$@" ;;
474
good)
475
bisect_good "$@" ;;
476
+ skip)
477
+ bisect_skip "$@" ;;
478
next)
479
# Not sure we want "next" at the UI level anymore.
480
bisect_next "$@" ;;
t/t6030-bisect-porcelain.sh
+71
@@ -71,6 +71,63 @@ test_expect_success 'bisect start with one bad and good' '
71
git bisect next
72
'
73
74
+# $HASH1 is good, $HASH4 is bad, we skip $HASH3
75
+# but $HASH2 is bad,
76
+# so we should find $HASH2 as the first bad commit
77
+test_expect_success 'bisect skip: successfull result' '
78
+ git bisect reset &&
79
+ git bisect start $HASH4 $HASH1 &&
80
+ git bisect skip &&
81
+ git bisect bad > my_bisect_log.txt &&
82
+ grep "$HASH2 is first bad commit" my_bisect_log.txt &&
83
+ git bisect reset
84
+'
85
+
86
+# $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
87
+# so we should not be able to tell the first bad commit
88
+# among $HASH2, $HASH3 and $HASH4
89
+test_expect_success 'bisect skip: cannot tell between 3 commits' '
90
+ git bisect start $HASH4 $HASH1 &&
91
+ git bisect skip || return 1
92
+
93
+ if git bisect skip > my_bisect_log.txt
94
+ then
95
+ echo Oops, should have failed.
96
+ false
97
+ else
98
+ test $? -eq 2 &&
99
+ grep "first bad commit could be any of" my_bisect_log.txt &&
100
+ ! grep $HASH1 my_bisect_log.txt &&
101
+ grep $HASH2 my_bisect_log.txt &&
102
+ grep $HASH3 my_bisect_log.txt &&
103
+ grep $HASH4 my_bisect_log.txt &&
104
+ git bisect reset
105
+ fi
106
+'
107
+
108
+# $HASH1 is good, $HASH4 is bad, we skip $HASH3
109
+# but $HASH2 is good,
110
+# so we should not be able to tell the first bad commit
111
+# among $HASH3 and $HASH4
112
+test_expect_success 'bisect skip: cannot tell between 2 commits' '
113
+ git bisect start $HASH4 $HASH1 &&
114
+ git bisect skip || return 1
115
+
116
+ if git bisect good > my_bisect_log.txt
117
+ then
118
+ echo Oops, should have failed.
119
+ false
120
+ else
121
+ test $? -eq 2 &&
122
+ grep "first bad commit could be any of" my_bisect_log.txt &&
123
+ ! grep $HASH1 my_bisect_log.txt &&
124
+ ! grep $HASH2 my_bisect_log.txt &&
125
+ grep $HASH3 my_bisect_log.txt &&
126
+ grep $HASH4 my_bisect_log.txt &&
127
+ git bisect reset
128
+ fi
129
+'
130
+
131
# We want to automatically find the commit that
132
# introduced "Another" into hello.
133
test_expect_success \
@@ -99,6 +156,20 @@ test_expect_success \
156
grep "$HASH4 is first bad commit" my_bisect_log.txt &&
157
git bisect reset'
158
159
+# $HASH1 is good, $HASH5 is bad, we skip $HASH3
160
+# but $HASH4 is good,
161
+# so we should find $HASH5 as the first bad commit
162
+HASH5=
163
+test_expect_success 'bisect skip: add line and then a new test' '
164
+ add_line_into_file "5: Another new line." hello &&
165
+ HASH5=$(git rev-parse --verify HEAD) &&
166
+ git bisect start $HASH5 $HASH1 &&
167
+ git bisect skip &&
168
+ git bisect good > my_bisect_log.txt &&
169
+ grep "$HASH5 is first bad commit" my_bisect_log.txt &&
170
+ git bisect reset
171
+'
172
+
173
#
174
#
175
test_done