85
return res;
86
}
87
88
+/*
89
+ * return code BISECT_INTERNAL_SUCCESS_MERGE_BASE
90
+ * and BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND are codes
91
+ * that indicate special success.
92
+ */
93
+
94
+static int is_bisect_success(enum bisect_error res)
95
+{
96
+ return !res ||
97
+ res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND ||
98
+ res == BISECT_INTERNAL_SUCCESS_MERGE_BASE;
99
+}
100
+
101
static int write_in_file(const char *path, const char *mode, const char *format, va_list args)
102
{
103
FILE *fp = NULL;
622
return bisect_next(terms, prefix);
623
}
624
612
-static int bisect_start(struct bisect_terms *terms, const char **argv, int argc)
625
+static enum bisect_error bisect_start(struct bisect_terms *terms, const char **argv, int argc)
626
{
627
int no_checkout = 0;
628
int first_parent_only = 0;
629
int i, has_double_dash = 0, must_write_terms = 0, bad_seen = 0;
617
- int flags, pathspec_pos, res = 0;
630
+ int flags, pathspec_pos;
631
+ enum bisect_error res = BISECT_OK;
632
struct string_list revs = STRING_LIST_INIT_DUP;
633
struct string_list states = STRING_LIST_INIT_DUP;
634
struct strbuf start_head = STRBUF_INIT;
768
* Get rid of any old bisect state.
769
*/
770
if (bisect_clean_state())
757
- return -1;
758
-
759
- /*
760
- * In case of mistaken revs or checkout error, or signals received,
761
- * "bisect_auto_next" below may exit or misbehave.
762
- * We have to trap this to be able to clean up using
763
- * "bisect_clean_state".
764
- */
771
+ return BISECT_FAILED;
772
773
/*
774
* Write new start state
785
}
786
if (update_ref(NULL, "BISECT_HEAD", &oid, NULL, 0,
787
UPDATE_REFS_MSG_ON_ERR)) {
781
- res = -1;
788
+ res = BISECT_FAILED;
789
goto finish;
790
}
791
}
797
for (i = 0; i < states.nr; i++)
798
if (bisect_write(states.items[i].string,
799
revs.items[i].string, terms, 1)) {
793
- res = -1;
800
+ res = BISECT_FAILED;
801
goto finish;
802
}
803
804
if (must_write_terms && write_terms(terms->term_bad,
805
terms->term_good)) {
799
- res = -1;
806
+ res = BISECT_FAILED;
807
goto finish;
808
}
809
810
res = bisect_append_log_quoted(argv);
811
if (res)
805
- res = -1;
812
+ res = BISECT_FAILED;
813
814
finish:
815
string_list_clear(&revs, 0);
816
string_list_clear(&states, 0);
817
strbuf_release(&start_head);
818
strbuf_release(&bisect_names);
819
+ if (res)
820
+ return res;
821
+
822
+ res = bisect_auto_next(terms, NULL);
823
+ if (!is_bisect_success(res))
824
+ bisect_clean_state();
825
return res;
826
}
827