]> git.ipfire.org Git - thirdparty/git.git/blobdiff - trace.c
Merge branch 'master' of git://repo.or.cz/git/fastimport
[thirdparty/git.git] / trace.c
diff --git a/trace.c b/trace.c
index f9efc918b8a0aa907a36edd107a2fa2a14582e78..7961a27a2ed4f32c766dabdf12c4115c3d3b36ba 100644 (file)
--- a/trace.c
+++ b/trace.c
 #include "quote.h"
 
 /* Stolen from "imap-send.c". */
-static int git_vasprintf(char **strp, const char *fmt, va_list ap)
+int nfvasprintf(char **strp, const char *fmt, va_list ap)
 {
        int len;
        char tmp[1024];
 
        if ((len = vsnprintf(tmp, sizeof(tmp), fmt, ap)) < 0 ||
            !(*strp = xmalloc(len + 1)))
-               return -1;
+               die("Fatal: Out of memory\n");
        if (len >= (int)sizeof(tmp))
                vsprintf(*strp, fmt, ap);
        else
@@ -41,13 +41,15 @@ static int git_vasprintf(char **strp, const char *fmt, va_list ap)
        return len;
 }
 
-/* Stolen from "imap-send.c". */
-int nfvasprintf(char **str, const char *fmt, va_list va)
+int nfasprintf(char **str, const char *fmt, ...)
 {
-       int ret = git_vasprintf(str, fmt, va);
-       if (ret < 0)
-               die("Fatal: Out of memory\n");
-       return ret;
+       int rc;
+       va_list args;
+
+       va_start(args, fmt);
+       rc = nfvasprintf(str, fmt, args);
+       va_end(args);
+       return rc;
 }
 
 /* Get a trace file descriptor from GIT_TRACE env variable. */
@@ -55,7 +57,8 @@ static int get_trace_fd(int *need_close)
 {
        char *trace = getenv("GIT_TRACE");
 
-       if (!trace || !strcmp(trace, "0") || !strcasecmp(trace, "false"))
+       if (!trace || !strcmp(trace, "") ||
+           !strcmp(trace, "0") || !strcasecmp(trace, "false"))
                return 0;
        if (!strcmp(trace, "1") || !strcasecmp(trace, "true"))
                return STDERR_FILENO;
@@ -100,7 +103,7 @@ void trace_printf(const char *format, ...)
        nfvasprintf(&trace_str, format, rest);
        va_end(rest);
 
-       write_or_whine(fd, trace_str, strlen(trace_str), err_msg);
+       write_or_whine_pipe(fd, trace_str, strlen(trace_str), err_msg);
 
        free(trace_str);
 
@@ -138,7 +141,7 @@ void trace_argv_printf(const char **argv, int count, const char *format, ...)
        strncpy(trace_str + format_len, argv_str, argv_len);
        strcpy(trace_str + trace_len - 1, "\n");
 
-       write_or_whine(fd, trace_str, trace_len, err_msg);
+       write_or_whine_pipe(fd, trace_str, trace_len, err_msg);
 
        free(argv_str);
        free(format_str);