| 289 | } |
| 290 | |
| 291 | static int bisect_write(const char *state, const char *rev, |
| 292 | const struct bisect_terms *terms, int nolog) |
| 293 | { |
| 294 | struct strbuf tag = STRBUF_INIT; |
| 295 | struct object_id oid; |
| 296 | struct commit *commit; |
| 297 | FILE *fp = NULL; |
| 298 | int res = 0; |
| 299 | |
| 300 | if (!strcmp(state, terms->term_bad)) { |
| 301 | strbuf_addf(&tag, "refs/bisect/%s", state); |
| 302 | } else if (one_of(state, terms->term_good, "skip", NULL)) { |
| 303 | strbuf_addf(&tag, "refs/bisect/%s-%s", state, rev); |
| 304 | } else { |
| 305 | res = error(_("Bad bisect_write argument: %s"), state); |
| 306 | goto finish; |
| 307 | } |
| 308 | |
| 309 | if (repo_get_oid(the_repository, rev, &oid)) { |
| 310 | res = error(_("couldn't get the oid of the rev '%s'"), rev); |
| 311 | goto finish; |
| 312 | } |
| 313 | |
| 314 | if (refs_update_ref(get_main_ref_store(the_repository), NULL, tag.buf, &oid, NULL, 0, |
| 315 | UPDATE_REFS_MSG_ON_ERR)) { |
| 316 | res = -1; |
| 317 | goto finish; |
| 318 | } |
| 319 | |
| 320 | fp = fopen(git_path_bisect_log(), "a"); |
| 321 | if (!fp) { |
| 322 | res = error_errno(_("couldn't open the file '%s'"), git_path_bisect_log()); |
| 323 | goto finish; |
| 324 | } |
| 325 | |
| 326 | commit = lookup_commit_reference(the_repository, &oid); |
| 327 | log_commit(fp, "%s", state, commit); |
| 328 | |
| 329 | if (!nolog) |
| 330 | fprintf(fp, "git bisect %s %s\n", state, rev); |
| 331 | |
| 332 | finish: |
| 333 | if (fp) |
| 334 | fclose(fp); |
| 335 | strbuf_release(&tag); |
| 336 | return res; |
| 337 | } |
| 338 | |
| 339 | static int check_and_set_terms(struct bisect_terms *terms, const char *cmd) |
| 340 | { |
no test coverage detected