mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-06 09:41:04 +00:00

This is a proposed adjustment to the trace APIs. This makes the trace levels into a bitmask so that they can be selectively enabled and adds a callback-level payload, plus a message-level payload. This makes it easier for me to a GIT_TRACE_PERF callbacks that are simply bypassed if the PERF level is not set.
58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
/*
|
|
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
*
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
* a Linking Exception. For full terms see the included COPYING file.
|
|
*/
|
|
#ifndef INCLUDE_trace_h__
|
|
#define INCLUDE_trace_h__
|
|
|
|
#include <git2/trace.h>
|
|
#include "buffer.h"
|
|
|
|
#ifdef GIT_TRACE
|
|
|
|
struct git_trace_data {
|
|
git_trace_level_t level;
|
|
git_trace_callback callback;
|
|
void *callback_payload;
|
|
};
|
|
|
|
extern struct git_trace_data git_trace__data;
|
|
|
|
GIT_INLINE(void) git_trace__write_fmt(
|
|
git_trace_level_t level,
|
|
void *message_payload,
|
|
const char *fmt,
|
|
...)
|
|
{
|
|
git_trace_callback callback = git_trace__data.callback;
|
|
git_buf message = GIT_BUF_INIT;
|
|
va_list ap;
|
|
|
|
va_start(ap, fmt);
|
|
git_buf_vprintf(&message, fmt, ap);
|
|
va_end(ap);
|
|
|
|
callback(
|
|
level, git_trace__data.callback_payload, message_payload,
|
|
git_buf_cstr(&message));
|
|
|
|
git_buf_free(&message);
|
|
}
|
|
|
|
#define git_trace_level() (git_trace__data.level)
|
|
#define git_trace(l, p, ...) do { \
|
|
if ((git_trace__data.level & (l)) != 0 && git_trace__data.callback) { \
|
|
git_trace__write_fmt((l), (p), __VA_ARGS__); \
|
|
} } while (0)
|
|
|
|
#else
|
|
|
|
#define git_trace_level() ((void)0)
|
|
#define git_trace(lvl, ...) ((void)0)
|
|
|
|
#endif
|
|
|
|
#endif
|