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); }
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 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); }