Navigation Menu

Skip to content

Commit

Permalink
trace: add trace_vprintf
Browse files Browse the repository at this point in the history
This is a necessary cleanup to adding new types of trace
functions.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Mar 8, 2011
1 parent 26db0f2 commit c605354
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions cache.h
Expand Up @@ -1067,6 +1067,7 @@ extern void alloc_report(void);
/* trace.c */
__attribute__((format (printf, 1, 2)))
extern void trace_printf(const char *format, ...);
extern void trace_vprintf(const char *format, va_list ap);
__attribute__((format (printf, 2, 3)))
extern void trace_argv_printf(const char **argv, const char *format, ...);
extern void trace_repo_setup(const char *prefix);
Expand Down
14 changes: 9 additions & 5 deletions trace.c
Expand Up @@ -62,28 +62,32 @@ static int get_trace_fd(int *need_close)
static const char err_msg[] = "Could not trace into fd given by "
"GIT_TRACE environment variable";

void trace_printf(const char *fmt, ...)
void trace_vprintf(const char *fmt, va_list ap)
{
struct strbuf buf = STRBUF_INIT;
va_list ap;
int fd, need_close = 0;

fd = get_trace_fd(&need_close);
if (!fd)
return;

set_try_to_free_routine(NULL); /* is never reset */
va_start(ap, fmt);
strbuf_vaddf(&buf, fmt, ap);
va_end(ap);

write_or_whine_pipe(fd, buf.buf, buf.len, err_msg);
strbuf_release(&buf);

if (need_close)
close(fd);
}

void trace_printf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
trace_vprintf(fmt, ap);
va_end(ap);
}

void trace_argv_printf(const char **argv, const char *fmt, ...)
{
struct strbuf buf = STRBUF_INIT;
Expand Down

0 comments on commit c605354

Please sign in to comment.