|
24 | 24 | #include "cache.h"
|
25 | 25 | #include "quote.h"
|
26 | 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 }; |
39 | 28 |
|
40 | 29 | /* Get a trace file descriptor from "key" env variable. */
|
41 | 30 | static int get_trace_fd(struct trace_key *key)
|
42 | 31 | {
|
43 | 32 | const char *trace;
|
44 | 33 |
|
45 |
| - normalize_trace_key(&key); |
46 |
| - |
47 | 34 | /* don't open twice */
|
48 | 35 | if (key->initialized)
|
49 | 36 | return key->fd;
|
@@ -81,8 +68,6 @@ static int get_trace_fd(struct trace_key *key)
|
81 | 68 |
|
82 | 69 | void trace_disable(struct trace_key *key)
|
83 | 70 | {
|
84 |
| - normalize_trace_key(&key); |
85 |
| - |
86 | 71 | if (key->need_close)
|
87 | 72 | close(key->fd);
|
88 | 73 | key->fd = 0;
|
@@ -128,7 +113,6 @@ static int prepare_trace_line(const char *file, int line,
|
128 | 113 | static void trace_write(struct trace_key *key, const void *buf, unsigned len)
|
129 | 114 | {
|
130 | 115 | if (write_in_full(get_trace_fd(key), buf, len) < 0) {
|
131 |
| - normalize_trace_key(&key); |
132 | 116 | warning("unable to write trace for %s: %s",
|
133 | 117 | key->key, strerror(errno));
|
134 | 118 | trace_disable(key);
|
@@ -167,13 +151,13 @@ static void trace_argv_vprintf_fl(const char *file, int line,
|
167 | 151 | {
|
168 | 152 | struct strbuf buf = STRBUF_INIT;
|
169 | 153 |
|
170 |
| - if (!prepare_trace_line(file, line, NULL, &buf)) |
| 154 | + if (!prepare_trace_line(file, line, &trace_default_key, &buf)) |
171 | 155 | return;
|
172 | 156 |
|
173 | 157 | strbuf_vaddf(&buf, format, ap);
|
174 | 158 |
|
175 | 159 | sq_quote_argv(&buf, argv, 0);
|
176 |
| - print_trace_line(NULL, &buf); |
| 160 | + print_trace_line(&trace_default_key, &buf); |
177 | 161 | }
|
178 | 162 |
|
179 | 163 | void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
|
@@ -215,7 +199,7 @@ void trace_printf(const char *format, ...)
|
215 | 199 | {
|
216 | 200 | va_list ap;
|
217 | 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); |
219 | 203 | va_end(ap);
|
220 | 204 | }
|
221 | 205 |
|
|
0 commit comments