From: Maarten Bosmans Date: Mon, 05 Feb 2024 20:49:30 GMT Subject: [PATCH 2/4] notes: use exisisting function stream_blob_to_fd Message-ID: <20240205204932.16653-3-maarten.bosmans@vortech.nl> In-Reply-To: <20240205204932.16653-1-maarten.bosmans@vortech.nl> From: Maarten Bosmans From: Maarten Bosmans Use functionality from streaming.c and remove the copy_obj_to_fd() function local to notes.c. Streaming the blob to stdout instead of copying through an intermediate buffer might also be more efficient, but at the size a typical note is, this is unlikely to matter a lot. Signed-off-by: Maarten Bosmans --- builtin/notes.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/builtin/notes.c b/builtin/notes.c index 8efe9809b2..048b8c559c 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -149,18 +149,6 @@ static int list_each_note(const struct object_id *object_oid, return 0; } -static void copy_obj_to_fd(int fd, const struct object_id *oid) -{ - unsigned long size; - enum object_type type; - char *buf = repo_read_object_file(the_repository, oid, &type, &size); - if (buf) { - if (size) - write_or_die(fd, buf, size); - free(buf); - } -} - static void write_commented_object(int fd, const struct object_id *object) { struct child_process show = CHILD_PROCESS_INIT; @@ -205,7 +193,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data * if (d->given) write_or_die(fd, d->buf.buf, d->buf.len); else if (old_note) - copy_obj_to_fd(fd, old_note); + stream_blob_to_fd(fd, old_note, NULL, 0); strbuf_addch(&buf, '\n'); strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char); -- 2.35.3