bisect: make "git bisect" use new "--next-all" bisect-helper function
This patch replace the "--next-exit" option of "git bisect--helper" with a "--next-all" option that does merge base checking using the "check_good_are_ancestors_of_bad" function implemented in "bisect.c" in a former patch. The new "--next-all" option is then used in "git-bisect.sh" instead of the "--next-exit" option, and all the shell functions in "git-bisect.sh" that are now unused are removed. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
May 9, 2009 at 17:55 UTC
0871984d304c9201b85897743eae583cd165106d
4 files changed
+13
-134
bisect.c
+3
-1
@@ -830,7 +830,7 @@ static void check_good_are_ancestors_of_bad(const char *prefix)
830
* the bisection process finished successfully.
831
* In this case the calling shell script should exit 0.
832
*/
833
-int bisect_next_exit(const char *prefix)
833
+int bisect_next_all(const char *prefix)
834
{
835
struct rev_info revs;
836
struct commit_list *tried;
@@ -841,6 +841,8 @@ int bisect_next_exit(const char *prefix)
841
if (read_bisect_refs())
842
die("reading bisect refs failed");
843
844
+ check_good_are_ancestors_of_bad(prefix);
845
+
846
bisect_rev_setup(&revs, prefix);
847
848
bisect_common(&revs, &reaches, &all);
bisect.h
+1
-1
@@ -27,7 +27,7 @@ struct rev_list_info {
27
28
extern int show_bisect_vars(struct rev_list_info *info, int reaches, int all);
29
30
-extern int bisect_next_exit(const char *prefix);
30
+extern int bisect_next_all(const char *prefix);
31
32
extern int estimate_bisect_steps(int all);
33
builtin-bisect--helper.c
+7
-7
@@ -4,24 +4,24 @@
4
#include "bisect.h"
5
6
static const char * const git_bisect_helper_usage[] = {
7
- "git bisect--helper --next-exit",
7
+ "git bisect--helper --next-all",
8
NULL
9
};
10
11
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
12
{
13
- int next_exit = 0;
13
+ int next_all = 0;
14
struct option options[] = {
15
- OPT_BOOLEAN(0, "next-exit", &next_exit,
16
- "output bisect result and exit instuctions"),
15
+ OPT_BOOLEAN(0, "next-all", &next_all,
16
+ "perform 'git bisect next'"),
17
OPT_END()
18
};
19
20
argc = parse_options(argc, argv, options, git_bisect_helper_usage, 0);
21
22
- if (!next_exit)
22
+ if (!next_all)
23
usage_with_options(git_bisect_helper_usage, options);
24
25
- /* next-exit */
26
- return bisect_next_exit(prefix);
25
+ /* next-all */
26
+ return bisect_next_all(prefix);
27
}
git-bisect.sh
+2
-125
@@ -167,10 +167,6 @@ is_expected_rev() {
167
test "$1" = $(cat "$GIT_DIR/BISECT_EXPECTED_REV")
168
}
169
170
-mark_expected_rev() {
171
- echo "$1" > "$GIT_DIR/BISECT_EXPECTED_REV"
172
-}
173
-
170
check_expected_revs() {
171
for _rev in "$@"; do
172
if ! is_expected_rev "$_rev"; then
@@ -269,132 +265,13 @@ bisect_auto_next() {
265
bisect_next_check && bisect_next || :
266
}
267
272
-bisect_checkout() {
273
- _rev="$1"
274
- _msg="$2"
275
- echo "Bisecting: $_msg"
276
- mark_expected_rev "$_rev"
277
- git checkout -q "$_rev" -- || exit
278
- git show-branch "$_rev"
279
-}
280
-
281
-is_among() {
282
- _rev="$1"
283
- _list="$2"
284
- case "$_list" in *$_rev*) return 0 ;; esac
285
- return 1
286
-}
287
-
288
-handle_bad_merge_base() {
289
- _badmb="$1"
290
- _good="$2"
291
- if is_expected_rev "$_badmb"; then
292
- cat >&2 <<EOF
293
-The merge base $_badmb is bad.
294
-This means the bug has been fixed between $_badmb and [$_good].
295
-EOF
296
- exit 3
297
- else
298
- cat >&2 <<EOF
299
-Some good revs are not ancestor of the bad rev.
300
-git bisect cannot work properly in this case.
301
-Maybe you mistake good and bad revs?
302
-EOF
303
- exit 1
304
- fi
305
-}
306
-
307
-handle_skipped_merge_base() {
308
- _mb="$1"
309
- _bad="$2"
310
- _good="$3"
311
- cat >&2 <<EOF
312
-Warning: the merge base between $_bad and [$_good] must be skipped.
313
-So we cannot be sure the first bad commit is between $_mb and $_bad.
314
-We continue anyway.
315
-EOF
316
-}
317
-
318
-#
319
-# "check_merge_bases" checks that merge bases are not "bad".
320
-#
321
-# - If one is "good", that's good, we have nothing to do.
322
-# - If one is "bad", it means the user assumed something wrong
323
-# and we must exit.
324
-# - If one is "skipped", we can't know but we should warn.
325
-# - If we don't know, we should check it out and ask the user to test.
326
-#
327
-# In the last case we will return 1, and otherwise 0.
328
-#
329
-check_merge_bases() {
330
- _bad="$1"
331
- _good="$2"
332
- _skip="$3"
333
- for _mb in $(git merge-base --all $_bad $_good)
334
- do
335
- if is_among "$_mb" "$_good"; then
336
- continue
337
- elif test "$_mb" = "$_bad"; then
338
- handle_bad_merge_base "$_bad" "$_good"
339
- elif is_among "$_mb" "$_skip"; then
340
- handle_skipped_merge_base "$_mb" "$_bad" "$_good"
341
- else
342
- bisect_checkout "$_mb" "a merge base must be tested"
343
- return 1
344
- fi
345
- done
346
- return 0
347
-}
348
-
349
-#
350
-# "check_good_are_ancestors_of_bad" checks that all "good" revs are
351
-# ancestor of the "bad" rev.
352
-#
353
-# If that's not the case, we need to check the merge bases.
354
-# If a merge base must be tested by the user we return 1 and
355
-# otherwise 0.
356
-#
357
-check_good_are_ancestors_of_bad() {
358
- test -f "$GIT_DIR/BISECT_ANCESTORS_OK" &&
359
- return
360
-
361
- _bad="$1"
362
- _good=$(echo $2 | sed -e 's/\^//g')
363
- _skip="$3"
364
-
365
- # Bisecting with no good rev is ok
366
- test -z "$_good" && return
367
-
368
- _side=$(git rev-list $_good ^$_bad)
369
- if test -n "$_side"; then
370
- # Return if a checkout was done
371
- check_merge_bases "$_bad" "$_good" "$_skip" || return
372
- fi
373
-
374
- : > "$GIT_DIR/BISECT_ANCESTORS_OK"
375
-
376
- return 0
377
-}
378
-
268
bisect_next() {
269
case "$#" in 0) ;; *) usage ;; esac
270
bisect_autostart
271
bisect_next_check good
272
384
- # Get bad, good and skipped revs
385
- bad=$(git rev-parse --verify refs/bisect/bad) &&
386
- good=$(git for-each-ref --format='^%(objectname)' \
387
- "refs/bisect/good-*" | tr '\012' ' ') &&
388
- skip=$(git for-each-ref --format='%(objectname)' \
389
- "refs/bisect/skip-*" | tr '\012' ' ') || exit
390
-
391
- # Maybe some merge bases must be tested first
392
- check_good_are_ancestors_of_bad "$bad" "$good" "$skip"
393
- # Return now if a checkout has already been done
394
- test "$?" -eq "1" && return
395
-
396
- # Perform bisection computation, display and checkout
397
- git bisect--helper --next-exit
273
+ # Perform all bisection computation, display and checkout
274
+ git bisect--helper --next-all
275
res=$?
276
277
# Check if we should exit because bisection is finished