From: Junio C Hamano Date: Mon, 13 May 2019 14:50:35 +0000 (+0900) Subject: Merge branch 'pw/clean-sequencer-state-upon-final-commit' X-Git-Tag: v2.22.0-rc0~3 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b51a0fdc3822c2ef260f6d496b6df6d33b101e8a Merge branch 'pw/clean-sequencer-state-upon-final-commit' "git chery-pick" (and "revert" that shares the same runtime engine) that deals with multiple commits got confused when the final step gets stopped with a conflict and the user concluded the sequence with "git commit". Attempt to fix it by cleaning up the state files used by these commands in such a situation. * pw/clean-sequencer-state-upon-final-commit: fix cherry-pick/revert status after commit commit/reset: try to clean up sequencer state --- b51a0fdc3822c2ef260f6d496b6df6d33b101e8a diff --cc sequencer.c index 72a1bc5fc5,c6a9a35422..f88a97fb10 --- a/sequencer.c +++ b/sequencer.c @@@ -2168,8 -2142,43 +2168,43 @@@ static int parse_insn_line(struct repos return !item->commit; } + int sequencer_get_last_command(struct repository *r, enum replay_action *action) + { + struct todo_item item; + char *eol; + const char *todo_file; + struct strbuf buf = STRBUF_INIT; + int ret = -1; + + todo_file = git_path_todo_file(); + if (strbuf_read_file(&buf, todo_file, 0) < 0) { + if (errno == ENOENT) + return -1; + else + return error_errno("unable to open '%s'", todo_file); + } + eol = strchrnul(buf.buf, '\n'); + if (buf.buf != eol && eol[-1] == '\r') + eol--; /* strip Carriage Return */ - if (parse_insn_line(r, &item, buf.buf, eol)) ++ if (parse_insn_line(r, &item, buf.buf, buf.buf, eol)) + goto fail; + if (item.command == TODO_PICK) + *action = REPLAY_PICK; + else if (item.command == TODO_REVERT) + *action = REPLAY_REVERT; + else + goto fail; + + ret = 0; + + fail: + strbuf_release(&buf); + + return ret; + } + -static int parse_insn_buffer(struct repository *r, char *buf, - struct todo_list *todo_list) +int todo_list_parse_insn_buffer(struct repository *r, char *buf, + struct todo_list *todo_list) { struct todo_item *item; char *p = buf, *next_p; diff --cc sequencer.h index f4a8f4e443,c4b79165d3..0c494b83d4 --- a/sequencer.h +++ b/sequencer.h @@@ -199,4 -143,7 +199,7 @@@ int read_author_script(const char *path void parse_strategy_opts(struct replay_opts *opts, char *raw_opts); int write_basic_state(struct replay_opts *opts, const char *head_name, - const char *onto, const char *orig_head); + struct commit *onto, const char *orig_head); + void sequencer_post_commit_cleanup(struct repository *r); + int sequencer_get_last_command(struct repository* r, + enum replay_action *action);