summaryrefslogtreecommitdiff
path: root/trace.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-02-24 14:28:59 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-03-08 20:12:04 (GMT)
commit39bc5e4680a1ed7192968fbe9f5784ad56ecbd36 (patch)
treeca97ba49a31a39d59a5d61bf4cfcf07904317255 /trace.c
parent06796607ef557e8913f1797cca3c98ce4844c36c (diff)
downloadgit-39bc5e4680a1ed7192968fbe9f5784ad56ecbd36.zip
git-39bc5e4680a1ed7192968fbe9f5784ad56ecbd36.tar.gz
git-39bc5e4680a1ed7192968fbe9f5784ad56ecbd36.tar.bz2
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>
Diffstat (limited to 'trace.c')
-rw-r--r--trace.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/trace.c b/trace.c
index 1d0e17e..ca0ab04 100644
--- a/trace.c
+++ b/trace.c
@@ -148,10 +148,8 @@ void trace_repo_setup(const char *prefix)
{
const char *git_work_tree;
char cwd[PATH_MAX];
- char *trace = getenv("GIT_TRACE");
- if (!trace || !strcmp(trace, "") ||
- !strcmp(trace, "0") || !strcasecmp(trace, "false"))
+ if (!trace_want("GIT_TRACE"))
return;
if (!getcwd(cwd, PATH_MAX))
@@ -168,3 +166,13 @@ void trace_repo_setup(const char *prefix)
trace_printf("setup: cwd: %s\n", quote_crnl(cwd));
trace_printf("setup: prefix: %s\n", quote_crnl(prefix));
}
+
+int trace_want(const char *key)
+{
+ const char *trace = getenv(key);
+
+ if (!trace || !strcmp(trace, "") ||
+ !strcmp(trace, "0") || !strcasecmp(trace, "false"))
+ return 0;
+ return 1;
+}