git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 5/5] sequencer: do not roll back lockfile unnecessarily

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Feb 28, 2018, 19:07 UTC
Message-ID
<baaa7016b8812ca99d922c14547e23082bb6acba.1519843916.git.martin.agren@gmail.com>
In-Reply-To
<cover.1519843916.git.martin.agren@gmail.com>

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>
---
 sequencer.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index e6bac4692a..0e6d04e4ce 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -303,10 +303,8 @@ static int write_message(const void *buf, size_t len, const char *filename,
 		rollback_lock_file(&msg_file);
 		return error_errno(_("could not write eol to '%s'"), filename);
 	}
-	if (commit_lock_file(&msg_file) < 0) {
-		rollback_lock_file(&msg_file);
-		return error(_("failed to finalize '%s'."), filename);
-	}
+	if (commit_lock_file(&msg_file) < 0)
+		return error(_("failed to finalize '%s'"), filename);
 
 	return 0;
 }
@@ -1585,10 +1583,8 @@ static int save_head(const char *head)
 	ssize_t written;
 
 	fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0);
-	if (fd < 0) {
-		rollback_lock_file(&head_lock);
+	if (fd < 0)
 		return error_errno(_("could not lock HEAD"));
-	}
 	strbuf_addf(&buf, "%s\n", head);
 	written = write_in_full(fd, buf.buf, buf.len);
 	strbuf_release(&buf);
@@ -1597,10 +1593,8 @@ static int save_head(const char *head)
 		return error_errno(_("could not write to '%s'"),
 				   git_path_head_file());
 	}
-	if (commit_lock_file(&head_lock) < 0) {
-		rollback_lock_file(&head_lock);
-		return error(_("failed to finalize '%s'."), git_path_head_file());
-	}
+	if (commit_lock_file(&head_lock) < 0)
+		return error(_("failed to finalize '%s'"), git_path_head_file());
 	return 0;
 }
 
@@ -1724,7 +1718,7 @@ static int save_todo(struct todo_list *todo_list, struct replay_opts *opts)
 			todo_list->buf.len - offset) < 0)
 		return error_errno(_("could not write to '%s'"), todo_path);
 	if (commit_lock_file(&todo_lock) < 0)
-		return error(_("failed to finalize '%s'."), todo_path);
+		return error(_("failed to finalize '%s'"), todo_path);
 
 	if (is_rebase_i(opts)) {
 		const char *done_path = rebase_path_done();
-- 
2.16.2.246.ga4ee44448f
Previous: Martin ÅgrenNext: Martin Ågren
Message 12 of 26 in “roll back locks in various code paths”
  1. 0/5 roll back locks in various code pathsMartin Ågren, Feb 27, 2018
  2. 1/5 sequencer: make lockfiles non-staticMartin Ågren, Feb 27, 2018
  3. 2/5 sequencer: always roll back lock in `do_recursive_merge()`Martin Ågren, Feb 27, 2018
  4. Jeff KingFeb 27, 2018
  5. Martin ÅgrenFeb 27, 2018
  6. Jeff KingFeb 27, 2018
  7. 3/5 merge-recursive: always roll back lock in `merge_recursive_generic()`Martin Ågren, Feb 27, 2018
  8. Martin ÅgrenFeb 28, 2018
  9. 0/5 roll back locks in various code pathsMartin Ågren, Feb 28, 2018
  10. 1/5 sequencer: make lockfiles non-staticMartin Ågren, Feb 28, 2018
  11. 2/5 sequencer: always roll back lock in `do_recursive_merge()`Martin Ågren, Feb 28, 2018
  12. 5/5 sequencer: do not roll back lockfile unnecessarilyMartin Ågren, Feb 28, 2018
  13. 4/5 merge: always roll back lock in `checkout_fast_forward()`Martin Ågren, Feb 28, 2018
  14. 3/5 merge-recursive: always roll back lock in `merge_recursive_generic()`Martin Ågren, Feb 28, 2018
  15. Martin ÅgrenFeb 28, 2018
  16. Junio C HamanoFeb 28, 2018
  17. Martin ÅgrenMar 1, 2018
  18. Jeff KingMar 1, 2018
  19. Junio C HamanoMar 1, 2018
  20. Martin ÅgrenMar 1, 2018
  21. Jeff KingMar 2, 2018
  22. Jeff KingMar 1, 2018
  23. 4/5 merge: always roll back lock in `checkout_fast_forward()`Martin Ågren, Feb 27, 2018
  24. 5/5 sequencer: do not roll back lockfile unnecessarilyMartin Ågren, Feb 27, 2018
  25. Jeff KingFeb 27, 2018
  26. Junio C HamanoFeb 27, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.