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

[PATCH 4/7] Refactor packet_write to prepare to integrate with sideband

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 30, 2008, 06:22 UTC
Message-ID
<20080130062206.GD15838@spearce.org>

Simple refactoring to move the actual formatting into a helper function. Later we'll integrate this new helper with sideband support, so we can embed a packet line within a multiplexed sideband stream.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 pkt-line.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/pkt-line.c b/pkt-line.c
index 355546a..5917e1d 100644
--- a/pkt-line.c
+++ b/pkt-line.c
@@ -43,16 +43,16 @@ void packet_flush(int fd)
 }
 
 #define hex(a) (hexchar[(a) & 15])
-void packet_write(int fd, const char *fmt, ...)
+static void packet_vwrite(
+	int fd,
+	const char *fmt,
+	va_list args)
 {
 	static char buffer[1000];
 	static char hexchar[] = "0123456789abcdef";
-	va_list args;
 	unsigned n;
 
-	va_start(args, fmt);
 	n = vsnprintf(buffer + 4, sizeof(buffer) - 4, fmt, args);
-	va_end(args);
 	if (n >= sizeof(buffer)-4)
 		die("protocol error: impossibly long line");
 	n += 4;
@@ -63,6 +63,15 @@ void packet_write(int fd, const char *fmt, ...)
 	safe_write(fd, buffer, n);
 }
 
+void packet_write(int fd, const char *fmt, ...)
+{
+	va_list args;
+
+	va_start(args, fmt);
+	packet_vwrite(fd, fmt, args);
+	va_end(args);
+}
+
 static void safe_read(int fd, void *buffer, unsigned size)
 {
 	size_t n = 0;
-- 
1.5.4.rc5.1126.g6ba14
Message 1 of 1 in “Refactor packet_write to prepare to integrate with sideband”
  1. 4/7 Refactor packet_write to prepare to integrate with sidebandShawn O. Pearce, Jan 30, 2008

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.