static int sequencer_rollback(struct replay_opts *opts) { const char *filename; FILE *f; unsigned char sha1[20]; struct strbuf buf = STRBUF_INIT; struct string_list merge_rr = STRING_LIST_INIT_DUP; if (setup_rerere(&merge_rr, 0) >= 0) { rerere_clear(&merge_rr); string_list_clear(&merge_rr, 1); } filename = git_path(SEQ_HEAD_FILE); f = fopen(filename, "r"); if (!f && errno == ENOENT) { /* * There is no multiple-cherry-pick in progress. * If CHERRY_PICK_HEAD or REVERT_HEAD indicates * a single-cherry-pick in progress, abort that. */ return rollback_single_pick(); } if (!f) return error(_("cannot open %s: %s"), filename, strerror(errno)); if (strbuf_getline(&buf, f, '\n')) { error(_("cannot read %s: %s"), filename, ferror(f) ? strerror(errno) : _("unexpected end of file")); fclose(f); goto fail; } fclose(f); if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') { error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"), filename); goto fail; } if (reset_for_rollback(sha1)) goto fail; remove_sequencer_state(); strbuf_release(&buf); return 0; fail: strbuf_release(&buf); return -1; }
int sequencer_rollback(struct replay_opts *opts) { FILE *f; unsigned char sha1[20]; struct strbuf buf = STRBUF_INIT; f = fopen(git_path_head_file(), "r"); if (!f && errno == ENOENT) { /* * There is no multiple-cherry-pick in progress. * If CHERRY_PICK_HEAD or REVERT_HEAD indicates * a single-cherry-pick in progress, abort that. */ return rollback_single_pick(); } if (!f) return error_errno(_("cannot open '%s'"), git_path_head_file()); if (strbuf_getline_lf(&buf, f)) { error(_("cannot read '%s': %s"), git_path_head_file(), ferror(f) ? strerror(errno) : _("unexpected end of file")); fclose(f); goto fail; } fclose(f); if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') { error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"), git_path_head_file()); goto fail; } if (is_null_sha1(sha1)) { error(_("cannot abort from a branch yet to be born")); goto fail; } if (!rollback_is_safe()) { /* Do not error, just do not rollback */ warning(_("You seem to have moved HEAD. " "Not rewinding, check your HEAD!")); } else if (reset_for_rollback(sha1)) goto fail; strbuf_release(&buf); return sequencer_remove_state(opts); fail: strbuf_release(&buf); return -1; }