Skip to content

Commit 54dbd09

Browse files
ossilatorgitster
authored andcommitted
sequencer: rewrite save_head() in terms of write_message()
Saves some code duplication. Signed-off-by: Oswald Buddenhagen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 73876f4 commit 54dbd09

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

sequencer.c

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,25 +3184,7 @@ static int create_seq_dir(struct repository *r)
31843184

31853185
static int save_head(const char *head)
31863186
{
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);
32063188
}
32073189

32083190
static int rollback_is_safe(void)

0 commit comments

Comments
 (0)