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 <gitster@pobox.com>

Junio C Hamano committed Sep 4, 2014 at 12:13 UTC 52d2ae582e84c6d4ace8ab7e021808915148816a
1 file changed +14 -8
builtin/receive-pack.c
+14 -8
@@ -137,15 +137,21 @@ static void show_ref(const char *path, const unsigned char *sha1)
137 if (ref_is_hidden(path))
138 return;
139
140 - if (sent_capabilities)
140 + if (sent_capabilities) {
141 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 + }
155 }
156
157 static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused)