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

[PATCH v1 1/3] pkt-line: add packet_write_list_gently()

From
Ben Peart <peartben@gmail.com>
Date
Mar 22, 2017, 16:52 UTC
Message-ID
<20170322165220.5660-2-benpeart@microsoft.com>
In-Reply-To
<20170322165220.5660-1-benpeart@microsoft.com>

Add packet_write_list_gently() which writes multiple lines in a single call and then calls packet_flush_gently(). This is used later in this patch series.

Signed-off-by: Ben Peart <benpeart@microsoft.com>
---
 pkt-line.c | 19 +++++++++++++++++++
 pkt-line.h |  1 +
 2 files changed, 20 insertions(+)
diff --git a/pkt-line.c b/pkt-line.c
index d4b6bfe076..fccdac1352 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -171,6 +171,25 @@ int packet_write_fmt_gently(int fd, const char *fmt, ...)
 	return status;
 }
 
+int packet_write_list_gently(int fd, const char *line, ...)
+{
+	va_list args;
+	int err;
+	va_start(args, line);
+	for (;;) {
+		if (!line)
+			break;
+		if (strlen(line) > LARGE_PACKET_DATA_MAX)
+			return -1;
+		err = packet_write_fmt_gently(fd, "%s\n", line);
+		if (err)
+			return err;
+		line = va_arg(args, const char*);
+	}
+	va_end(args);
+	return packet_flush_gently(fd);
+}
+
 static int packet_write_gently(const int fd_out, const char *buf, size_t size)
 {
 	static char packet_write_buffer[LARGE_PACKET_MAX];
diff --git a/pkt-line.h b/pkt-line.h
index 18eac64830..3674d04509 100644
--- a/pkt-line.h
+++ b/pkt-line.h
@@ -25,6 +25,7 @@ void packet_buf_flush(struct strbuf *buf);
 void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
 int packet_flush_gently(int fd);
 int packet_write_fmt_gently(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
+int packet_write_list_gently(int fd, const char *line, ...);
 int write_packetized_from_fd(int fd_in, int fd_out);
 int write_packetized_from_buf(const char *src_in, size_t len, int fd_out);
 
-- 
2.12.0.gvfs.1.42.g0b7328eac2
Previous: Ben PeartNext: Junio C Hamano
Message 2 of 12 in “Add support for downloading blobs on demand”
  1. 0/3 Add support for downloading blobs on demandBen Peart, Mar 22, 2017
  2. 1/3 pkt-line: add packet_write_list_gently()Ben Peart, Mar 22, 2017
  3. Junio C HamanoMar 22, 2017
  4. Ben PeartMar 24, 2017
  5. 3/3 convert: use new sub-process module for filter processesBen Peart, Mar 22, 2017
  6. 2/3 sub-process: refactor the filter process code into a reusable moduleBen Peart, Mar 22, 2017
  7. Junio C HamanoMar 23, 2017
  8. Ben PeartMar 24, 2017
  9. Junio C HamanoMar 24, 2017
  10. Junio C HamanoMar 24, 2017
  11. Ben PeartMar 27, 2017
  12. Duy NguyenMar 25, 2017

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.