Code

i18n: git-notes basic commands
[git.git] / trace.c
diff --git a/trace.c b/trace.c
index 02279b82c48eeb9b6e084b10dc2646eec5efbc01..eda3f6d721dc3c70a858eaa247a3100111324fb4 100644 (file)
--- a/trace.c
+++ b/trace.c
@@ -64,28 +64,18 @@ static const char err_msg[] = "Could not trace into fd given by "
 
 void trace_printf(const char *fmt, ...)
 {
-       struct strbuf buf;
+       struct strbuf buf = STRBUF_INIT;
        va_list ap;
-       int fd, len, need_close = 0;
+       int fd, need_close = 0;
 
        fd = get_trace_fd(&need_close);
        if (!fd)
                return;
 
        set_try_to_free_routine(NULL);  /* is never reset */
-       strbuf_init(&buf, 64);
        va_start(ap, fmt);
-       len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
+       strbuf_vaddf(&buf, fmt, ap);
        va_end(ap);
-       if (len >= strbuf_avail(&buf)) {
-               strbuf_grow(&buf, len - strbuf_avail(&buf) + 128);
-               va_start(ap, fmt);
-               len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
-               va_end(ap);
-               if (len >= strbuf_avail(&buf))
-                       die("broken vsnprintf");
-       }
-       strbuf_setlen(&buf, len);
 
        write_or_whine_pipe(fd, buf.buf, buf.len, err_msg);
        strbuf_release(&buf);
@@ -96,28 +86,18 @@ void trace_printf(const char *fmt, ...)
 
 void trace_argv_printf(const char **argv, const char *fmt, ...)
 {
-       struct strbuf buf;
+       struct strbuf buf = STRBUF_INIT;
        va_list ap;
-       int fd, len, need_close = 0;
+       int fd, need_close = 0;
 
        fd = get_trace_fd(&need_close);
        if (!fd)
                return;
 
        set_try_to_free_routine(NULL);  /* is never reset */
-       strbuf_init(&buf, 64);
        va_start(ap, fmt);
-       len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
+       strbuf_vaddf(&buf, fmt, ap);
        va_end(ap);
-       if (len >= strbuf_avail(&buf)) {
-               strbuf_grow(&buf, len - strbuf_avail(&buf) + 128);
-               va_start(ap, fmt);
-               len = vsnprintf(buf.buf, strbuf_avail(&buf), fmt, ap);
-               va_end(ap);
-               if (len >= strbuf_avail(&buf))
-                       die("broken vsnprintf");
-       }
-       strbuf_setlen(&buf, len);
 
        sq_quote_argv(&buf, argv, 0);
        strbuf_addch(&buf, '\n');
@@ -154,6 +134,7 @@ static const char *quote_crnl(const char *path)
 /* FIXME: move prefix to startup_info struct and get rid of this arg */
 void trace_repo_setup(const char *prefix)
 {
+       const char *git_work_tree;
        char cwd[PATH_MAX];
        char *trace = getenv("GIT_TRACE");
 
@@ -164,8 +145,14 @@ void trace_repo_setup(const char *prefix)
        if (!getcwd(cwd, PATH_MAX))
                die("Unable to get current working directory");
 
+       if (!(git_work_tree = get_git_work_tree()))
+               git_work_tree = "(null)";
+
+       if (!prefix)
+               prefix = "(null)";
+
        trace_printf("setup: git_dir: %s\n", quote_crnl(get_git_dir()));
-       trace_printf("setup: worktree: %s\n", quote_crnl(get_git_work_tree()));
+       trace_printf("setup: worktree: %s\n", quote_crnl(git_work_tree));
        trace_printf("setup: cwd: %s\n", quote_crnl(cwd));
        trace_printf("setup: prefix: %s\n", quote_crnl(prefix));
 }