pkt-line: extract set_packet_header()
Extracted set_packet_header() function converts an integer to a 4 byte hex string. Make this function locally available so that other pkt-line functions could use it. Signed-off-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Schneider committed
Oct 16, 2016 at 16:20 UTC
2f60bdd1a83f14ceee75da309974b0401fa5b019
1 file changed
+13
-6
pkt-line.c
+13
-6
@@ -97,10 +97,20 @@ void packet_buf_flush(struct strbuf *buf)
97
strbuf_add(buf, "0000", 4);
98
}
99
100
-#define hex(a) (hexchar[(a) & 15])
101
-static void format_packet(struct strbuf *out, const char *fmt, va_list args)
100
+static void set_packet_header(char *buf, const int size)
101
{
102
static char hexchar[] = "0123456789abcdef";
103
+
104
+ #define hex(a) (hexchar[(a) & 15])
105
+ buf[0] = hex(size >> 12);
106
+ buf[1] = hex(size >> 8);
107
+ buf[2] = hex(size >> 4);
108
+ buf[3] = hex(size);
109
+ #undef hex
110
+}
111
+
112
+static void format_packet(struct strbuf *out, const char *fmt, va_list args)
113
+{
114
size_t orig_len, n;
115
116
orig_len = out->len;
@@ -111,10 +121,7 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
121
if (n > LARGE_PACKET_MAX)
122
die("protocol error: impossibly long line");
123
114
- out->buf[orig_len + 0] = hex(n >> 12);
115
- out->buf[orig_len + 1] = hex(n >> 8);
116
- out->buf[orig_len + 2] = hex(n >> 4);
117
- out->buf[orig_len + 3] = hex(n);
124
+ set_packet_header(&out->buf[orig_len], n);
125
packet_trace(out->buf + orig_len + 4, n - 4, 1);
126
}
127