Skip to content

Commit 52d2ae5

Browse files
committed
receive-pack: factor out capability string generation
Similar to the previous one for send-pack, make it easier and cleaner to add to capability advertisement. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 887f353 commit 52d2ae5

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

builtin/receive-pack.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,21 @@ static void show_ref(const char *path, const unsigned char *sha1)
137137
if (ref_is_hidden(path))
138138
return;
139139

140-
if (sent_capabilities)
140+
if (sent_capabilities) {
141141
packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
142-
else
143-
packet_write(1, "%s %s%c%s%s agent=%s\n",
144-
sha1_to_hex(sha1), path, 0,
145-
" report-status delete-refs side-band-64k quiet",
146-
prefer_ofs_delta ? " ofs-delta" : "",
147-
git_user_agent_sanitized());
148-
sent_capabilities = 1;
142+
} else {
143+
struct strbuf cap = STRBUF_INIT;
144+
145+
strbuf_addstr(&cap,
146+
"report-status delete-refs side-band-64k quiet");
147+
if (prefer_ofs_delta)
148+
strbuf_addstr(&cap, " ofs-delta");
149+
strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
150+
packet_write(1, "%s %s%c%s\n",
151+
sha1_to_hex(sha1), path, 0, cap.buf);
152+
strbuf_release(&cap);
153+
sent_capabilities = 1;
154+
}
149155
}
150156

151157
static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused)

0 commit comments

Comments
 (0)