From: Derrick Stolee <derrickstolee@xxxxxxxxxx> The 'features' capability sends a list of "key=value" pairs from the server. These are a set of fixed config values, all prefixed with "serve." to avoid conflicting with other config values of similar names. The initial set chosen here are: * bundleURI: Allow advertising one or more bundle servers by URI. * partialCloneFilter: Advertise one or more recommended partial clone filters. * sparseCheckout: Advertise that this repository recommends using the sparse-checkout feature in cone mode. The client will have the choice to enable these features. RFC-TODO: Create Documentation/config/serve.txt Signed-off-by: Derrick Stolee <derrickstolee@xxxxxxxxxx> --- protocol-caps.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ protocol-caps.h | 1 + 2 files changed, 67 insertions(+) diff --git a/protocol-caps.c b/protocol-caps.c index bbde91810ac..88b01c4133e 100644 --- a/protocol-caps.c +++ b/protocol-caps.c @@ -8,6 +8,7 @@ #include "object-store.h" #include "string-list.h" #include "strbuf.h" +#include "config.h" struct requested_info { unsigned size : 1; @@ -111,3 +112,68 @@ int cap_object_info(struct repository *r, struct packet_reader *request) return 0; } + +static void send_lines(struct repository *r, struct packet_writer *writer, + struct string_list *str_list) +{ + struct string_list_item *item; + + if (!str_list->nr) + return; + + for_each_string_list_item (item, str_list) { + packet_writer_write(writer, "%s", item->string); + } +} + +int cap_features(struct repository *r, struct packet_reader *request) +{ + struct packet_writer writer; + struct string_list feature_list = STRING_LIST_INIT_DUP; + int i = 0; + const char *keys[] = { + "bundleuri", + "partialclonefilter", + "sparsecheckout", + NULL + }; + struct strbuf serve_feature = STRBUF_INIT; + struct strbuf key_equals_value = STRBUF_INIT; + size_t len; + strbuf_add(&serve_feature, "serve.", 6); + len = serve_feature.len; + + packet_writer_init(&writer, 1); + + while (keys[i]) { + struct string_list_item *item; + const struct string_list *values = NULL; + strbuf_setlen(&serve_feature, len); + strbuf_addstr(&serve_feature, keys[i]); + + values = repo_config_get_value_multi(r, serve_feature.buf); + + if (values) { + for_each_string_list_item(item, values) { + strbuf_reset(&key_equals_value); + strbuf_addstr(&key_equals_value, keys[i]); + strbuf_addch(&key_equals_value, '='); + strbuf_addstr(&key_equals_value, item->string); + + string_list_append(&feature_list, key_equals_value.buf); + } + } + + i++; + } + strbuf_release(&serve_feature); + strbuf_release(&key_equals_value); + + send_lines(r, &writer, &feature_list); + + string_list_clear(&feature_list, 1); + + packet_flush(1); + + return 0; +} diff --git a/protocol-caps.h b/protocol-caps.h index 15c4550360c..681d2106d88 100644 --- a/protocol-caps.h +++ b/protocol-caps.h @@ -4,5 +4,6 @@ struct repository; struct packet_reader; int cap_object_info(struct repository *r, struct packet_reader *request); +int cap_features(struct repository *r, struct packet_reader *request); #endif /* PROTOCOL_CAPS_H */ -- 2.36.0.rc2.902.g60576bbc845