| 38 | } |
| 39 | |
| 40 | static void packet_trace(const char *buf, unsigned int len, int write) |
| 41 | { |
| 42 | struct strbuf out; |
| 43 | static int in_pack, sideband; |
| 44 | |
| 45 | if (!trace_want(&trace_packet) && !trace_want(&trace_pack)) |
| 46 | return; |
| 47 | |
| 48 | if (in_pack) { |
| 49 | if (packet_trace_pack(buf, len, sideband)) |
| 50 | return; |
| 51 | } else if (starts_with(buf, "PACK") || starts_with(buf, "\1PACK")) { |
| 52 | in_pack = 1; |
| 53 | sideband = *buf == '\1'; |
| 54 | packet_trace_pack(buf, len, sideband); |
| 55 | |
| 56 | /* |
| 57 | * Make a note in the human-readable trace that the pack data |
| 58 | * started. |
| 59 | */ |
| 60 | buf = "PACK ..."; |
| 61 | len = strlen(buf); |
| 62 | } |
| 63 | |
| 64 | if (!trace_want(&trace_packet)) |
| 65 | return; |
| 66 | |
| 67 | /* +32 is just a guess for header + quoting */ |
| 68 | strbuf_init(&out, len+32); |
| 69 | |
| 70 | strbuf_addf(&out, "packet: %12s%c ", |
| 71 | get_trace_prefix(), write ? '>' : '<'); |
| 72 | |
| 73 | /* XXX we should really handle printable utf8 */ |
| 74 | for (unsigned int i = 0; i < len; i++) { |
| 75 | /* suppress newlines */ |
| 76 | if (buf[i] == '\n') |
| 77 | continue; |
| 78 | if (buf[i] >= 0x20 && buf[i] <= 0x7e) |
| 79 | strbuf_addch(&out, buf[i]); |
| 80 | else |
| 81 | strbuf_addf(&out, "\\%o", buf[i]); |
| 82 | } |
| 83 | |
| 84 | strbuf_addch(&out, '\n'); |
| 85 | trace_strbuf(&trace_packet, &out); |
| 86 | strbuf_release(&out); |
| 87 | } |
| 88 | |
| 89 | /* |
| 90 | * If we buffered things up above (we don't, but we should), |
no test coverage detected