Skip to content

Commit 6f25305

Browse files
peffgitster
authored andcommitted
trace: do not fall back to stderr
If the trace code cannot open a specified file, or does not understand the contents of the GIT_TRACE variable, it falls back to printing trace output to stderr. This is an attempt to be helpful, but in practice it just ends up annoying. The user was trying to get the output to go somewhere else, so spewing it to stderr does not really accomplish that. And as it's intended for debugging, they can presumably re-run the command with their error corrected. So instead of falling back, this patch disables bogus trace keys for the rest of the program, just as we do for write errors. We can drop the "Defaulting to..." part of the error message entirely; after seeing "cannot open '/foo'", the user can assume that tracing is skipped. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ca5c701 commit 6f25305

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

trace.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,19 @@ static int get_trace_fd(struct trace_key *key)
6161
else if (is_absolute_path(trace)) {
6262
int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
6363
if (fd == -1) {
64-
warning("could not open '%s' for tracing: %s\n"
65-
" Defaulting to tracing on stderr...",
64+
warning("could not open '%s' for tracing: %s",
6665
trace, strerror(errno));
67-
key->fd = STDERR_FILENO;
66+
trace_disable(key);
6867
} else {
6968
key->fd = fd;
7069
key->need_close = 1;
7170
}
7271
} else {
7372
warning("unknown trace value for '%s': %s\n"
7473
" If you want to trace into a file, then please set %s\n"
75-
" to an absolute pathname (starting with /)\n"
76-
" Defaulting to tracing on stderr...",
74+
" to an absolute pathname (starting with /)",
7775
key->key, trace, key->key);
78-
key->fd = STDERR_FILENO;
76+
trace_disable(key);
7977
}
8078

8179
key->initialized = 1;

0 commit comments

Comments
 (0)