bundle-uri: serve bundle.* keys from config

Implement the "bundle-uri" protocol v2 capability by populating the key=value packet lines from the local Git config. The list of bundles is provided from the keys beginning with "bundle.". In the future, we may want to filter this list to be more specific to the exact known keys that the server intends to share, but for flexibility at the moment we will assume that the config values are well-formed. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Dec 22, 2022 at 15:14 UTC 738dc7d4a5f42376bc748008dd8792aa4eb25627
2 files changed +47 -1
bundle-uri.c
+15 -1
@@ -581,6 +581,16 @@ cached:
581 return advertise_bundle_uri;
582 }
583
584 +static int config_to_packet_line(const char *key, const char *value, void *data)
585 +{
586 + struct packet_reader *writer = data;
587 +
588 + if (!strncmp(key, "bundle.", 7))
589 + packet_write_fmt(writer->fd, "%s=%s", key, value);
590 +
591 + return 0;
592 +}
593 +
594 int bundle_uri_command(struct repository *r,
595 struct packet_reader *request)
596 {
@@ -592,7 +602,11 @@ int bundle_uri_command(struct repository *r,
602 if (request->status != PACKET_READ_FLUSH)
603 die(_("bundle-uri: expected flush after arguments"));
604
595 - /* TODO: Implement the communication */
605 + /*
606 + * Read all "bundle.*" config lines to the client as key=value
607 + * packet lines.
608 + */
609 + git_config(config_to_packet_line, &writer);
610
611 packet_writer_flush(&writer);
612
t/lib-bundle-uri-protocol.sh
+32
@@ -136,6 +136,8 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
136 [bundle]
137 version = 1
138 mode = all
139 + [bundle "only"]
140 + uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED
141 EOF
142
143 test-tool bundle-uri \
@@ -157,6 +159,36 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
159 [bundle]
160 version = 1
161 mode = all
162 + [bundle "only"]
163 + uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED
164 + EOF
165 +
166 + test-tool bundle-uri \
167 + ls-remote \
168 + "$BUNDLE_URI_REPO_URI" \
169 + >actual &&
170 + test_cmp_config_output expect actual
171 +'
172 +
173 +test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2 with list" '
174 + test_config -C "$BUNDLE_URI_PARENT" \
175 + bundle.bundle1.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl" &&
176 + test_config -C "$BUNDLE_URI_PARENT" \
177 + bundle.bundle2.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-2.bdl" &&
178 + test_config -C "$BUNDLE_URI_PARENT" \
179 + bundle.bundle3.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-3.bdl" &&
180 +
181 + # All data about bundle URIs
182 + cat >expect <<-EOF &&
183 + [bundle]
184 + version = 1
185 + mode = all
186 + [bundle "bundle1"]
187 + uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl
188 + [bundle "bundle2"]
189 + uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-2.bdl
190 + [bundle "bundle3"]
191 + uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-3.bdl
192 EOF
193
194 test-tool bundle-uri \