]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bundle-uri: serve bundle.* keys from config
authorDerrick Stolee <derrickstolee@github.com>
Thu, 22 Dec 2022 15:14:13 +0000 (15:14 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 25 Dec 2022 07:24:24 +0000 (16:24 +0900)
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>
bundle-uri.c
t/lib-bundle-uri-protocol.sh

index 28d8966005e45d5b9784ead844fb1fe5478d9579..26ff4b062d72bb15dac40897f7d247f9ca4a7272 100644 (file)
@@ -581,6 +581,16 @@ cached:
        return advertise_bundle_uri;
 }
 
+static int config_to_packet_line(const char *key, const char *value, void *data)
+{
+       struct packet_reader *writer = data;
+
+       if (!strncmp(key, "bundle.", 7))
+               packet_write_fmt(writer->fd, "%s=%s", key, value);
+
+       return 0;
+}
+
 int bundle_uri_command(struct repository *r,
                       struct packet_reader *request)
 {
@@ -592,7 +602,11 @@ int bundle_uri_command(struct repository *r,
        if (request->status != PACKET_READ_FLUSH)
                die(_("bundle-uri: expected flush after arguments"));
 
-       /* TODO: Implement the communication */
+       /*
+        * Read all "bundle.*" config lines to the client as key=value
+        * packet lines.
+        */
+       git_config(config_to_packet_line, &writer);
 
        packet_writer_flush(&writer);
 
index 5620e230387c23ebc21a9ceebd70ff9b2cae7f28..3022ea4a95b782a85c03650009dff8e343664274 100644 (file)
@@ -136,6 +136,8 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
        [bundle]
                version = 1
                mode = all
+       [bundle "only"]
+               uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED
        EOF
 
        test-tool bundle-uri \
@@ -157,6 +159,36 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
        [bundle]
                version = 1
                mode = all
+       [bundle "only"]
+               uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED
+       EOF
+
+       test-tool bundle-uri \
+               ls-remote \
+               "$BUNDLE_URI_REPO_URI" \
+               >actual &&
+       test_cmp_config_output expect actual
+'
+
+test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2 with list" '
+       test_config -C "$BUNDLE_URI_PARENT" \
+               bundle.bundle1.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl" &&
+       test_config -C "$BUNDLE_URI_PARENT" \
+               bundle.bundle2.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-2.bdl" &&
+       test_config -C "$BUNDLE_URI_PARENT" \
+               bundle.bundle3.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-3.bdl" &&
+
+       # All data about bundle URIs
+       cat >expect <<-EOF &&
+       [bundle]
+               version = 1
+               mode = all
+       [bundle "bundle1"]
+               uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl
+       [bundle "bundle2"]
+               uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-2.bdl
+       [bundle "bundle3"]
+               uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-3.bdl
        EOF
 
        test-tool bundle-uri \