]> git.proxmox.com Git - libgit2.git/blame - src/trace.h
Drop patch as it is merged upstream
[libgit2.git] / src / trace.h
CommitLineData
b5ec5430
ET
1/*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7#ifndef INCLUDE_trace_h__
8#define INCLUDE_trace_h__
9
eae0bfdc
PP
10#include "common.h"
11
b5ec5430
ET
12#include <git2/trace.h>
13#include "buffer.h"
14
15#ifdef GIT_TRACE
16
17struct git_trace_data {
18 git_trace_level_t level;
0c9c969a 19 git_trace_cb callback;
b5ec5430
ET
20};
21
22extern struct git_trace_data git_trace__data;
23
24GIT_INLINE(void) git_trace__write_fmt(
25 git_trace_level_t level,
26 const char *fmt, ...)
27{
0c9c969a 28 git_trace_cb callback = git_trace__data.callback;
b5ec5430
ET
29 git_buf message = GIT_BUF_INIT;
30 va_list ap;
1fed6b07 31
b5ec5430
ET
32 va_start(ap, fmt);
33 git_buf_vprintf(&message, fmt, ap);
34 va_end(ap);
1fed6b07 35
b5ec5430
ET
36 callback(level, git_buf_cstr(&message));
37
ac3d33df 38 git_buf_dispose(&message);
b5ec5430
ET
39}
40
41#define git_trace_level() (git_trace__data.level)
42#define git_trace(l, ...) { \
43 if (git_trace__data.level >= l && \
44 git_trace__data.callback != NULL) { \
45 git_trace__write_fmt(l, __VA_ARGS__); \
46 } \
47 }
48
49#else
50
cde32d4d
JG
51GIT_INLINE(void) git_trace__null(
52 git_trace_level_t level,
53 const char *fmt, ...)
54{
55 GIT_UNUSED(level);
56 GIT_UNUSED(fmt);
57}
58
0c9c969a 59#define git_trace_level() ((git_trace_level_t)0)
cde32d4d 60#define git_trace git_trace__null
b5ec5430
ET
61
62#endif
63
64#endif