@@ -582,11 +582,12 @@ static enum bisect_error bisect_auto_next(struct bisect_terms *terms, const char
return bisect_next(terms, prefix);
}
-static int bisect_start(struct bisect_terms *terms, int no_checkout,
+static enum bisect_error bisect_start(struct bisect_terms *terms, int no_checkout,
const char **argv, int argc)
{
int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0;
- int flags, pathspec_pos, res = 0;
+ int flags, pathspec_pos;
+ enum bisect_error res = BISECT_OK;
struct string_list revs = STRING_LIST_INIT_DUP;
struct string_list states = STRING_LIST_INIT_DUP;
struct strbuf start_head = STRBUF_INIT;
@@ -639,9 +640,12 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
return error(_("unrecognized option: '%s'"), arg);
} else {
char *commit_id = xstrfmt("%s^{commit}", arg);
- if (get_oid(commit_id, &oid) && has_double_dash)
- die(_("'%s' does not appear to be a valid "
- "revision"), arg);
+ if (get_oid(commit_id, &oid) && has_double_dash) {
+ error(_("'%s' does not appear to be a valid "
+ "revision"), arg);
+ free(commit_id);
+ return BISECT_FAILED;
+ }
string_list_append(&revs, oid_to_hex(&oid));
free(commit_id);
@@ -719,12 +723,12 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
* Get rid of any old bisect state.
*/
if (bisect_clean_state())
- return -1;
+ return BISECT_FAILED;
/*
- * In case of mistaken revs or checkout error, or signals received,
+ * In case of mistaken revs or checkout error,
* "bisect_auto_next" below may exit or misbehave.
- * We have to trap this to be able to clean up using
+ * We have to handle this to be able to clean up using
* "bisect_clean_state".
*/
@@ -740,7 +744,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
}
if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
UPDATE_REFS_MSG_ON_ERR)) {
- res = -1;
+ res = BISECT_FAILED;
goto finish;
}
}
@@ -752,25 +756,51 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout,
for (i = 0; i < states.nr; i++)
if (bisect_write(states.items[i].string,
revs.items[i].string, terms, 1)) {
- res = -1;
+ res = BISECT_FAILED;
goto finish;
}
if (must_write_terms && write_terms(terms->term_bad,
terms->term_good)) {
- res = -1;
+ res = BISECT_FAILED;
goto finish;
}
res = bisect_append_log_quoted(argv);
if (res)
- res = -1;
+ res = BISECT_FAILED;
finish:
string_list_clear(&revs, 0);
string_list_clear(&states, 0);
strbuf_release(&start_head);
strbuf_release(&bisect_names);
+ if (res)
+ return res;
+
+ res = bisect_auto_next(terms, NULL);
+ /*
+ * In case of mistaken revs or checkout error, or signals received,
+ * "bisect_auto_next" below may exit or misbehave.
+ * We have to handle this to be able to clean up using
+ * "bisect_clean_state".
+ * return code BISECT_INTERNAL_SUCCESS_MERGE_BASE is special code
+ * that indicates special success.
+ * -> bisect_start()
+ * . res = bisect_auto_next()
+ * -> bisect_auto_next()
+ * . return bisect_next()
+ * -> bisect_next()
+ * . res = bisect_next_all()
+ * -> bisect_next_all()
+ * . res = check_good_are_ancestors_of_bad()
+ * -> check_good_are_ancestors_of_bad()
+ * . res = check_merge_bases()
+ * -> check_merge_bases()
+ * . res = BISECT_INTERNAL_SUCCESS_MERGE_BASE
+ */
+ if (res && res != BISECT_INTERNAL_SUCCESS_MERGE_BASE)
+ bisect_clean_state();
return res;
}
@@ -63,34 +63,13 @@ bisect_autostart() {
[Nn]*)
exit ;;
esac
- bisect_start
+ git bisect--helper --bisect-start
else
exit 1
fi
}
}
-bisect_start() {
- git bisect--helper --bisect-start $@ || exit
-
- #
- # Change state.
- # In case of mistaken revs or checkout error, or signals received,
- # "bisect_auto_next" below may exit or misbehave.
- # We have to trap this to be able to clean up using
- # "bisect_clean_state".
- #
- trap 'git bisect--helper --bisect-clean-state' 0
- trap 'exit 255' 1 2 3 15
-
- #
- # Check if we can proceed to the next bisect state.
- #
- git bisect--helper --bisect-auto-next || exit
-
- trap '-' 0
-}
-
bisect_skip() {
all=''
for arg in "$@"
@@ -183,8 +162,7 @@ bisect_replay () {
get_terms
case "$command" in
start)
- cmd="bisect_start $rev"
- eval "$cmd" ;;
+ eval "git bisect--helper --bisect-start $rev" ;;
"$TERM_GOOD"|"$TERM_BAD"|skip)
git bisect--helper --bisect-write "$command" "$rev" "$TERM_GOOD" "$TERM_BAD" || exit;;
terms)
@@ -283,7 +261,7 @@ case "$#" in
help)
git bisect -h ;;
start)
- bisect_start "$@" ;;
+ git bisect--helper --bisect-start "$@" ;;
bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
bisect_state "$cmd" "$@" ;;
skip)