summary refs log tree commit diff
path: root/trace.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-02-24 09:29:50 -0500
committerJunio C Hamano <gitster@pobox.com>2011-03-08 12:12:04 -0800
commit94b3b3746456949d834ec7bf454da3db4eb439cf (patch)
tree1dc8aaf5084f6c435fb5124debcd782bff7786ec /trace.c
parent39bc5e4680a1ed7192968fbe9f5784ad56ecbd36 (diff)
trace: add trace_strbuf
If you happen to have a strbuf, it is a little more readable
and a little more efficient to be able to print it directly
instead of jamming it through the trace_printf interface.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'trace.c')
-rw-r--r--trace.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/trace.c b/trace.c
index ca0ab0448b..9f39eab025 100644
--- a/trace.c
+++ b/trace.c
@@ -65,19 +65,14 @@ static const char err_msg[] = "Could not trace into fd given by "
 void trace_vprintf(const char *key, const char *fmt, va_list ap)
 {
 	struct strbuf buf = STRBUF_INIT;
-	int fd, need_close = 0;
 
-	fd = get_trace_fd(key, &need_close);
-	if (!fd)
+	if (!trace_want(key))
 		return;
 
 	set_try_to_free_routine(NULL);	/* is never reset */
 	strbuf_vaddf(&buf, fmt, ap);
-	write_or_whine_pipe(fd, buf.buf, buf.len, err_msg);
+	trace_strbuf(key, &buf);
 	strbuf_release(&buf);
-
-	if (need_close)
-		close(fd);
 }
 
 void trace_printf_key(const char *key, const char *fmt, ...)
@@ -96,6 +91,20 @@ void trace_printf(const char *fmt, ...)
 	va_end(ap);
 }
 
+void trace_strbuf(const char *key, const struct strbuf *buf)
+{
+	int fd, need_close = 0;
+
+	fd = get_trace_fd(key, &need_close);
+	if (!fd)
+		return;
+
+	write_or_whine_pipe(fd, buf->buf, buf->len, err_msg);
+
+	if (need_close)
+		close(fd);
+}
+
 void trace_argv_printf(const char **argv, const char *fmt, ...)
 {
 	struct strbuf buf = STRBUF_INIT;