From 516d2aaf8837c8675141cf9c330c18c44765b69d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 4 Mar 2016 16:18:50 +0100 Subject: [PATCH] sequencer (rebase -i): write the 'done' file In the interactive rebase, commands that were successfully processed are not simply discarded, but appended to the 'done' file instead. This is used e.g. to display the current state to the user in the output of `git status` or the progress. Signed-off-by: Johannes Schindelin --- sequencer.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sequencer.c b/sequencer.c index 95c31bb9ac..3bff3d9686 100644 --- a/sequencer.c +++ b/sequencer.c @@ -38,6 +38,12 @@ static GIT_PATH_FUNC(rebase_path, "rebase-merge") * file and written to the tail of 'done'. */ static GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo") +/* + * The rebase command lines that have already been processed. A line + * is moved here when it is first handled, before any associated user + * actions. + */ +static GIT_PATH_FUNC(rebase_path_done, "rebase-merge/done") /* * A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and * GIT_AUTHOR_DATE that will be used for the commit that is currently @@ -1272,6 +1278,20 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts) todo_path, strerror(errno)); if (commit_lock_file(&todo_lock) < 0) return error(_("Error wrapping up %s."), todo_path); + + if (is_rebase_i(opts)) { + const char *done_path = rebase_path_done(); + int fd = open(done_path, O_CREAT | O_WRONLY | O_APPEND, 0666); + int prev_offset = !next ? 0 : + todo_list->items[next - 1].offset_in_buf; + + if (offset > prev_offset && write_in_full(fd, + todo_list->buf.buf + prev_offset, + offset - prev_offset) < 0) + return error(_("Could not write to %s (%s)"), + done_path, strerror(errno)); + close(fd); + } return 0; }