Skip to content

Commit 124647c

Browse files
kbleesgitster
authored andcommitted
trace: disable additional trace output for unit tests
Some unit-tests use trace output to verify internal state, and unstable output such as timestamps and line numbers are not useful there. Disable additional trace output if GIT_TRACE_BARE is set. Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c69dfd2 commit 124647c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

t/test-lib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME
109109
export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME
110110
export EDITOR
111111

112+
# Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output
113+
GIT_TRACE_BARE=1
114+
export GIT_TRACE_BARE
115+
112116
if test -n "${TEST_GIT_INDEX_VERSION:+isset}"
113117
then
114118
GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION"

trace.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,17 @@ static const char err_msg[] = "Could not trace into fd given by "
8787

8888
static int prepare_trace_line(struct trace_key *key, struct strbuf *buf)
8989
{
90+
static struct trace_key trace_bare = TRACE_KEY_INIT(BARE);
91+
9092
if (!trace_want(key))
9193
return 0;
9294

9395
set_try_to_free_routine(NULL); /* is never reset */
9496

97+
/* unit tests may want to disable additional trace output */
98+
if (trace_want(&trace_bare))
99+
return 1;
100+
95101
/* add line prefix here */
96102

97103
return 1;

0 commit comments

Comments
 (0)