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>
Jeff King committed
Feb 24, 2011 at 09:29 UTC
94b3b3746456949d834ec7bf454da3db4eb439cf
2 files changed
+17
-7
cache.h
+1
@@ -1072,6 +1072,7 @@ __attribute__((format (printf, 2, 3)))
1072
extern void trace_argv_printf(const char **argv, const char *format, ...);
1073
extern void trace_repo_setup(const char *prefix);
1074
extern int trace_want(const char *key);
1075
+extern void trace_strbuf(const char *key, const struct strbuf *buf);
1076
1077
/* convert.c */
1078
/* returns 1 if *dst was used */
trace.c
+16
-7
@@ -65,19 +65,14 @@ static const char err_msg[] = "Could not trace into fd given by "
65
void trace_vprintf(const char *key, const char *fmt, va_list ap)
66
{
67
struct strbuf buf = STRBUF_INIT;
68
- int fd, need_close = 0;
68
70
- fd = get_trace_fd(key, &need_close);
71
- if (!fd)
69
+ if (!trace_want(key))
70
return;
71
72
set_try_to_free_routine(NULL); /* is never reset */
73
strbuf_vaddf(&buf, fmt, ap);
76
- write_or_whine_pipe(fd, buf.buf, buf.len, err_msg);
74
+ trace_strbuf(key, &buf);
75
strbuf_release(&buf);
78
-
79
- if (need_close)
80
- close(fd);
76
}
77
78
void trace_printf_key(const char *key, const char *fmt, ...)
@@ -96,6 +91,20 @@ void trace_printf(const char *fmt, ...)
91
va_end(ap);
92
}
93
94
+void trace_strbuf(const char *key, const struct strbuf *buf)
95
+{
96
+ int fd, need_close = 0;
97
+
98
+ fd = get_trace_fd(key, &need_close);
99
+ if (!fd)
100
+ return;
101
+
102
+ write_or_whine_pipe(fd, buf->buf, buf->len, err_msg);
103
+
104
+ if (need_close)
105
+ close(fd);
106
+}
107
+
108
void trace_argv_printf(const char **argv, const char *fmt, ...)
109
{
110
struct strbuf buf = STRBUF_INIT;