git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/8] write_file: drop "gently" form

From
Jeff King <peff@peff.net>
Date
Jul 8, 2016, 09:09 UTC
Message-ID
<20160708090934.GD10152@sigill.intra.peff.net>
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
Previous: Jeff KingNext: Jeff King
Message 9 of 27 in “am: ignore return value of write_file()”
  1. am: ignore return value of write_file()René Scharfe, Jul 7, 2016
  2. Jeff KingJul 7, 2016
  3. Johannes SchindelinJul 8, 2016
  4. Jeff KingJul 8, 2016
  5. 0/8 write_file cleanupsJeff King, Jul 8, 2016
  6. 1/8 config: fix bogus fd check when setting up default configJeff King, Jul 8, 2016
  7. 2/8 am: ignore return value of write_file()Jeff King, Jul 8, 2016
  8. 3/8 branch: use non-gentle write_file for branch descriptionJeff King, Jul 8, 2016
  9. 4/8 write_file: drop "gently" formJeff King, Jul 8, 2016
  10. 5/8 write_file: use xopenJeff King, Jul 8, 2016
  11. 6/8 write_file: add pointer+len variantJeff King, Jul 8, 2016
  12. 7/8 write_file: add format attributeJeff King, Jul 8, 2016
  13. Jeff KingJul 8, 2016
  14. 1/2 walker: let walker_say take arbitrary formatsJeff King, Jul 8, 2016
  15. 2/2 avoid using sha1_to_hex output as printf formatJeff King, Jul 8, 2016
  16. Jeff KingJul 8, 2016
  17. Junio C HamanoJul 8, 2016
  18. Junio C HamanoJul 8, 2016
  19. Jeff KingJul 8, 2016
  20. 8/8 use write_file_buf where applicableJeff King, Jul 8, 2016
  21. 9/8 branch: use write_file_buf instead of write_fileJeff King, Jul 8, 2016
  22. René ScharfeJul 8, 2016
  23. Johannes SchindelinJul 9, 2016
  24. Johannes SchindelinJul 10, 2016
  25. Johannes SchindelinJul 8, 2016
  26. René ScharfeJul 8, 2016
  27. Jeff KingJul 8, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.