31
N_("git bisect--helper --bisect-next"),
32
N_("git bisect--helper --bisect-auto-next"),
33
N_("git bisect--helper --bisect-autostart"),
34
+ N_("git bisect--helper --bisect-state (bad|new) [<rev>]"),
35
+ N_("git bisect--helper --bisect-state (good|old) [<rev>...]"),
36
NULL
37
};
38
857
return res;
858
}
859
860
+static enum bisect_error bisect_state(struct bisect_terms *terms, const char **argv,
861
+ int argc)
862
+{
863
+ const char *state;
864
+ int i, verify_expected = 1;
865
+ struct object_id oid, expected;
866
+ struct strbuf buf = STRBUF_INIT;
867
+ struct oid_array revs = OID_ARRAY_INIT;
868
+
869
+ if (!argc)
870
+ return error(_("Please call `--bisect-state` with at least one argument"));
871
+
872
+ if (bisect_autostart(terms))
873
+ return BISECT_FAILED;
874
+
875
+ state = argv[0];
876
+ if (check_and_set_terms(terms, state) ||
877
+ !one_of(state, terms->term_good, terms->term_bad, "skip", NULL))
878
+ return BISECT_FAILED;
879
+
880
+ argv++;
881
+ argc--;
882
+ if (argc > 1 && !strcmp(state, terms->term_bad))
883
+ return error(_("'git bisect %s' can take only one argument."), terms->term_bad);
884
+
885
+ if (argc == 0) {
886
+ const char *head = "BISECT_HEAD";
887
+ enum get_oid_result res_head = get_oid(head, &oid);
888
+
889
+ if (res_head == MISSING_OBJECT) {
890
+ head = "HEAD";
891
+ res_head = get_oid(head, &oid);
892
+ }
893
+
894
+ if (res_head)
895
+ error(_("Bad rev input: %s"), head);
896
+ oid_array_append(&revs, &oid);
897
+ }
898
+
899
+ /*
900
+ * All input revs must be checked before executing bisect_write()
901
+ * to discard junk revs.
902
+ */
903
+
904
+ for (; argc; argc--, argv++) {
905
+ if (get_oid(*argv, &oid)){
906
+ error(_("Bad rev input: %s"), *argv);
907
+ oid_array_clear(&revs);
908
+ return BISECT_FAILED;
909
+ }
910
+ oid_array_append(&revs, &oid);
911
+ }
912
+
913
+ if (strbuf_read_file(&buf, git_path_bisect_expected_rev(), 0) < the_hash_algo->hexsz ||
914
+ get_oid_hex(buf.buf, &expected) < 0)
915
+ verify_expected = 0; /* Ignore invalid file contents */
916
+ strbuf_release(&buf);
917
+
918
+ for (i = 0; i < revs.nr; i++) {
919
+ if (bisect_write(state, oid_to_hex(&revs.oid[i]), terms, 0)) {
920
+ oid_array_clear(&revs);
921
+ return BISECT_FAILED;
922
+ }
923
+ if (verify_expected && !oideq(&revs.oid[i], &expected)) {
924
+ unlink_or_warn(git_path_bisect_ancestors_ok());
925
+ unlink_or_warn(git_path_bisect_expected_rev());
926
+ verify_expected = 0;
927
+ }
928
+ }
929
+
930
+ oid_array_clear(&revs);
931
+ return bisect_auto_next(terms, NULL);
932
+}
933
+
934
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
935
{
936
enum {
944
BISECT_START,
945
BISECT_AUTOSTART,
946
BISECT_NEXT,
871
- BISECT_AUTO_NEXT
947
+ BISECT_AUTO_NEXT,
948
+ BISECT_STATE
949
} cmdmode = 0;
950
int res = 0, nolog = 0;
951
struct option options[] = {
971
N_("verify the next bisection state then checkout the next bisection commit"), BISECT_AUTO_NEXT),
972
OPT_CMDMODE(0, "bisect-autostart", &cmdmode,
973
N_("start the bisection if it has not yet been started"), BISECT_AUTOSTART),
974
+ OPT_CMDMODE(0, "bisect-state", &cmdmode,
975
+ N_("mark the state of ref (or refs)"), BISECT_STATE),
976
OPT_BOOL(0, "no-log", &nolog,
977
N_("no log for BISECT_WRITE")),
978
OPT_END()
1043
set_terms(&terms, "bad", "good");
1044
res = bisect_autostart(&terms);
1045
break;
1046
+ case BISECT_STATE:
1047
+ set_terms(&terms, "bad", "good");
1048
+ get_terms(&terms);
1049
+ res = bisect_state(&terms, argv, argc);
1050
+ break;
1051
default:
1052
BUG("unknown subcommand %d", cmdmode);
1053
}