Skip to content

Commit

Permalink
trace: factor out "do we want to trace" logic
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
peff authored and gitster committed Mar 8, 2011
1 parent 0679660 commit 39bc5e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions cache.h
Expand Up @@ -1071,6 +1071,7 @@ 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);
extern int trace_want(const char *key);

/* convert.c */
/* returns 1 if *dst was used */
Expand Down
14 changes: 11 additions & 3 deletions trace.c
Expand Up @@ -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))
Expand All @@ -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;
}

0 comments on commit 39bc5e4

Please sign in to comment.