xdiff/xhistogram: move index allocation into find_lcs
[gitweb.git] / pkt-line.c
index 08a1427c0d4f6743182b235ec9d9c710c3c99b5b..30489c60b1d3f8acc002fad31aa68b528757c8da 100644 (file)
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "pkt-line.h"
+#include "run-command.h"
 
 char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
@@ -11,6 +12,11 @@ void packet_trace_identity(const char *prog)
        packet_trace_prefix = xstrdup(prog);
 }
 
+static const char *get_trace_prefix(void)
+{
+       return in_async() ? "sideband" : packet_trace_prefix;
+}
+
 static int packet_trace_pack(const char *buf, unsigned int len, int sideband)
 {
        if (!sideband) {
@@ -57,7 +63,7 @@ static void packet_trace(const char *buf, unsigned int len, int write)
        strbuf_init(&out, len+32);
 
        strbuf_addf(&out, "packet: %12s%c ",
-                   packet_trace_prefix, write ? '>' : '<');
+                   get_trace_prefix(), write ? '>' : '<');
 
        /* XXX we should really handle printable utf8 */
        for (i = 0; i < len; i++) {
@@ -166,27 +172,8 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
 
 static int packet_length(const char *linelen)
 {
-       int n;
-       int len = 0;
-
-       for (n = 0; n < 4; n++) {
-               unsigned char c = linelen[n];
-               len <<= 4;
-               if (c >= '0' && c <= '9') {
-                       len += c - '0';
-                       continue;
-               }
-               if (c >= 'a' && c <= 'f') {
-                       len += c - 'a' + 10;
-                       continue;
-               }
-               if (c >= 'A' && c <= 'F') {
-                       len += c - 'A' + 10;
-                       continue;
-               }
-               return -1;
-       }
-       return len;
+       int val = hex2chr(linelen);
+       return (val < 0) ? val : (val << 8) | hex2chr(linelen + 2);
 }
 
 int packet_read(int fd, char **src_buf, size_t *src_len,