Skip to content

Commit 1df6df0

Browse files
dschogitster
authored andcommitted
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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 556907f commit 1df6df0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

sequencer.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ static GIT_PATH_FUNC(rebase_path, "rebase-merge")
4040
* file and written to the tail of 'done'.
4141
*/
4242
static GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo")
43+
/*
44+
* The rebase command lines that have already been processed. A line
45+
* is moved here when it is first handled, before any associated user
46+
* actions.
47+
*/
48+
static GIT_PATH_FUNC(rebase_path_done, "rebase-merge/done")
4349
/*
4450
* A script to set the GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, and
4551
* GIT_AUTHOR_DATE that will be used for the commit that is currently
@@ -1296,6 +1302,23 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
12961302
return error_errno(_("could not write to '%s'"), todo_path);
12971303
if (commit_lock_file(&todo_lock) < 0)
12981304
return error(_("failed to finalize '%s'."), todo_path);
1305+
1306+
if (is_rebase_i(opts)) {
1307+
const char *done_path = rebase_path_done();
1308+
int fd = open(done_path, O_CREAT | O_WRONLY | O_APPEND, 0666);
1309+
int prev_offset = !next ? 0 :
1310+
todo_list->items[next - 1].offset_in_buf;
1311+
1312+
if (fd >= 0 && offset > prev_offset &&
1313+
write_in_full(fd, todo_list->buf.buf + prev_offset,
1314+
offset - prev_offset) < 0) {
1315+
close(fd);
1316+
return error_errno(_("could not write to '%s'"),
1317+
done_path);
1318+
}
1319+
if (fd >= 0)
1320+
close(fd);
1321+
}
12991322
return 0;
13001323
}
13011324

0 commit comments

Comments
 (0)