git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: "René Scharfe" <l.s.r@web.de>, "Git List" <git@vger.kernel.org>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH 4/8] write_file: drop "gently" form
Date: Fri, 8 Jul 2016 05:09:34 -0400	[thread overview]
Message-ID: <20160708090934.GD10152@sigill.intra.peff.net> (raw)
In-Reply-To: <20160708090400.GA26594@sigill.intra.peff.net>

There are no callers left of write_file_gently(). Let's drop
it, as it doesn't seem likely for new callers to be added
(since its inception, the only callers who wanted the gentle
form generally just died immediately themselves, and have
since been converted).

While we're there, let's also drop the "int" return from
write_file, as it is never meaningful (in the non-gentle
form, we always either die or return 0).

Signed-off-by: Jeff King <peff@peff.net>
---
 cache.h   |  3 +--
 wrapper.c | 54 +++++++++++-------------------------------------------
 2 files changed, 12 insertions(+), 45 deletions(-)

diff --git a/cache.h b/cache.h
index f1dc289..3f6c53f 100644
--- a/cache.h
+++ b/cache.h
@@ -1745,8 +1745,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);
diff --git a/wrapper.c b/wrapper.c
index 5dc4e15..0349441 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -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)
-- 
2.9.0.393.g704e522


  parent reply	other threads:[~2016-07-08  9:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-07 20:02 [PATCH] am: ignore return value of write_file() René Scharfe
2016-07-07 20:31 ` Jeff King
2016-07-08  6:37   ` Johannes Schindelin
2016-07-08  6:56     ` Jeff King
2016-07-08  9:04       ` [PATCH 0/8] write_file cleanups Jeff King
2016-07-08  9:06         ` [PATCH 1/8] config: fix bogus fd check when setting up default config Jeff King
2016-07-08  9:08         ` [PATCH 2/8] am: ignore return value of write_file() Jeff King
2016-07-08  9:08         ` [PATCH 3/8] branch: use non-gentle write_file for branch description Jeff King
2016-07-08  9:09         ` Jeff King [this message]
2016-07-08  9:10         ` [PATCH 5/8] write_file: use xopen Jeff King
2016-07-08  9:12         ` [PATCH 6/8] write_file: add pointer+len variant Jeff King
2016-07-08  9:12         ` [PATCH 7/8] write_file: add format attribute Jeff King
2016-07-08  9:25           ` Jeff King
2016-07-08  9:25             ` [PATCH 1/2] walker: let walker_say take arbitrary formats Jeff King
2016-07-08  9:25             ` [PATCH 2/2] avoid using sha1_to_hex output as printf format Jeff King
2016-07-08 10:35               ` Jeff King
2016-07-08 17:02                 ` Junio C Hamano
2016-07-08 17:09                   ` Junio C Hamano
2016-07-08 21:41                     ` Jeff King
2016-07-08  9:12         ` [PATCH 8/8] use write_file_buf where applicable Jeff King
2016-07-08  9:16         ` [PATCH 9/8] branch: use write_file_buf instead of write_file Jeff King
2016-07-08 18:44         ` [PATCH 0/8] write_file cleanups René Scharfe
2016-07-09 14:24       ` [PATCH] am: ignore return value of write_file() Johannes Schindelin
2016-07-10 10:53         ` Johannes Schindelin
2016-07-08  6:33 ` Johannes Schindelin
2016-07-08 18:44   ` René Scharfe
2016-07-08 21:51     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160708090934.GD10152@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).