@matheusbsbs / matheus-bagliano / commits / 185c04e041
Fork 0

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 <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Feb 5, 2010 at 12:57 UTC 185c04e041fb33191c5828339381fd8c4058a43a
1 file changed +8 -10
builtin-receive-pack.c
+8 -10
@@ -31,7 +31,7 @@ static int prefer_ofs_delta = 1;
31 static int auto_update_server_info;
32 static int auto_gc = 1;
33 static const char *head_name;
34 -static char *capabilities_to_send;
34 +static int sent_capabilities;
35
36 static enum deny_action parse_deny_action(const char *var, const char *value)
37 {
@@ -105,19 +105,21 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
105
106 static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
107 {
108 - if (!capabilities_to_send)
108 + if (sent_capabilities)
109 packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
110 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;
116 return 0;
117 }
118
119 static void write_head_info(void)
120 {
121 for_each_ref(show_ref, NULL);
120 - if (capabilities_to_send)
122 + if (!sent_capabilities)
123 show_ref("capabilities^{}", null_sha1, 0, NULL);
124
125 }
@@ -670,10 +672,6 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
672 else if (0 <= receive_unpack_limit)
673 unpack_limit = receive_unpack_limit;
674
673 - capabilities_to_send = (prefer_ofs_delta) ?
674 - " report-status delete-refs ofs-delta " :
675 - " report-status delete-refs ";
676 -
675 if (advertise_refs || !stateless_rpc) {
676 add_alternate_refs();
677 write_head_info();