MCPcopy Create free account
hub / github.com/git/git / save_todo

Function save_todo

sequencer.c:3627–3667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3625}
3626
3627static int save_todo(struct todo_list *todo_list, struct replay_opts *opts,
3628 int reschedule)
3629{
3630 struct lock_file todo_lock = LOCK_INIT;
3631 const char *todo_path = get_todo_path(opts);
3632 int next = todo_list->current, offset, fd;
3633
3634 /*
3635 * rebase -i writes "git-rebase-todo" without the currently executing
3636 * command, appending it to "done" instead.
3637 */
3638 if (is_rebase_i(opts) && !reschedule)
3639 next++;
3640
3641 fd = hold_lock_file_for_update(&todo_lock, todo_path, 0);
3642 if (fd < 0)
3643 return error_errno(_("could not lock '%s'"), todo_path);
3644 offset = get_item_line_offset(todo_list, next);
3645 if (write_in_full(fd, todo_list->buf.buf + offset,
3646 todo_list->buf.len - offset) < 0)
3647 return error_errno(_("could not write to '%s'"), todo_path);
3648 if (commit_lock_file(&todo_lock) < 0)
3649 return error(_("failed to finalize '%s'"), todo_path);
3650
3651 if (is_rebase_i(opts) && !reschedule && next > 0) {
3652 const char *done = rebase_path_done();
3653 int fd = open(done, O_CREAT | O_WRONLY | O_APPEND, 0666);
3654 int ret = 0;
3655
3656 if (fd < 0)
3657 return 0;
3658 if (write_in_full(fd, get_item_line(todo_list, next - 1),
3659 get_item_line_length(todo_list, next - 1))
3660 < 0)
3661 ret = error_errno(_("could not write to '%s'"), done);
3662 if (close(fd) < 0)
3663 ret = error_errno(_("failed to finalize '%s'"), done);
3664 return ret;
3665 }
3666 return 0;
3667}
3668
3669static int save_opts(struct replay_opts *opts)
3670{

Callers 1

pick_commitsFunction · 0.85

Calls 10

get_todo_pathFunction · 0.85
is_rebase_iFunction · 0.85
error_errnoFunction · 0.85
get_item_line_offsetFunction · 0.85
write_in_fullFunction · 0.85
commit_lock_fileFunction · 0.85
errorFunction · 0.85
get_item_lineFunction · 0.85
get_item_line_lengthFunction · 0.85

Tested by

no test coverage detected