Re: [PATCH 10/15] sequencer: lib'ify save_head()
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Aug 24, 2016, 07:30 UTC
- Message-ID
- <CAPig+cSxeOkT7fLuCQrGJNabPfx1855+1-5pqcq0==22mzJk9w@mail.gmail.com>
- In-Reply-To
- <416659fa3df92eabf3265ec079a6ea8cbc17366f.1471968378.git.johannes.schindelin@gmx.de>
On Tue, Aug 23, 2016 at 12:07 PM, Johannes Schindelin <johannes.schindelin@gmx.de> wrote:
Show 23 quoted lines
> To be truly useful, the sequencer should never die() but always return
> an error.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> diff --git a/sequencer.c b/sequencer.c
> @@ -844,18 +844,22 @@ static int create_seq_dir(void)
> -static void save_head(const char *head)
> +static int save_head(const char *head)
> {
> static struct lock_file head_lock;
> struct strbuf buf = STRBUF_INIT;
> int fd;
>
> - fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), LOCK_DIE_ON_ERROR);
> + 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);
> if (write_in_full(fd, buf.buf, buf.len) < 0)
> - die_errno(_("Could not write to %s"), git_path_head_file());
> + return error_errno(_("Could not write to %s"),
> + git_path_head_file());Does this need to rollback the lockfile before returning?
Show 5 quoted lines
> if (commit_lock_file(&head_lock) < 0)
> - die(_("Error wrapping up %s."), git_path_head_file());
> + return error(_("Error wrapping up %s."), git_path_head_file());
> + return 0;
> }