Skip to content

Commit 185c04e

Browse files
spearcegitster
authored andcommitted
receive-pack: Refactor how capabilities are shown to the client
Moving capability advertisement into the packet_write call itself makes it easier to add additional capabilities to the list, be it optional by configuration, or always present in the protocol. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0c499ea commit 185c04e

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

builtin-receive-pack.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int prefer_ofs_delta = 1;
3131
static int auto_update_server_info;
3232
static int auto_gc = 1;
3333
static const char *head_name;
34-
static char *capabilities_to_send;
34+
static int sent_capabilities;
3535

3636
static enum deny_action parse_deny_action(const char *var, const char *value)
3737
{
@@ -105,19 +105,21 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
105105

106106
static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
107107
{
108-
if (!capabilities_to_send)
108+
if (sent_capabilities)
109109
packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
110110
else
111-
packet_write(1, "%s %s%c%s\n",
112-
sha1_to_hex(sha1), path, 0, capabilities_to_send);
113-
capabilities_to_send = NULL;
111+
packet_write(1, "%s %s%c%s%s\n",
112+
sha1_to_hex(sha1), path, 0,
113+
" report-status delete-refs",
114+
prefer_ofs_delta ? " ofs-delta" : "");
115+
sent_capabilities = 1;
114116
return 0;
115117
}
116118

117119
static void write_head_info(void)
118120
{
119121
for_each_ref(show_ref, NULL);
120-
if (capabilities_to_send)
122+
if (!sent_capabilities)
121123
show_ref("capabilities^{}", null_sha1, 0, NULL);
122124

123125
}
@@ -670,10 +672,6 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
670672
else if (0 <= receive_unpack_limit)
671673
unpack_limit = receive_unpack_limit;
672674

673-
capabilities_to_send = (prefer_ofs_delta) ?
674-
" report-status delete-refs ofs-delta " :
675-
" report-status delete-refs ";
676-
677675
if (advertise_refs || !stateless_rpc) {
678676
add_alternate_refs();
679677
write_head_info();

0 commit comments

Comments
 (0)