git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 21/24] bundle-uri: allow relative URLs in bundle lists

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
May 20, 2022, 18:40 UTC
Message-ID
<be9b139db9113f5653ceaed9b5c35c236cf70a78.1653072042.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1234.git.1653072042.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>

Bundle providers may want to distribute that data across multiple CDNs. This might require a change in the base URI, all the way to the domain name. If all bundles require an absolute URI in their 'uri' value, then every push to a CDN would require altering the table of contents to match the expected domain and exact location within it.

Allow a bundle list to specify a relative URI for the bundles. This allows easier distribution of bundle data.

Signed-off-by: Derrick Stolee <derrickstolee@github.com>
---
 bundle-uri.c                |  6 ++++-
 bundle-uri.h                |  9 +++++++
 t/helper/test-bundle-uri.c  |  2 ++
 t/t5750-bundle-uri-parse.sh | 54 +++++++++++++++++++++++++++++++++++++
 transport.c                 |  3 +++
 5 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/bundle-uri.c b/bundle-uri.c
index 70be53aa38d..9e7dc0fb4ca 100644
--- a/bundle-uri.c
+++ b/bundle-uri.c
@@ -7,6 +7,7 @@
 #include "run-command.h"
 #include "hashmap.h"
 #include "pkt-line.h"
+#include "remote.h"
 
 static int compare_bundles(const void *hashmap_cmp_fn_data,
 			   const struct hashmap_entry *he1,
@@ -49,6 +50,7 @@ void clear_bundle_list(struct bundle_list *list)
 
 	for_all_bundles_in_list(list, clear_remote_bundle_info, NULL);
 	hashmap_clear_and_free(&list->bundles, struct remote_bundle_info, ent);
+	free(list->baseURI);
 }
 
 int for_all_bundles_in_list(struct bundle_list *list,
@@ -169,7 +171,7 @@ static int bundle_list_update(const char *key, const char *value,
 
 	if (!strcmp(dot, "uri")) {
 		free(bundle->uri);
-		bundle->uri = xstrdup(value);
+		bundle->uri = relative_url(list->baseURI, value, NULL);
 		return 0;
 	}
 
@@ -197,6 +199,8 @@ int parse_bundle_list_in_config_format(const char *uri,
 	};
 
 	list->mode = BUNDLE_MODE_NONE;
+	if (!list->baseURI)
+		list->baseURI = xstrdup(uri);
 	result = git_config_from_file_with_options(config_to_bundle_list,
 						   filename, list,
 						   &opts);
diff --git a/bundle-uri.h b/bundle-uri.h
index 9f6fc2d75f9..fdcaea048a8 100644
--- a/bundle-uri.h
+++ b/bundle-uri.h
@@ -65,6 +65,15 @@ struct bundle_list {
 	enum bundle_list_mode mode;
 	unsigned forFetch : 1;
 	struct hashmap bundles;
+
+	/**
+	 * The baseURI of a bundle_list is used as the base for any
+	 * relative URIs advertised by the bundle list at that location.
+	 *
+	 * When the list is generated from a Git server, then use that
+	 * server's location.
+	 */
+	char *baseURI;
 };
 
 void init_bundle_list(struct bundle_list *list);
diff --git a/t/helper/test-bundle-uri.c b/t/helper/test-bundle-uri.c
index 23ce0eebca3..b535dc47134 100644
--- a/t/helper/test-bundle-uri.c
+++ b/t/helper/test-bundle-uri.c
@@ -35,6 +35,8 @@ static int cmd__bundle_uri_parse(int argc, const char **argv, enum input_mode mo
 
 	init_bundle_list(&list);
 
+	list.baseURI = xstrdup("<uri>");
+
 	switch (mode) {
 	case KEY_VALUE_PAIRS:
 		if (argc)
diff --git a/t/t5750-bundle-uri-parse.sh b/t/t5750-bundle-uri-parse.sh
index c2b7a8ce968..ea279c2b762 100755
--- a/t/t5750-bundle-uri-parse.sh
+++ b/t/t5750-bundle-uri-parse.sh
@@ -30,6 +30,30 @@ test_expect_success 'bundle_uri_parse_line() just URIs' '
 	test_cmp_config_output expect actual
 '
 
+test_expect_success 'bundle_uri_parse_line(): relative URIs' '
+	cat >in <<-\EOF &&
+	bundle.one.uri=bundle.bdl
+	bundle.two.uri=../bundle.bdl
+	bundle.three.uri=sub/dir/bundle.bdl
+	EOF
+
+	cat >expect <<-\EOF &&
+	[bundle "list"]
+		version = 1
+		mode = all
+	[bundle "one"]
+		uri = <uri>/bundle.bdl
+	[bundle "two"]
+		uri = bundle.bdl
+	[bundle "three"]
+		uri = <uri>/sub/dir/bundle.bdl
+	EOF
+
+	test-tool bundle-uri parse-key-values <in >actual 2>err &&
+	test_must_be_empty err &&
+	test_cmp_config_output expect actual
+'
+
 test_expect_success 'bundle_uri_parse_line() parsing edge cases: empty key or value' '
 	cat >in <<-\EOF &&
 	=bogus-value
@@ -106,6 +130,36 @@ test_expect_success 'parse config format: just URIs' '
 	test_cmp_config_output expect actual
 '
 
+test_expect_success 'parse config format: relative URIs' '
+	cat >in <<-\EOF &&
+	[bundle "list"]
+		version = 1
+		mode = all
+	[bundle "one"]
+		uri = bundle.bdl
+	[bundle "two"]
+		uri = ../bundle.bdl
+	[bundle "three"]
+		uri = sub/dir/bundle.bdl
+	EOF
+
+	cat >expect <<-\EOF &&
+	[bundle "list"]
+		version = 1
+		mode = all
+	[bundle "one"]
+		uri = <uri>/bundle.bdl
+	[bundle "two"]
+		uri = bundle.bdl
+	[bundle "three"]
+		uri = <uri>/sub/dir/bundle.bdl
+	EOF
+
+	test-tool bundle-uri parse-config in >actual 2>err &&
+	test_must_be_empty err &&
+	test_cmp_config_output expect actual
+'
+
 test_expect_success 'parse config format edge cases: empty key or value' '
 	cat >in1 <<-\EOF &&
 	= bogus-value
diff --git a/transport.c b/transport.c
index f0114778ff4..52b99cd3298 100644
--- a/transport.c
+++ b/transport.c
@@ -1544,6 +1544,9 @@ int transport_get_remote_bundle_uri(struct transport *transport, int quiet)
 	    (git_config_get_bool("transfer.bundleuri", &value) || !value))
 		return 0;
 
+	if (!transport->bundles->baseURI)
+		transport->bundles->baseURI = xstrdup(transport->url);
+
 	if (!vtable->get_bundle_uri) {
 		if (quiet)
 			return -1;
-- 
gitgitgadget
Previous: Ævar Arnfjörð Bjarmason via GitGitGadgetNext: Derrick Stolee via GitGitGadget
Message 24 of 25 in “[RFC] Bundle URIs Combined RFC”
  1. 00/24 [RFC] Bundle URIs Combined RFCDerrick Stolee via GitGitGadget, May 20, 2022
  2. 01/24 docs: document bundle URI standardDerrick Stolee via GitGitGadget, May 20, 2022
  3. 02/24 remote-curl: add 'get' capabilityDerrick Stolee via GitGitGadget, May 20, 2022
  4. 06/24 fetch: add 'refs/bundle/' to log.excludeDecorationDerrick Stolee via GitGitGadget, May 20, 2022
  5. 05/24 fetch: add --bundle-uri optionDerrick Stolee via GitGitGadget, May 20, 2022
  6. 04/24 bundle-uri: add support for http(s):// and file://Derrick Stolee via GitGitGadget, May 20, 2022
  7. 03/24 bundle-uri: create basic file-copy logicDerrick Stolee via GitGitGadget, May 20, 2022
  8. 12/24 bundle-uri: unit test "key=value" parsingÆvar Arnfjörð Bjarmason via GitGitGadget, May 20, 2022
  9. 10/24 bundle-uri: create base key-value pair parsingDerrick Stolee via GitGitGadget, May 20, 2022
  10. 07/24 clone: add --bundle-uri optionDerrick Stolee via GitGitGadget, May 20, 2022
  11. 11/24 bundle-uri: create "key=value" line parsingÆvar Arnfjörð Bjarmason via GitGitGadget, May 20, 2022
  12. 14/24 bundle-uri: parse bundle list in config formatDerrick Stolee via GitGitGadget, May 20, 2022
  13. 09/24 bundle-uri: create bundle_list struct and helpersDerrick Stolee via GitGitGadget, May 20, 2022
  14. 15/24 bundle-uri: fetch a list of bundlesDerrick Stolee via GitGitGadget, May 20, 2022
  15. 16/24 protocol v2: add server-side "bundle-uri" skeletonÆvar Arnfjörð Bjarmason via GitGitGadget, May 20, 2022
  16. 08/24 clone: --bundle-uri cannot be combined with --depthDerrick Stolee via GitGitGadget, May 20, 2022
  17. 13/24 bundle-uri: limit recursion depth for bundle listsDerrick Stolee via GitGitGadget, May 20, 2022
  18. 18/24 bundle-uri client: add "git ls-remote-bundle-uri"Ævar Arnfjörð Bjarmason via GitGitGadget, May 20, 2022
  19. 17/24 bundle-uri client: add minimal NOOP clientÆvar Arnfjörð Bjarmason via GitGitGadget, May 20, 2022
  20. 19/24 bundle-uri: serve URI advertisement from bundle.* configDerrick Stolee via GitGitGadget, May 20, 2022
  21. 22/24 bundle-uri: download bundles from an advertised listDerrick Stolee via GitGitGadget, May 20, 2022
  22. 24/24 t5601: basic bundle URI testsDerrick Stolee via GitGitGadget, May 20, 2022
  23. 20/24 bundle-uri client: add boolean transfer.bundleURI settingÆvar Arnfjörð Bjarmason via GitGitGadget, May 20, 2022
  24. 21/24 bundle-uri: allow relative URLs in bundle listsDerrick Stolee via GitGitGadget, May 20, 2022
  25. 23/24 clone: unbundle the advertised bundlesDerrick Stolee via GitGitGadget, May 20, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.