"Derrick Stolee via GitGitGadget" <gitgitgadget@xxxxxxxxx> writes: > +/** > + * 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; > + > + dot = strchr(pkey, '.'); > + if (!dot) { > + if (!strcmp(pkey, "version")) { > + int version = atoi(value); > + if (version != 1) > + return 1; > + > + list->version = version; > + return 0; > + } > + > + if (!strcmp(pkey, "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; > + } Drive-by comment from Review Club: we could simplify "section.[subsection.]key" parsing using parse_config_key(). There are other places in the code that do custom parsing like this, but maybe they should use parse_config_key() too. > + > + /* Ignore other unknown global keys. */ > + return 0; > + } > + > + 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 int find_temp_filename(struct strbuf *name) > { > int fd; > -- > gitgitgadget