From 1dbc08952d2b934e4ff4e15cfb9c6adca0f53501 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Fri, 23 Jan 2026 11:35:05 -0500 Subject: [PATCH] scalar: add ---cache-server-url options In #836, we implemented custom gvfs..cache-server config options that allow existing enlistments to point specific GVFS Protocol verbs at different cache servers. However, that did not help at clone time. This change adds ---cache-server-url options to 'scalar clone' to allow initial clones to take advantage of different cache servers. The intended use here is to take advantage of new cache server infrastructure as each protocol endpoint is deployed independently. Signed-off-by: Derrick Stolee --- Documentation/scalar.adoc | 9 +++++++-- scalar.c | 40 +++++++++++++++++++++++++++++++++++++- t/t9210-scalar.sh | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/Documentation/scalar.adoc b/Documentation/scalar.adoc index 809947f250d846..fc560824c567cf 100644 --- a/Documentation/scalar.adoc +++ b/Documentation/scalar.adoc @@ -10,8 +10,8 @@ SYNOPSIS [verse] scalar clone [--single-branch] [--branch ] [--full-clone] [--[no-]src] [--[no-]tags] [--[no-]maintenance] - [--[no-]src] [--local-cache-path ] [--cache-server-url ] - [] + [--cache-server-url ] [--[verb]-cache-server-url ] + [--local-cache-path ] [] scalar list scalar register [--[no-]maintenance] [] scalar unregister [] @@ -121,6 +121,11 @@ clone), and `~/.scalarCache` on macOS. Retrieve missing objects from the specified remote, which is expected to understand the GVFS protocol. +--[verb]-cache-server-url :: + Set the appropriate `gvfs..cache-server` config value that overrides + the provided `--cache-server-url` or the dynamically discovered URL. The + list of allowed verbs is `prefetch`, `get`, and `post`. + --gvfs-protocol:: --no-gvfs-protocol:: When cloning from a `` with either `dev.azure.com` or diff --git a/scalar.c b/scalar.c index 421e23cf1b50ce..59b5ad740db4e5 100644 --- a/scalar.c +++ b/scalar.c @@ -773,6 +773,7 @@ static int cmd_clone(int argc, const char **argv) int src = 1, tags = 1, maintenance = 1; const char *cache_server_url = NULL, *local_cache_root = NULL; char *default_cache_server_url = NULL, *local_cache_root_abs = NULL; + const char *prefetch_server = NULL, *get_server = NULL, *post_server = NULL; int gvfs_protocol = -1; const char *ref_format = NULL; @@ -795,6 +796,15 @@ static int cmd_clone(int argc, const char **argv) OPT_STRING(0, "cache-server-url", &cache_server_url, N_(""), N_("the url or friendly name of the cache server")), + OPT_STRING(0, "prefetch-cache-server-url", &prefetch_server, + N_(""), + N_("the url or friendly name of a cache server for the prefetch endpoint")), + OPT_STRING(0, "get-cache-server-url", &get_server, + N_(""), + N_("the url or friendly name of a cache server for the objects GET endpoint")), + OPT_STRING(0, "post-cache-server-url", &post_server, + N_(""), + N_("the url or friendly name of a cache server for the objects POST endpoint")), OPT_STRING(0, "local-cache-path", &local_cache_root, N_(""), N_("override the path for the local Scalar cache")), @@ -807,7 +817,8 @@ static int cmd_clone(int argc, const char **argv) const char * const clone_usage[] = { N_("scalar clone [--single-branch] [--branch ] [--full-clone]\n" "\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] [--ref-format ]\n" - "\t []"), + "\t[--cache-server-url ] [--[verb]-cache-server-url ]\n" + "\t[--local-cache-path ] []"), NULL }; const char *url; @@ -969,6 +980,33 @@ static int cmd_clone(int argc, const char **argv) if (cache_server_url) fprintf(stderr, "Cache server URL: %s\n", cache_server_url); + + if (prefetch_server && + set_config("gvfs.prefetch.cache-server=%s", prefetch_server)) { + res = error(_("could not configure prefetch cache server")); + goto cleanup; + } + if (prefetch_server) + fprintf(stderr, "Prefetch cache server URL: %s\n", + prefetch_server); + + if (get_server && + set_config("gvfs.get.cache-server=%s", get_server)) { + res = error(_("could not configure objects GET cache server")); + goto cleanup; + } + if (get_server) + fprintf(stderr, "Objects GET cache server URL: %s\n", + get_server); + + if (post_server && + set_config("gvfs.post.cache-server=%s", post_server)) { + res = error(_("could not configure objects POST cache server")); + goto cleanup; + } + if (post_server) + fprintf(stderr, "Objects POST cache server URL: %s\n", + post_server); } else { if (set_config("core.useGVFSHelper=false") || set_config("remote.origin.promisor=true") || diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index 4a22150eefcdc2..9edb57378aa5bd 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -448,6 +448,47 @@ test_expect_success '`scalar clone` with GVFS-enabled server' ' ) ' +. "$TEST_DIRECTORY"/lib-gvfs-helper.sh + +test_expect_success 'scalar clone: all verbs with different servers' ' + git config --global core.askPass true && + + test_when_finished "per_test_cleanup" && + test_when_finished "scalar delete scalar-clone" && + + start_gvfs_protocol_server 1 && + start_gvfs_protocol_server 2 && + start_gvfs_protocol_server 3 && + + # Configure each verb to use a different server: + # - server 0: default (unused in this test; not running.) + # - server 1: prefetch + # - server 2: get + # - server 3: post + scalar -c credential.interactive=true \ + clone --full-clone \ + --cache-server-url="$(cache_server_url 0)" \ + --prefetch-cache-server-url="$(cache_server_url 1)" \ + --get-cache-server-url="$(cache_server_url 2)" \ + --post-cache-server-url="$(cache_server_url 3)" \ + --gvfs-protocol \ + -- "http://$HOST_PORT/" scalar-clone 2>err >out && + + test_grep "Cache server URL: $(cache_server_url 0)" err && + test_grep "Prefetch cache server URL: $(cache_server_url 1)" err && + test_grep "Objects GET cache server URL: $(cache_server_url 2)" err && + test_grep "Objects POST cache server URL: $(cache_server_url 3)" err && + + test_cmp_config -C scalar-clone/src "$(cache_server_url 0)" gvfs.cache-server && + test_cmp_config -C scalar-clone/src "$(cache_server_url 1)" gvfs.prefetch.cache-server && + test_cmp_config -C scalar-clone/src "$(cache_server_url 2)" gvfs.get.cache-server && + test_cmp_config -C scalar-clone/src "$(cache_server_url 3)" gvfs.post.cache-server && + + verify_server_was_contacted 1 && + verify_server_was_contacted 2 && + verify_server_was_contacted 3 +' + test_expect_success 'fetch does not hang in gvfs-helper' ' test_must_fail git -C using-gvfs/src fetch origin does-not-exist '