Skip to content

Commit 738dc7d

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 70b9c10 commit 738dc7d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

bundle-uri.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,16 @@ int bundle_uri_advertise(struct repository *r, struct strbuf *value UNUSED)
581581
return advertise_bundle_uri;
582582
}
583583

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+
584594
int bundle_uri_command(struct repository *r,
585595
struct packet_reader *request)
586596
{
@@ -592,7 +602,11 @@ int bundle_uri_command(struct repository *r,
592602
if (request->status != PACKET_READ_FLUSH)
593603
die(_("bundle-uri: expected flush after arguments"));
594604

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);
596610

597611
packet_writer_flush(&writer);
598612

t/lib-bundle-uri-protocol.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
136136
[bundle]
137137
version = 1
138138
mode = all
139+
[bundle "only"]
140+
uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED
139141
EOF
140142
141143
test-tool bundle-uri \
@@ -157,6 +159,36 @@ test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol
157159
[bundle]
158160
version = 1
159161
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
160192
EOF
161193
162194
test-tool bundle-uri \

0 commit comments

Comments
 (0)