sequencer: avoid using errno clobbered by rollback_lock_file()

As pointed out in a review of the `--rebase-merges` patch series, `rollback_lock_file()` clobbers errno. Therefore, we have to report the error message that uses errno before calling said function. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Apr 25, 2018 at 14:28 UTC bf5c0571d6542d992380467c26cb7bdcab23fcb5
1 file changed +6 -4
sequencer.c
+6 -4
@@ -346,12 +346,14 @@ static int write_message(const void *buf, size_t len, const char *filename,
346 if (msg_fd < 0)
347 return error_errno(_("could not lock '%s'"), filename);
348 if (write_in_full(msg_fd, buf, len) < 0) {
349 + error_errno(_("could not write to '%s'"), filename);
350 rollback_lock_file(&msg_file);
350 - return error_errno(_("could not write to '%s'"), filename);
351 + return -1;
352 }
353 if (append_eol && write(msg_fd, "\n", 1) < 0) {
354 + error_errno(_("could not write eol to '%s'"), filename);
355 rollback_lock_file(&msg_file);
354 - return error_errno(_("could not write eol to '%s'"), filename);
356 + return -1;
357 }
358 if (commit_lock_file(&msg_file) < 0)
359 return error(_("failed to finalize '%s'"), filename);
@@ -2125,9 +2127,9 @@ static int save_head(const char *head)
2127 written = write_in_full(fd, buf.buf, buf.len);
2128 strbuf_release(&buf);
2129 if (written < 0) {
2130 + error_errno(_("could not write to '%s'"), git_path_head_file());
2131 rollback_lock_file(&head_lock);
2129 - return error_errno(_("could not write to '%s'"),
2130 - git_path_head_file());
2132 + return -1;
2133 }
2134 if (commit_lock_file(&head_lock) < 0)
2135 return error(_("failed to finalize '%s'"), git_path_head_file());