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

[PATCH] object-file: inline write_buffer()

From
René Scharfe <l.s.r@web.de>
Date
Dec 13, 2022, 19:35 UTC
Message-ID
<94dff140-489c-40b2-7212-201ed3b7d008@web.de>

write_buffer() reports the OS error if it is unable to write. Its only caller dies in that case, giving some more context in its last message.

Inline this function and show only a single error message that includes both the context (writing a loose object file) and the OS error. This shortens the code and simplifies the output.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 object-file.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/object-file.c b/object-file.c
index 26290554bb..c1b71c2834 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1864,13 +1864,6 @@ int finalize_object_file(const char *tmpfile, const char *filename)
 	return 0;
 }

-static int write_buffer(int fd, const void *buf, size_t len)
-{
-	if (write_in_full(fd, buf, len) < 0)
-		return error_errno(_("file write error"));
-	return 0;
-}
-
 static void hash_object_file_literally(const struct git_hash_algo *algo,
 				       const void *buf, unsigned long len,
 				       const char *type, struct object_id *oid)
@@ -2015,8 +2008,8 @@ static int write_loose_object_common(git_hash_ctx *c,

 	ret = git_deflate(stream, flush ? Z_FINISH : 0);
 	the_hash_algo->update_fn(c, in0, stream->next_in - in0);
-	if (write_buffer(fd, compressed, stream->next_out - compressed) < 0)
-		die(_("unable to write loose object file"));
+	if (write_in_full(fd, compressed, stream->next_out - compressed) < 0)
+		die_errno(_("unable to write loose object file"));
 	stream->next_out = compressed;
 	stream->avail_out = compressed_len;

--
2.39.0
Message 1 of 1 in “object-file: inline write_buffer()”
  1. object-file: inline write_buffer()René Scharfe, Dec 13, 2022

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.