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

[PATCH] sequencer: rewrite save_head() in terms of write_message()

From
Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Date
Mar 23, 2023, 16:22 UTC
Message-ID
<20230323162235.995544-1-oswald.buddenhagen@gmx.de>
Saves some code duplication.
Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
---
 sequencer.c | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 3be23d7ca2..ff985fb2e9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -3187,25 +3187,7 @@ static int create_seq_dir(struct repository *r)
 
 static int save_head(const char *head)
 {
-	struct lock_file head_lock = LOCK_INIT;
-	struct strbuf buf = STRBUF_INIT;
-	int fd;
-	ssize_t written;
-
-	fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0);
-	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);
-	if (written < 0) {
-		error_errno(_("could not write to '%s'"), git_path_head_file());
-		rollback_lock_file(&head_lock);
-		return -1;
-	}
-	if (commit_lock_file(&head_lock) < 0)
-		return error(_("failed to finalize '%s'"), git_path_head_file());
-	return 0;
+	return write_message(head, strlen(head), git_path_head_file(), 1);
 }
 
 static int rollback_is_safe(void)
-- 
2.40.0.152.g15d061e6df
Next: Junio C Hamano
Message 1 of 2 in “sequencer: rewrite save_head() in terms of write_message()”
  1. sequencer: rewrite save_head() in terms of write_message()Oswald Buddenhagen, Mar 23, 2023
  2. Junio C HamanoMar 24, 2023

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.