2006-09-03 00:23:48 +08:00
|
|
|
/*
|
|
|
|
* GIT - The information manager from hell
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2002 Michael R. Elkins <me@mutt.org>
|
|
|
|
* Copyright (C) 2002-2004 Oswald Buddenhagen <ossi@users.sf.net>
|
|
|
|
* Copyright (C) 2004 Theodore Y. Ts'o <tytso@mit.edu>
|
|
|
|
* Copyright (C) 2006 Mike McCormack
|
|
|
|
* Copyright (C) 2006 Christian Couder
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cache.h"
|
|
|
|
#include "quote.h"
|
|
|
|
|
2011-02-24 22:28:41 +08:00
|
|
|
/* Get a trace file descriptor from "key" env variable. */
|
2014-07-12 08:00:06 +08:00
|
|
|
static int get_trace_fd(struct trace_key *key)
|
2006-09-03 00:23:48 +08:00
|
|
|
{
|
2014-07-12 08:00:06 +08:00
|
|
|
static struct trace_key trace_default = { "GIT_TRACE" };
|
|
|
|
const char *trace;
|
|
|
|
|
|
|
|
/* use default "GIT_TRACE" if NULL */
|
|
|
|
if (!key)
|
|
|
|
key = &trace_default;
|
|
|
|
|
|
|
|
/* don't open twice */
|
|
|
|
if (key->initialized)
|
|
|
|
return key->fd;
|
|
|
|
|
|
|
|
trace = getenv(key->key);
|
2006-09-03 00:23:48 +08:00
|
|
|
|
2006-10-14 22:05:25 +08:00
|
|
|
if (!trace || !strcmp(trace, "") ||
|
|
|
|
!strcmp(trace, "0") || !strcasecmp(trace, "false"))
|
2014-07-12 08:00:06 +08:00
|
|
|
key->fd = 0;
|
|
|
|
else if (!strcmp(trace, "1") || !strcasecmp(trace, "true"))
|
|
|
|
key->fd = STDERR_FILENO;
|
|
|
|
else if (strlen(trace) == 1 && isdigit(*trace))
|
|
|
|
key->fd = atoi(trace);
|
|
|
|
else if (is_absolute_path(trace)) {
|
2006-09-03 00:23:48 +08:00
|
|
|
int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
|
|
|
|
if (fd == -1) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Could not open '%s' for tracing: %s\n"
|
|
|
|
"Defaulting to tracing on stderr...\n",
|
|
|
|
trace, strerror(errno));
|
2014-07-12 08:00:06 +08:00
|
|
|
key->fd = STDERR_FILENO;
|
|
|
|
} else {
|
|
|
|
key->fd = fd;
|
|
|
|
key->need_close = 1;
|
2006-09-03 00:23:48 +08:00
|
|
|
}
|
2014-07-12 08:00:06 +08:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "What does '%s' for %s mean?\n"
|
|
|
|
"If you want to trace into a file, then please set "
|
|
|
|
"%s to an absolute pathname (starting with /).\n"
|
|
|
|
"Defaulting to tracing on stderr...\n",
|
|
|
|
trace, key->key, key->key);
|
|
|
|
key->fd = STDERR_FILENO;
|
2006-09-03 00:23:48 +08:00
|
|
|
}
|
|
|
|
|
2014-07-12 08:00:06 +08:00
|
|
|
key->initialized = 1;
|
|
|
|
return key->fd;
|
|
|
|
}
|
2006-09-03 00:23:48 +08:00
|
|
|
|
2014-07-12 08:00:06 +08:00
|
|
|
void trace_disable(struct trace_key *key)
|
|
|
|
{
|
|
|
|
if (key->need_close)
|
|
|
|
close(key->fd);
|
|
|
|
key->fd = 0;
|
|
|
|
key->initialized = 1;
|
|
|
|
key->need_close = 0;
|
2006-09-03 00:23:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char err_msg[] = "Could not trace into fd given by "
|
|
|
|
"GIT_TRACE environment variable";
|
|
|
|
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
static int prepare_trace_line(struct trace_key *key, struct strbuf *buf)
|
|
|
|
{
|
2014-07-12 08:03:01 +08:00
|
|
|
static struct trace_key trace_bare = TRACE_KEY_INIT(BARE);
|
|
|
|
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
if (!trace_want(key))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
set_try_to_free_routine(NULL); /* is never reset */
|
|
|
|
|
2014-07-12 08:03:01 +08:00
|
|
|
/* unit tests may want to disable additional trace output */
|
|
|
|
if (trace_want(&trace_bare))
|
|
|
|
return 1;
|
|
|
|
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
/* add line prefix here */
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_trace_line(struct trace_key *key, struct strbuf *buf)
|
|
|
|
{
|
|
|
|
/* append newline if missing */
|
|
|
|
if (buf->len && buf->buf[buf->len - 1] != '\n')
|
|
|
|
strbuf_addch(buf, '\n');
|
|
|
|
|
|
|
|
write_or_whine_pipe(get_trace_fd(key), buf->buf, buf->len, err_msg);
|
|
|
|
strbuf_release(buf);
|
|
|
|
}
|
|
|
|
|
2014-07-12 08:00:06 +08:00
|
|
|
static void trace_vprintf(struct trace_key *key, const char *format, va_list ap)
|
2006-09-03 00:23:48 +08:00
|
|
|
{
|
2011-02-26 13:08:53 +08:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
2006-09-03 00:23:48 +08:00
|
|
|
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
if (!prepare_trace_line(key, &buf))
|
2006-09-03 00:23:48 +08:00
|
|
|
return;
|
|
|
|
|
2014-06-11 15:57:23 +08:00
|
|
|
strbuf_vaddf(&buf, format, ap);
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
print_trace_line(key, &buf);
|
2006-09-03 00:23:48 +08:00
|
|
|
}
|
|
|
|
|
2014-07-12 08:00:06 +08:00
|
|
|
void trace_printf_key(struct trace_key *key, const char *format, ...)
|
2011-02-24 22:28:41 +08:00
|
|
|
{
|
|
|
|
va_list ap;
|
2014-06-11 15:57:23 +08:00
|
|
|
va_start(ap, format);
|
|
|
|
trace_vprintf(key, format, ap);
|
2011-02-24 22:28:41 +08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2014-06-11 15:57:23 +08:00
|
|
|
void trace_printf(const char *format, ...)
|
2011-02-24 22:28:15 +08:00
|
|
|
{
|
|
|
|
va_list ap;
|
2014-06-11 15:57:23 +08:00
|
|
|
va_start(ap, format);
|
2014-07-12 08:00:06 +08:00
|
|
|
trace_vprintf(NULL, format, ap);
|
2011-02-24 22:28:15 +08:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
void trace_strbuf(struct trace_key *key, const struct strbuf *data)
|
2011-02-24 22:29:50 +08:00
|
|
|
{
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
|
|
|
|
|
|
|
if (!prepare_trace_line(key, &buf))
|
2011-02-24 22:29:50 +08:00
|
|
|
return;
|
|
|
|
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
strbuf_addbuf(&buf, data);
|
|
|
|
print_trace_line(key, &buf);
|
2011-02-24 22:29:50 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 15:57:23 +08:00
|
|
|
void trace_argv_printf(const char **argv, const char *format, ...)
|
2006-09-03 00:23:48 +08:00
|
|
|
{
|
2011-02-26 13:08:53 +08:00
|
|
|
struct strbuf buf = STRBUF_INIT;
|
nfv?asprintf are broken without va_copy, workaround them.
* drop nfasprintf.
* move nfvasprintf into imap-send.c back, and let it work on a 8k buffer,
and die() in case of overflow. It should be enough for imap commands, if
someone cares about imap-send, he's welcomed to fix it properly.
* replace nfvasprintf use in merge-recursive with a copy of the strbuf_addf
logic, it's one place, we'll live with it.
To ease the change, output_buffer string list is replaced with a strbuf ;)
* rework trace.c to call vsnprintf itself. It's used to format strerror()s
and git command names, it should never be more than a few octets long, let
it work on a 8k static buffer with vsnprintf or die loudly.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
2007-09-20 16:43:11 +08:00
|
|
|
va_list ap;
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
|
|
|
|
if (!prepare_trace_line(NULL, &buf))
|
2006-09-03 00:23:48 +08:00
|
|
|
return;
|
|
|
|
|
2014-06-11 15:57:23 +08:00
|
|
|
va_start(ap, format);
|
|
|
|
strbuf_vaddf(&buf, format, ap);
|
nfv?asprintf are broken without va_copy, workaround them.
* drop nfasprintf.
* move nfvasprintf into imap-send.c back, and let it work on a 8k buffer,
and die() in case of overflow. It should be enough for imap commands, if
someone cares about imap-send, he's welcomed to fix it properly.
* replace nfvasprintf use in merge-recursive with a copy of the strbuf_addf
logic, it's one place, we'll live with it.
To ease the change, output_buffer string list is replaced with a strbuf ;)
* rework trace.c to call vsnprintf itself. It's used to format strerror()s
and git command names, it should never be more than a few octets long, let
it work on a 8k static buffer with vsnprintf or die loudly.
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
2007-09-20 16:43:11 +08:00
|
|
|
va_end(ap);
|
2006-09-03 00:23:48 +08:00
|
|
|
|
2007-12-03 12:51:50 +08:00
|
|
|
sq_quote_argv(&buf, argv, 0);
|
trace: add infrastructure to augment trace output with additional info
To be able to add a common prefix or suffix to all trace output (e.g.
a timestamp or file:line of the caller), factor out common setup and
cleanup tasks of the trace* functions.
When adding a common prefix, it makes sense that the output of each trace
call starts on a new line. Add '\n' in case the caller forgot.
Note that this explicitly limits trace output to line-by-line, it is no
longer possible to trace-print just part of a line. Until now, this was
just an implicit assumption (trace-printing part of a line worked, but
messed up the trace file if multiple threads or processes were involved).
Thread-safety / inter-process-safety is also the reason why we need to do
the prefixing and suffixing in memory rather than issuing multiple write()
calls. Write_or_whine_pipe() / xwrite() is atomic unless the size exceeds
MAX_IO_SIZE (8MB, see wrapper.c). In case of trace_strbuf, this costs an
additional string copy (which should be irrelevant for performance in light
of actual file IO).
While we're at it, rename trace_strbuf's 'buf' argument, which suggests
that the function is modifying the buffer. Trace_strbuf() currently is the
only trace API that can print arbitrary binary data (without barfing on
'%' or stopping at '\0'), so 'data' seems more appropriate.
Signed-off-by: Karsten Blees <blees@dcon.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-07-12 08:02:18 +08:00
|
|
|
print_trace_line(NULL, &buf);
|
2006-09-03 00:23:48 +08:00
|
|
|
}
|
2010-11-26 23:31:57 +08:00
|
|
|
|
|
|
|
static const char *quote_crnl(const char *path)
|
|
|
|
{
|
|
|
|
static char new_path[PATH_MAX];
|
|
|
|
const char *p2 = path;
|
|
|
|
char *p1 = new_path;
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
while (*p2) {
|
|
|
|
switch (*p2) {
|
|
|
|
case '\\': *p1++ = '\\'; *p1++ = '\\'; break;
|
|
|
|
case '\n': *p1++ = '\\'; *p1++ = 'n'; break;
|
|
|
|
case '\r': *p1++ = '\\'; *p1++ = 'r'; break;
|
|
|
|
default:
|
|
|
|
*p1++ = *p2;
|
|
|
|
}
|
|
|
|
p2++;
|
|
|
|
}
|
|
|
|
*p1 = '\0';
|
|
|
|
return new_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: move prefix to startup_info struct and get rid of this arg */
|
|
|
|
void trace_repo_setup(const char *prefix)
|
|
|
|
{
|
2014-07-12 08:00:06 +08:00
|
|
|
static struct trace_key key = TRACE_KEY_INIT(SETUP);
|
2011-01-06 08:30:01 +08:00
|
|
|
const char *git_work_tree;
|
2010-11-26 23:31:57 +08:00
|
|
|
char cwd[PATH_MAX];
|
|
|
|
|
2014-07-12 08:00:06 +08:00
|
|
|
if (!trace_want(&key))
|
2010-11-26 23:31:57 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!getcwd(cwd, PATH_MAX))
|
|
|
|
die("Unable to get current working directory");
|
|
|
|
|
2011-01-06 08:30:01 +08:00
|
|
|
if (!(git_work_tree = get_git_work_tree()))
|
|
|
|
git_work_tree = "(null)";
|
|
|
|
|
|
|
|
if (!prefix)
|
|
|
|
prefix = "(null)";
|
|
|
|
|
2014-07-12 08:00:06 +08:00
|
|
|
trace_printf_key(&key, "setup: git_dir: %s\n", quote_crnl(get_git_dir()));
|
|
|
|
trace_printf_key(&key, "setup: worktree: %s\n", quote_crnl(git_work_tree));
|
|
|
|
trace_printf_key(&key, "setup: cwd: %s\n", quote_crnl(cwd));
|
|
|
|
trace_printf_key(&key, "setup: prefix: %s\n", quote_crnl(prefix));
|
2010-11-26 23:31:57 +08:00
|
|
|
}
|
2011-02-24 22:28:59 +08:00
|
|
|
|
2014-07-12 08:00:06 +08:00
|
|
|
int trace_want(struct trace_key *key)
|
2011-02-24 22:28:59 +08:00
|
|
|
{
|
2014-07-12 08:00:06 +08:00
|
|
|
return !!get_trace_fd(key);
|
2011-02-24 22:28:59 +08:00
|
|
|
}
|