Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3feda6a

Browse files
committed
tests: fix compiler warning if tracing is disabled
If building libgit2's test suite with tracing disabled, then the compiler will emit a warning due to the unused `message_prefix` function. Fix the issue by wrapping the whole file into ifdef's for `GIT_TRACE` and providing separate empty function implementations for both `cl_global_trace_register` and `cl_global_trace_disable`.
1 parent fb439c9 commit 3feda6a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tests/clar_libgit2_trace.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
#if defined(GIT_TRACE)
2+
13
#include "clar_libgit2.h"
24
#include "clar_libgit2_trace.h"
35
#include "clar_libgit2_timer.h"
46
#include "trace.h"
57

6-
78
struct method {
89
const char *name;
910
void (*git_trace_cb)(git_trace_level_t level, const char *msg);
@@ -32,7 +33,6 @@ static const char *message_prefix(git_trace_level_t level)
3233
}
3334
}
3435

35-
#if defined(GIT_TRACE)
3636
static void _git_trace_cb__printf(git_trace_level_t level, const char *msg)
3737
{
3838
printf("%s%s\n", message_prefix(level), msg);
@@ -225,15 +225,11 @@ void _cl_trace_cb__event_handler(
225225
}
226226
}
227227

228-
#endif /*GIT_TRACE*/
229-
230228
/**
231229
* Setup/Enable git_trace() based upon settings user's environment.
232-
*
233230
*/
234231
void cl_global_trace_register(void)
235232
{
236-
#if defined(GIT_TRACE)
237233
if (!s_trace_loaded)
238234
_load_trace_params();
239235

@@ -246,7 +242,6 @@ void cl_global_trace_register(void)
246242

247243
git_trace_set(s_trace_level, s_trace_method->git_trace_cb);
248244
cl_trace_register(_cl_trace_cb__event_handler, NULL);
249-
#endif
250245
}
251246

252247
/**
@@ -258,7 +253,6 @@ void cl_global_trace_register(void)
258253
*/
259254
void cl_global_trace_disable(void)
260255
{
261-
#if defined(GIT_TRACE)
262256
cl_trace_register(NULL, NULL);
263257
git_trace_set(GIT_TRACE_NONE, NULL);
264258
if (s_trace_method && s_trace_method->close)
@@ -268,5 +262,16 @@ void cl_global_trace_disable(void)
268262
* since we only want to hit the environment variables
269263
* once.
270264
*/
271-
#endif
272265
}
266+
267+
#else /* GIT_TRACE */
268+
269+
void cl_global_trace_register(void)
270+
{
271+
}
272+
273+
void cl_global_trace_disable(void)
274+
{
275+
}
276+
277+
#endif /* GIT_TRACE*/

0 commit comments

Comments
 (0)