sequencer: rewrite save_head() in terms of write_message()
Saves some code duplication. Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Oswald Buddenhagen committed
Mar 23, 2023 at 17:22 UTC
54dbd0933ba9e35a97562bd4224842c3a0362742
1 file changed
+1
-19
sequencer.c
+1
-19
@@ -3184,25 +3184,7 @@ static int create_seq_dir(struct repository *r)
3184
3185
static int save_head(const char *head)
3186
{
3187
- struct lock_file head_lock = LOCK_INIT;
3188
- struct strbuf buf = STRBUF_INIT;
3189
- int fd;
3190
- ssize_t written;
3191
-
3192
- fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0);
3193
- if (fd < 0)
3194
- return error_errno(_("could not lock HEAD"));
3195
- strbuf_addf(&buf, "%s\n", head);
3196
- written = write_in_full(fd, buf.buf, buf.len);
3197
- strbuf_release(&buf);
3198
- if (written < 0) {
3199
- error_errno(_("could not write to '%s'"), git_path_head_file());
3200
- rollback_lock_file(&head_lock);
3201
- return -1;
3202
- }
3203
- if (commit_lock_file(&head_lock) < 0)
3204
- return error(_("failed to finalize '%s'"), git_path_head_file());
3205
- return 0;
3187
+ return write_message(head, strlen(head), git_path_head_file(), 1);
3188
}
3189
3190
static int rollback_is_safe(void)