write_file(): drop "fatal" parameter
All callers except three passed 1 for the "fatal" parameter to ask this function to die upon error, but to a casual reader of the code, it was not all obvious what that 1 meant. Instead, split the function into two based on a common write_file_v() that takes the flag, introduce write_file_gently() as a new way to attempt creating a file without dying on error, and make three callers to call it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
@ -205,13 +205,13 @@ static int write_state_text(const struct am_state *state,
|
||||
fmt = "%s\n";
|
||||
else
|
||||
fmt = "%s";
|
||||
return write_file(am_path(state, name), 1, fmt, string);
|
||||
return write_file(am_path(state, name), fmt, string);
|
||||
}
|
||||
|
||||
static int write_state_count(const struct am_state *state,
|
||||
const char *name, int value)
|
||||
{
|
||||
return write_file(am_path(state, name), 1, "%d\n", value);
|
||||
return write_file(am_path(state, name), "%d\n", value);
|
||||
}
|
||||
|
||||
static int write_state_bool(const struct am_state *state,
|
||||
|
@ -776,7 +776,7 @@ static int edit_branch_description(const char *branch_name)
|
||||
" %s\n"
|
||||
"Lines starting with '%c' will be stripped.\n",
|
||||
branch_name, comment_line_char);
|
||||
if (write_file(git_path(edit_description), 0, "%s", buf.buf)) {
|
||||
if (write_file_gently(git_path(edit_description), "%s", buf.buf)) {
|
||||
strbuf_release(&buf);
|
||||
return error(_("could not write branch description template: %s"),
|
||||
strerror(errno));
|
||||
|
@ -378,7 +378,7 @@ static void separate_git_dir(const char *git_dir)
|
||||
die_errno(_("unable to move %s to %s"), src, git_dir);
|
||||
}
|
||||
|
||||
write_file(git_link, 1, "gitdir: %s\n", git_dir);
|
||||
write_file(git_link, "gitdir: %s\n", git_dir);
|
||||
}
|
||||
|
||||
int init_db(const char *template_dir, unsigned int flags)
|
||||
|
@ -213,7 +213,7 @@ static int add_worktree(const char *path, const char **child_argv)
|
||||
* after the preparation is over.
|
||||
*/
|
||||
strbuf_addf(&sb, "%s/locked", sb_repo.buf);
|
||||
write_file(sb.buf, 1, "initializing\n");
|
||||
write_file(sb.buf, "initializing\n");
|
||||
|
||||
strbuf_addf(&sb_git, "%s/.git", path);
|
||||
if (safe_create_leading_directories_const(sb_git.buf))
|
||||
@ -223,8 +223,8 @@ static int add_worktree(const char *path, const char **child_argv)
|
||||
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "%s/gitdir", sb_repo.buf);
|
||||
write_file(sb.buf, 1, "%s\n", real_path(sb_git.buf));
|
||||
write_file(sb_git.buf, 1, "gitdir: %s/worktrees/%s\n",
|
||||
write_file(sb.buf, "%s\n", real_path(sb_git.buf));
|
||||
write_file(sb_git.buf, "gitdir: %s/worktrees/%s\n",
|
||||
real_path(get_git_common_dir()), name);
|
||||
/*
|
||||
* This is to keep resolve_ref() happy. We need a valid HEAD
|
||||
@ -241,10 +241,10 @@ static int add_worktree(const char *path, const char **child_argv)
|
||||
die(_("unable to resolve HEAD"));
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "%s/HEAD", sb_repo.buf);
|
||||
write_file(sb.buf, 1, "%s\n", sha1_to_hex(rev));
|
||||
write_file(sb.buf, "%s\n", sha1_to_hex(rev));
|
||||
strbuf_reset(&sb);
|
||||
strbuf_addf(&sb, "%s/commondir", sb_repo.buf);
|
||||
write_file(sb.buf, 1, "../..\n");
|
||||
write_file(sb.buf, "../..\n");
|
||||
|
||||
fprintf_ln(stderr, _("Enter %s (identifier %s)"), path, name);
|
||||
|
||||
|
Reference in New Issue
Block a user