@matheusbsbs / matheus-bagliano / commits / 1b249ffe8d
Fork 0

bisect: fix quoting TRIED revs when "bad" commit is also "skip"ped

When the "bad" commit was also "skip"ped and when more than one commit was skipped, the "filter_skipped" function would have printed something like: bisect_rev=<hash1>|<hash2> (where <hash1> and <hash2> are hexadecimal sha1 hashes) and this would have been evaled later as piping "bisect_rev=<hash1>" into "<hash2>", which would have failed. So this patch makes the "filter_skipped" function properly quote what it outputs, so that it will print something like: bisect_rev='<hash1>|<hash2>' which will be properly evaled later. The caller was not stopping properly because the scriptlet this function returned to be evaled was not strung together with && and because of this, an error in an earlier part of the output was simply ignored. A test case is added to the test suite. And while at it, we also initialize the VARS, FOUND and TRIED variables, so that we protect ourselves from environment variables the user may have with these names. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Feb 27, 2009 at 07:31 UTC 1b249ffe8dff12849e3e215b46b245daecfadba0
2 files changed +66 -35
git-bisect.sh
+41 -35
@@ -269,56 +269,62 @@ filter_skipped() {
269
270 # Let's parse the output of:
271 # "git rev-list --bisect-vars --bisect-all ..."
272 - eval_rev_list "$_eval" | while read hash line
273 - do
274 - case "$VARS,$FOUND,$TRIED,$hash" in
275 - # We display some vars.
276 - 1,*,*,*) echo "$hash $line" ;;
277 -
278 - # Split line.
279 - ,*,*,---*) ;;
280 -
281 - # We had nothing to search.
272 + eval_rev_list "$_eval" | {
273 + VARS= FOUND= TRIED=
274 + while read hash line
275 + do
276 + case "$VARS,$FOUND,$TRIED,$hash" in
277 + 1,*,*,*)
278 + # "bisect_foo=bar" read from rev-list output.
279 + echo "$hash &&"
280 + ;;
281 + ,*,*,---*)
282 + # Separator
283 + ;;
284 ,,,bisect_rev*)
283 - echo "bisect_rev="
285 + # We had nothing to search.
286 + echo "bisect_rev= &&"
287 VARS=1
288 ;;
286 -
287 - # We did not find a good bisect rev.
288 - # This should happen only if the "bad"
289 - # commit is also a "skip" commit.
289 ,,*,bisect_rev*)
291 - echo "bisect_rev=$TRIED"
290 + # We did not find a good bisect rev.
291 + # This should happen only if the "bad"
292 + # commit is also a "skip" commit.
293 + echo "bisect_rev='$TRIED' &&"
294 VARS=1
295 ;;
294 -
295 - # We are searching.
296 ,,*,*)
297 + # We are searching.
298 TRIED="${TRIED:+$TRIED|}$hash"
299 case "$_skip" in
300 *$hash*) ;;
301 *)
301 - echo "bisect_rev=$hash"
302 - echo "bisect_tried=\"$TRIED\""
302 + echo "bisect_rev=$hash &&"
303 + echo "bisect_tried='$TRIED' &&"
304 FOUND=1
305 ;;
306 esac
307 ;;
307 -
308 - # We have already found a rev to be tested.
309 - ,1,*,bisect_rev*) VARS=1 ;;
310 - ,1,*,*) ;;
311 -
312 - # ???
313 - *) die "filter_skipped error " \
314 - "VARS: '$VARS' " \
315 - "FOUND: '$FOUND' " \
316 - "TRIED: '$TRIED' " \
317 - "hash: '$hash' " \
318 - "line: '$line'"
319 - ;;
320 - esac
321 - done
308 + ,1,*,bisect_rev*)
309 + # We have already found a rev to be tested.
310 + VARS=1
311 + ;;
312 + ,1,*,*)
313 + ;;
314 + *)
315 + # Unexpected input
316 + echo "die 'filter_skipped error'"
317 + die "filter_skipped error " \
318 + "VARS: '$VARS' " \
319 + "FOUND: '$FOUND' " \
320 + "TRIED: '$TRIED' " \
321 + "hash: '$hash' " \
322 + "line: '$line'"
323 + ;;
324 + esac
325 + done
326 + echo ':'
327 + }
328 }
329
330 exit_if_skipped_commits () {
t/t6030-bisect-porcelain.sh
+25
@@ -224,6 +224,31 @@ test_expect_success 'bisect skip: cannot tell between 2 commits' '
224 fi
225 '
226
227 +# $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3
228 +# and $HASH2 is good,
229 +# so we should not be able to tell the first bad commit
230 +# among $HASH3 and $HASH4
231 +test_expect_success 'bisect skip: with commit both bad and skipped' '
232 + git bisect start &&
233 + git bisect skip &&
234 + git bisect bad &&
235 + git bisect good $HASH1 &&
236 + git bisect skip &&
237 + if git bisect good > my_bisect_log.txt
238 + then
239 + echo Oops, should have failed.
240 + false
241 + else
242 + test $? -eq 2 &&
243 + grep "first bad commit could be any of" my_bisect_log.txt &&
244 + ! grep $HASH1 my_bisect_log.txt &&
245 + ! grep $HASH2 my_bisect_log.txt &&
246 + grep $HASH3 my_bisect_log.txt &&
247 + grep $HASH4 my_bisect_log.txt &&
248 + git bisect reset
249 + fi
250 +'
251 +
252 # We want to automatically find the commit that
253 # introduced "Another" into hello.
254 test_expect_success \