diff options
-rw-r--r-- | builtin/branch.c | 5 | ||||
-rw-r--r-- | cache.h | 3 | ||||
-rw-r--r-- | wrapper.c | 54 |
3 files changed, 13 insertions, 49 deletions
diff --git a/builtin/branch.c b/builtin/branch.c index 2ecde53bf8..15232c4a42 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -618,10 +618,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_gently(git_path(edit_description), "%s", buf.buf)) { - strbuf_release(&buf); - return error_errno(_("could not write branch description template")); - } + write_file(git_path(edit_description), "%s", buf.buf); strbuf_reset(&buf); if (launch_editor(git_path(edit_description), &buf, NULL)) { strbuf_release(&buf); @@ -1734,8 +1734,7 @@ static inline ssize_t write_str_in_full(int fd, const char *str) return write_in_full(fd, str, strlen(str)); } -extern int write_file(const char *path, const char *fmt, ...); -extern int write_file_gently(const char *path, const char *fmt, ...); +extern void write_file(const char *path, const char *fmt, ...); /* pager.c */ extern void setup_pager(void); @@ -640,56 +640,24 @@ int xsnprintf(char *dst, size_t max, const char *fmt, ...) return len; } -static int write_file_v(const char *path, int fatal, - const char *fmt, va_list params) +void write_file(const char *path, const char *fmt, ...) { + va_list params; struct strbuf sb = STRBUF_INIT; int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0666); - if (fd < 0) { - if (fatal) - die_errno(_("could not open %s for writing"), path); - return -1; - } - strbuf_vaddf(&sb, fmt, params); - strbuf_complete_line(&sb); - if (write_in_full(fd, sb.buf, sb.len) != sb.len) { - int err = errno; - close(fd); - strbuf_release(&sb); - errno = err; - if (fatal) - die_errno(_("could not write to %s"), path); - return -1; - } - strbuf_release(&sb); - if (close(fd)) { - if (fatal) - die_errno(_("could not close %s"), path); - return -1; - } - return 0; -} - -int write_file(const char *path, const char *fmt, ...) -{ - int status; - va_list params; + if (fd < 0) + die_errno(_("could not open %s for writing"), path); va_start(params, fmt); - status = write_file_v(path, 1, fmt, params); + strbuf_vaddf(&sb, fmt, params); va_end(params); - return status; -} - -int write_file_gently(const char *path, const char *fmt, ...) -{ - int status; - va_list params; - va_start(params, fmt); - status = write_file_v(path, 0, fmt, params); - va_end(params); - return status; + strbuf_complete_line(&sb); + if (write_in_full(fd, sb.buf, sb.len) != sb.len) + die_errno(_("could not write to %s"), path); + strbuf_release(&sb); + if (close(fd)) + die_errno(_("could not close %s"), path); } void sleep_millisec(int millisec) |