trace: remove trace key normalization
Trace key normalization is not used, not strictly necessary, complicates the code and would negatively affect compilation speed if moved to header. New trace_default_key key or existing separate marco could be used instead of passing NULL as a key. Signed-off-by: Gennady Kupava <gkupava@bloomberg.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Gennady Kupava committed
Nov 26, 2017 at 20:11 UTC
406102a731145d39c497e384857ac9f9d2bdccb2
2 files changed
+7
-21
trace.c
+4
-20
@@ -24,26 +24,13 @@
24
#include "cache.h"
25
#include "quote.h"
26
27
-/*
28
- * "Normalize" a key argument by converting NULL to our trace_default,
29
- * and otherwise passing through the value. All caller-facing functions
30
- * should normalize their inputs in this way, though most get it
31
- * for free by calling get_trace_fd() (directly or indirectly).
32
- */
33
-static void normalize_trace_key(struct trace_key **key)
34
-{
35
- static struct trace_key trace_default = { "GIT_TRACE" };
36
- if (!*key)
37
- *key = &trace_default;
38
-}
27
+struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 };
28
29
/* Get a trace file descriptor from "key" env variable. */
30
static int get_trace_fd(struct trace_key *key)
31
{
32
const char *trace;
33
45
- normalize_trace_key(&key);
46
-
34
/* don't open twice */
35
if (key->initialized)
36
return key->fd;
@@ -81,8 +68,6 @@ static int get_trace_fd(struct trace_key *key)
68
69
void trace_disable(struct trace_key *key)
70
{
84
- normalize_trace_key(&key);
85
-
71
if (key->need_close)
72
close(key->fd);
73
key->fd = 0;
@@ -128,7 +113,6 @@ static int prepare_trace_line(const char *file, int line,
113
static void trace_write(struct trace_key *key, const void *buf, unsigned len)
114
{
115
if (write_in_full(get_trace_fd(key), buf, len) < 0) {
131
- normalize_trace_key(&key);
116
warning("unable to write trace for %s: %s",
117
key->key, strerror(errno));
118
trace_disable(key);
@@ -167,13 +151,13 @@ static void trace_argv_vprintf_fl(const char *file, int line,
151
{
152
struct strbuf buf = STRBUF_INIT;
153
170
- if (!prepare_trace_line(file, line, NULL, &buf))
154
+ if (!prepare_trace_line(file, line, &trace_default_key, &buf))
155
return;
156
157
strbuf_vaddf(&buf, format, ap);
158
159
sq_quote_argv(&buf, argv, 0);
176
- print_trace_line(NULL, &buf);
160
+ print_trace_line(&trace_default_key, &buf);
161
}
162
163
void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
@@ -215,7 +199,7 @@ void trace_printf(const char *format, ...)
199
{
200
va_list ap;
201
va_start(ap, format);
218
- trace_vprintf_fl(NULL, 0, NULL, format, ap);
202
+ trace_vprintf_fl(NULL, 0, &trace_default_key, format, ap);
203
va_end(ap);
204
}
205
trace.h
+3
-1
@@ -11,6 +11,8 @@ struct trace_key {
11
unsigned int need_close : 1;
12
};
13
14
+extern struct trace_key trace_default_key;
15
+
16
#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name, 0, 0, 0 }
17
18
extern void trace_repo_setup(const char *prefix);
@@ -78,7 +80,7 @@ extern void trace_performance_since(uint64_t start, const char *format, ...);
80
*/
81
82
#define trace_printf(...) \
81
- trace_printf_key_fl(TRACE_CONTEXT, __LINE__, NULL, __VA_ARGS__)
83
+ trace_printf_key_fl(TRACE_CONTEXT, __LINE__, &trace_default_key, __VA_ARGS__)
84
85
#define trace_printf_key(key, ...) \
86
trace_printf_key_fl(TRACE_CONTEXT, __LINE__, key, __VA_ARGS__)