1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-22 22:36:09 +02:00

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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2016-08-05 03:58:38 -04:00 committed by Junio C Hamano
parent ca5c701ca5
commit 6f25305799

10
trace.c
View File

@ -61,10 +61,9 @@ static int get_trace_fd(struct trace_key *key)
else if (is_absolute_path(trace)) {
int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
if (fd == -1) {
warning("could not open '%s' for tracing: %s\n"
" Defaulting to tracing on stderr...",
warning("could not open '%s' for tracing: %s",
trace, strerror(errno));
key->fd = STDERR_FILENO;
trace_disable(key);
} else {
key->fd = fd;
key->need_close = 1;
@ -72,10 +71,9 @@ static int get_trace_fd(struct trace_key *key)
} else {
warning("unknown trace value for '%s': %s\n"
" If you want to trace into a file, then please set %s\n"
" to an absolute pathname (starting with /)\n"
" Defaulting to tracing on stderr...",
" to an absolute pathname (starting with /)",
key->key, trace, key->key);
key->fd = STDERR_FILENO;
trace_disable(key);
}
key->initialized = 1;