summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c605354)
raw | patch | inline | side by side (parent: c605354)
author | Jeff King <peff@peff.net> | |
Thu, 24 Feb 2011 14:28:41 +0000 (09:28 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 8 Mar 2011 20:12:04 +0000 (12:12 -0800) |
Right now you turn all tracing off and on with GIT_TRACE. To
support new types of tracing without forcing the user to see
all of them, we will soon support turning each tracing area
on with GIT_TRACE_*.
This patch lays the groundwork by providing an interface
which does not assume GIT_TRACE. However, we still maintain
the trace_printf interface so that existing callers do not
need to be refactored.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
support new types of tracing without forcing the user to see
all of them, we will soon support turning each tracing area
on with GIT_TRACE_*.
This patch lays the groundwork by providing an interface
which does not assume GIT_TRACE. However, we still maintain
the trace_printf interface so that existing callers do not
need to be refactored.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h | patch | blob | history | |
trace.c | patch | blob | history |
index 08b23b2ab96c1c20f90fbb03ad4d155b9a53bf88..2ab1bf9383994e826777da8b4c3fe7a960d6c509 100644 (file)
--- a/cache.h
+++ b/cache.h
/* trace.c */
__attribute__((format (printf, 1, 2)))
extern void trace_printf(const char *format, ...);
-extern void trace_vprintf(const char *format, va_list ap);
+extern void trace_vprintf(const char *key, 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);
index 623e793e4f4a959252347c643c77747b04c80543..1d0e17e014a5268f76e1c13de2311b27866bc6a9 100644 (file)
--- a/trace.c
+++ b/trace.c
#include "cache.h"
#include "quote.h"
-/* Get a trace file descriptor from GIT_TRACE env variable. */
-static int get_trace_fd(int *need_close)
+/* Get a trace file descriptor from "key" env variable. */
+static int get_trace_fd(const char *key, int *need_close)
{
- char *trace = getenv("GIT_TRACE");
+ char *trace = getenv(key);
if (!trace || !strcmp(trace, "") ||
!strcmp(trace, "0") || !strcasecmp(trace, "false"))
return fd;
}
- fprintf(stderr, "What does '%s' for GIT_TRACE mean?\n", trace);
+ fprintf(stderr, "What does '%s' for %s mean?\n", trace, key);
fprintf(stderr, "If you want to trace into a file, "
- "then please set GIT_TRACE to an absolute pathname "
- "(starting with /).\n");
+ "then please set %s to an absolute pathname "
+ "(starting with /).\n", key);
fprintf(stderr, "Defaulting to tracing on stderr...\n");
return STDERR_FILENO;
static const char err_msg[] = "Could not trace into fd given by "
"GIT_TRACE environment variable";
-void trace_vprintf(const char *fmt, va_list ap)
+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(&need_close);
+ fd = get_trace_fd(key, &need_close);
if (!fd)
return;
close(fd);
}
+void trace_printf_key(const char *key, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ trace_vprintf(key, fmt, ap);
+ va_end(ap);
+}
+
void trace_printf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
- trace_vprintf(fmt, ap);
+ trace_vprintf("GIT_TRACE", fmt, ap);
va_end(ap);
}
va_list ap;
int fd, need_close = 0;
- fd = get_trace_fd(&need_close);
+ fd = get_trace_fd("GIT_TRACE", &need_close);
if (!fd)
return;