sequencer: do not roll back lockfile unnecessarily

If `commit_lock_file()` or `hold_lock_file_for_update()` fail, there is no need to call `rollback_lock_file()` on the lockfile. It doesn't hurt either, but it does make different callers in this file inconsistent, which might be confusing. While at it, remove a trailing '.' from a recurring error message. Signed-off-by: Martin Ågren <martin.agren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Ågren committed Feb 28, 2018 at 20:07 UTC 350292a1efb38bbcd6255a424df6adbfe78910ac
1 file changed +6 -12
sequencer.c
+6 -12
@@ -352,10 +352,8 @@ static int write_message(const void *buf, size_t len, const char *filename,
352 rollback_lock_file(&msg_file);
353 return error_errno(_("could not write eol to '%s'"), filename);
354 }
355 - if (commit_lock_file(&msg_file) < 0) {
356 - rollback_lock_file(&msg_file);
357 - return error(_("failed to finalize '%s'."), filename);
358 - }
355 + if (commit_lock_file(&msg_file) < 0)
356 + return error(_("failed to finalize '%s'"), filename);
357
358 return 0;
359 }
@@ -2107,10 +2105,8 @@ static int save_head(const char *head)
2105 ssize_t written;
2106
2107 fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0);
2110 - if (fd < 0) {
2111 - rollback_lock_file(&head_lock);
2108 + if (fd < 0)
2109 return error_errno(_("could not lock HEAD"));
2113 - }
2110 strbuf_addf(&buf, "%s\n", head);
2111 written = write_in_full(fd, buf.buf, buf.len);
2112 strbuf_release(&buf);
@@ -2119,10 +2115,8 @@ static int save_head(const char *head)
2115 return error_errno(_("could not write to '%s'"),
2116 git_path_head_file());
2117 }
2122 - if (commit_lock_file(&head_lock) < 0) {
2123 - rollback_lock_file(&head_lock);
2124 - return error(_("failed to finalize '%s'."), git_path_head_file());
2125 - }
2118 + if (commit_lock_file(&head_lock) < 0)
2119 + return error(_("failed to finalize '%s'"), git_path_head_file());
2120 return 0;
2121 }
2122
@@ -2246,7 +2240,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
2240 todo_list->buf.len - offset) < 0)
2241 return error_errno(_("could not write to '%s'"), todo_path);
2242 if (commit_lock_file(&todo_lock) < 0)
2249 - return error(_("failed to finalize '%s'."), todo_path);
2243 + return error(_("failed to finalize '%s'"), todo_path);
2244
2245 if (is_rebase_i(opts)) {
2246 const char *done_path = rebase_path_done();