@@ -67,6 +67,86 @@ int for_all_bundles_in_list(struct bundle_list *list,
return 0;
}
+/**
+ * Given a key-value pair, update the state of the given bundle list.
+ * Returns 0 if the key-value pair is understood. Returns 1 if the key
+ * is not understood or the value is malformed.
+ */
+MAYBE_UNUSED
+static int bundle_list_update(const char *key, const char *value,
+ struct bundle_list *list)
+{
+ const char *pkey, *dot;
+ struct strbuf id = STRBUF_INIT;
+ struct remote_bundle_info lookup = REMOTE_BUNDLE_INFO_INIT;
+ struct remote_bundle_info *bundle;
+
+ if (!skip_prefix(key, "bundle.", &pkey))
+ return 1;
+
+ if (!strcmp(pkey, "list.version")) {
+ int version = atoi(value);
+ if (version != 1)
+ return 1;
+
+ list->version = version;
+ return 0;
+ }
+
+ if (!strcmp(pkey, "list.mode")) {
+ if (!strcmp(value, "all"))
+ list->mode = BUNDLE_MODE_ALL;
+ else if (!strcmp(value, "any"))
+ list->mode = BUNDLE_MODE_ANY;
+ else
+ return 1;
+ return 0;
+ }
+
+ /*
+ * All remaining keys must be of the form "bundle.<id>.*" where
+ * <id> != "list"
+ */
+
+ dot = strchr(pkey, '.');
+ if (!dot)
+ return 1;
+ if (dot - pkey == 4 &&
+ !strncmp(pkey, "list", 4))
+ return 1;
+
+ strbuf_add(&id, pkey, dot - pkey);
+ dot++;
+
+ /*
+ * Check for an existing bundle with this <id>, or create one
+ * if necessary.
+ */
+ lookup.id = id.buf;
+ hashmap_entry_init(&lookup.ent, strhash(lookup.id));
+ if (!(bundle = hashmap_get_entry(&list->bundles, &lookup, ent, NULL))) {
+ CALLOC_ARRAY(bundle, 1);
+ bundle->id = strbuf_detach(&id, NULL);
+ strbuf_init(&bundle->file, 0);
+ hashmap_entry_init(&bundle->ent, strhash(bundle->id));
+ hashmap_add(&list->bundles, &bundle->ent);
+ }
+ strbuf_release(&id);
+
+ if (!strcmp(dot, "uri")) {
+ free(bundle->uri);
+ bundle->uri = xstrdup(value);
+ return 0;
+ }
+
+ /*
+ * At this point, we ignore any information that we don't
+ * understand, assuming it to be hints for a heuristic the client
+ * does not currently understand.
+ */
+ return 0;
+}
+
static void find_temp_filename(struct strbuf *name)
{
int fd;