static void packet_trace(const char *buf, unsigned int len, int write) { int i; struct strbuf out; static int in_pack, sideband; if (!trace_want(&trace_packet) && !trace_want(&trace_pack)) return; if (in_pack) { if (packet_trace_pack(buf, len, sideband)) return; } else if (starts_with(buf, "PACK") || starts_with(buf, "\1PACK")) { in_pack = 1; sideband = *buf == '\1'; packet_trace_pack(buf, len, sideband); /* * Make a note in the human-readable trace that the pack data * started. */ buf = "PACK ..."; len = strlen(buf); } if (!trace_want(&trace_packet)) return; /* +32 is just a guess for header + quoting */ strbuf_init(&out, len+32); strbuf_addf(&out, "packet: %12s%c ", get_trace_prefix(), write ? '>' : '<'); /* XXX we should really handle printable utf8 */ for (i = 0; i < len; i++) { /* suppress newlines */ if (buf[i] == '\n') continue; if (buf[i] >= 0x20 && buf[i] <= 0x7e) strbuf_addch(&out, buf[i]); else strbuf_addf(&out, "\\%o", buf[i]); } strbuf_addch(&out, '\n'); trace_strbuf(&trace_packet, &out); strbuf_release(&out); }
static void trace_vprintf(const char *key, const char *fmt, va_list ap) { struct strbuf buf = STRBUF_INIT; if (!trace_want(key)) return; set_try_to_free_routine(NULL); /* is never reset */ strbuf_vaddf(&buf, fmt, ap); trace_strbuf(key, &buf); strbuf_release(&buf); }
/* FIXME: move prefix to startup_info struct and get rid of this arg */ void trace_repo_setup(const char *prefix) { static const char *key = "GIT_TRACE_SETUP"; const char *git_work_tree; char cwd[PATH_MAX]; if (!trace_want(key)) return; 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_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)); }
static void packet_trace(const char *buf, unsigned int len, int write) { int i; struct strbuf out; if (!trace_want(trace_key)) return; /* +32 is just a guess for header + quoting */ strbuf_init(&out, len+32); strbuf_addf(&out, "packet: %12s%c ", packet_trace_prefix, write ? '>' : '<'); if ((len >= 4 && !prefixcmp(buf, "PACK")) || (len >= 5 && !prefixcmp(buf+1, "PACK"))) { strbuf_addstr(&out, "PACK ..."); unsetenv(trace_key); } else { /* XXX we should really handle printable utf8 */ for (i = 0; i < len; i++) { /* suppress newlines */ if (buf[i] == '\n') continue; if (buf[i] >= 0x20 && buf[i] <= 0x7e) strbuf_addch(&out, buf[i]); else strbuf_addf(&out, "\\%o", buf[i]); } } strbuf_addch(&out, '\n'); trace_strbuf(trace_key, &out); strbuf_release(&out); }