trace: factor out "do we want to trace" logic
As we add more tracing areas, this will avoid repeated code. Technically, trace_printf already checks this and will avoid printing if the trace key is not set. However, callers may want to find out early whether or not tracing is enabled so they can avoid doing work in the common non-trace case. 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:28 UTC
39bc5e4680a1ed7192968fbe9f5784ad56ecbd36
2 files changed
+12
-3
cache.h
+1
@@ -1071,6 +1071,7 @@ extern void trace_vprintf(const char *key, const char *format, va_list ap);
1071
__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
1076
/* convert.c */
1077
/* returns 1 if *dst was used */
trace.c
+11
-3
@@ -148,10 +148,8 @@ void trace_repo_setup(const char *prefix)
148
{
149
const char *git_work_tree;
150
char cwd[PATH_MAX];
151
- char *trace = getenv("GIT_TRACE");
151
153
- if (!trace || !strcmp(trace, "") ||
154
- !strcmp(trace, "0") || !strcasecmp(trace, "false"))
152
+ if (!trace_want("GIT_TRACE"))
153
return;
154
155
if (!getcwd(cwd, PATH_MAX))
@@ -168,3 +166,13 @@ void trace_repo_setup(const char *prefix)
166
trace_printf("setup: cwd: %s\n", quote_crnl(cwd));
167
trace_printf("setup: prefix: %s\n", quote_crnl(prefix));
168
}
169
+
170
+int trace_want(const char *key)
171
+{
172
+ const char *trace = getenv(key);
173
+
174
+ if (!trace || !strcmp(trace, "") ||
175
+ !strcmp(trace, "0") || !strcasecmp(trace, "false"))
176
+ return 0;
177
+ return 1;
178
+}