Skip to content

Commit 406102a

Browse files
Gennady Kupavagitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 14c63a9 commit 406102a

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

trace.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,13 @@
2424
#include "cache.h"
2525
#include "quote.h"
2626

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 };
3928

4029
/* Get a trace file descriptor from "key" env variable. */
4130
static int get_trace_fd(struct trace_key *key)
4231
{
4332
const char *trace;
4433

45-
normalize_trace_key(&key);
46-
4734
/* don't open twice */
4835
if (key->initialized)
4936
return key->fd;
@@ -81,8 +68,6 @@ static int get_trace_fd(struct trace_key *key)
8168

8269
void trace_disable(struct trace_key *key)
8370
{
84-
normalize_trace_key(&key);
85-
8671
if (key->need_close)
8772
close(key->fd);
8873
key->fd = 0;
@@ -128,7 +113,6 @@ static int prepare_trace_line(const char *file, int line,
128113
static void trace_write(struct trace_key *key, const void *buf, unsigned len)
129114
{
130115
if (write_in_full(get_trace_fd(key), buf, len) < 0) {
131-
normalize_trace_key(&key);
132116
warning("unable to write trace for %s: %s",
133117
key->key, strerror(errno));
134118
trace_disable(key);
@@ -167,13 +151,13 @@ static void trace_argv_vprintf_fl(const char *file, int line,
167151
{
168152
struct strbuf buf = STRBUF_INIT;
169153

170-
if (!prepare_trace_line(file, line, NULL, &buf))
154+
if (!prepare_trace_line(file, line, &trace_default_key, &buf))
171155
return;
172156

173157
strbuf_vaddf(&buf, format, ap);
174158

175159
sq_quote_argv(&buf, argv, 0);
176-
print_trace_line(NULL, &buf);
160+
print_trace_line(&trace_default_key, &buf);
177161
}
178162

179163
void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
@@ -215,7 +199,7 @@ void trace_printf(const char *format, ...)
215199
{
216200
va_list ap;
217201
va_start(ap, format);
218-
trace_vprintf_fl(NULL, 0, NULL, format, ap);
202+
trace_vprintf_fl(NULL, 0, &trace_default_key, format, ap);
219203
va_end(ap);
220204
}
221205

trace.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ struct trace_key {
1111
unsigned int need_close : 1;
1212
};
1313

14+
extern struct trace_key trace_default_key;
15+
1416
#define TRACE_KEY_INIT(name) { "GIT_TRACE_" #name, 0, 0, 0 }
1517

1618
extern void trace_repo_setup(const char *prefix);
@@ -78,7 +80,7 @@ extern void trace_performance_since(uint64_t start, const char *format, ...);
7880
*/
7981

8082
#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__)
8284

8385
#define trace_printf_key(key, ...) \
8486
trace_printf_key_fl(TRACE_CONTEXT, __LINE__, key, __VA_ARGS__)

0 commit comments

Comments
 (0)