From: Junio C Hamano Date: Wed, 6 Dec 2017 17:09:03 +0000 (-0800) Subject: Merge branch 'pw/sequencer-recover-from-unlockable-index' into maint X-Git-Tag: v2.15.2~7 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0175b6e2b9f99101b37cd4b1aa61711678a17105?ds=inline;hp=-c Merge branch 'pw/sequencer-recover-from-unlockable-index' into maint The sequencer machinery (used by "git cherry-pick A..B", and "git rebase -i", among other things) would have lost a commit if stopped due to an unlockable index file, which has been fixed. * pw/sequencer-recover-from-unlockable-index: sequencer: reschedule pick if index can't be locked --- 0175b6e2b9f99101b37cd4b1aa61711678a17105 diff --combined sequencer.c index 2882d53120,10924ffd49..5e09b5d34f --- a/sequencer.c +++ b/sequencer.c @@@ -438,7 -438,8 +438,8 @@@ static int do_recursive_merge(struct co char **xopt; static struct lock_file index_lock; - hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR); + if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0) + return -1; read_cache(); @@@ -2670,19 -2671,6 +2671,19 @@@ leave_check return res; } +static int rewrite_file(const char *path, const char *buf, size_t len) +{ + int rc = 0; + int fd = open(path, O_WRONLY | O_TRUNC); + if (fd < 0) + return error_errno(_("could not open '%s' for writing"), path); + if (write_in_full(fd, buf, len) < 0) + rc = error_errno(_("could not write to '%s'"), path); + if (close(fd) && !rc) + rc = error_errno(_("could not close '%s'"), path); + return rc; +} + /* skip picking commits whose parents are unchanged */ int skip_unnecessary_picks(void) { @@@ -2755,11 -2743,29 +2756,11 @@@ } close(fd); - fd = open(rebase_path_todo(), O_WRONLY, 0666); - if (fd < 0) { - error_errno(_("could not open '%s' for writing"), - rebase_path_todo()); - todo_list_release(&todo_list); - return -1; - } - if (write_in_full(fd, todo_list.buf.buf + offset, - todo_list.buf.len - offset) < 0) { - error_errno(_("could not write to '%s'"), - rebase_path_todo()); - close(fd); - todo_list_release(&todo_list); - return -1; - } - if (ftruncate(fd, todo_list.buf.len - offset) < 0) { - error_errno(_("could not truncate '%s'"), - rebase_path_todo()); + if (rewrite_file(rebase_path_todo(), todo_list.buf.buf + offset, + todo_list.buf.len - offset) < 0) { todo_list_release(&todo_list); - close(fd); return -1; } - close(fd); todo_list.current = i; if (is_fixup(peek_command(&todo_list, 0))) @@@ -2944,7 -2950,15 +2945,7 @@@ int rearrange_squash(void } } - fd = open(todo_file, O_WRONLY); - if (fd < 0) - res = error_errno(_("could not open '%s'"), todo_file); - else if (write(fd, buf.buf, buf.len) < 0) - res = error_errno(_("could not write to '%s'"), todo_file); - else if (ftruncate(fd, buf.len) < 0) - res = error_errno(_("could not truncate '%s'"), - todo_file); - close(fd); + res = rewrite_file(todo_file, buf.buf, buf.len); strbuf_release(&buf); }