Skip to content

Commit 2f60bdd

Browse files
larsxschneidergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 81c634e commit 2f60bdd

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pkt-line.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,20 @@ void packet_buf_flush(struct strbuf *buf)
9797
strbuf_add(buf, "0000", 4);
9898
}
9999

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)
102101
{
103102
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+
{
104114
size_t orig_len, n;
105115

106116
orig_len = out->len;
@@ -111,10 +121,7 @@ static void format_packet(struct strbuf *out, const char *fmt, va_list args)
111121
if (n > LARGE_PACKET_MAX)
112122
die("protocol error: impossibly long line");
113123

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);
118125
packet_trace(out->buf + orig_len + 4, n - 4, 1);
119126
}
120127

0 commit comments

Comments
 (0)