Skip to content

Commit 63f25a0

Browse files
committed
scalar: add --<verb>-cache-server-url options
In #836, we implemented custom gvfs.<verb>.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 --<verb>-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 <stolee@gmail.com>
1 parent 82d60a0 commit 63f25a0

3 files changed

Lines changed: 87 additions & 3 deletions

File tree

Documentation/scalar.adoc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ SYNOPSIS
1010
[verse]
1111
scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]
1212
[--[no-]src] [--[no-]tags] [--[no-]maintenance]
13-
[--[no-]src] [--local-cache-path <path>] [--cache-server-url <url>]
14-
<url> [<enlistment>]
13+
[--cache-server-url <url>] [--[verb]-cache-server-url <url>]
14+
[--local-cache-path <path>] <url> [<enlistment>]
1515
scalar list
1616
scalar register [--[no-]maintenance] [<enlistment>]
1717
scalar unregister [<enlistment>]
@@ -121,6 +121,11 @@ clone), and `~/.scalarCache` on macOS.
121121
Retrieve missing objects from the specified remote, which is expected to
122122
understand the GVFS protocol.
123123

124+
--[verb]-cache-server-url <url>::
125+
Set the appropriate `gvfs.<verb>.cache-server` config value that overrides
126+
the provided `--cache-server-url` or the dynamically discovered URL. The
127+
list of allowed verbs is `prefetch`, `get`, and `post`.
128+
124129
--gvfs-protocol::
125130
--no-gvfs-protocol::
126131
When cloning from a `<url>` with either `dev.azure.com` or

scalar.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,7 @@ static int cmd_clone(int argc, const char **argv)
783783
int src = 1, tags = 1, maintenance = 1;
784784
const char *cache_server_url = NULL, *local_cache_root = NULL;
785785
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
786+
const char *prefetch_server = NULL, *get_server = NULL, *post_server = NULL;
786787
int gvfs_protocol = -1;
787788
const char *ref_format = NULL;
788789

@@ -805,6 +806,15 @@ static int cmd_clone(int argc, const char **argv)
805806
OPT_STRING(0, "cache-server-url", &cache_server_url,
806807
N_("<url>"),
807808
N_("the url or friendly name of the cache server")),
809+
OPT_STRING(0, "prefetch-cache-server-url", &prefetch_server,
810+
N_("<url>"),
811+
N_("the url or friendly name of a cache server for the prefetch endpoint")),
812+
OPT_STRING(0, "get-cache-server-url", &get_server,
813+
N_("<url>"),
814+
N_("the url or friendly name of a cache server for the objects GET endpoint")),
815+
OPT_STRING(0, "post-cache-server-url", &post_server,
816+
N_("<url>"),
817+
N_("the url or friendly name of a cache server for the objects POST endpoint")),
808818
OPT_STRING(0, "local-cache-path", &local_cache_root,
809819
N_("<path>"),
810820
N_("override the path for the local Scalar cache")),
@@ -817,7 +827,8 @@ static int cmd_clone(int argc, const char **argv)
817827
const char * const clone_usage[] = {
818828
N_("scalar clone [--single-branch] [--branch <main-branch>] [--full-clone]\n"
819829
"\t[--[no-]src] [--[no-]tags] [--[no-]maintenance] [--ref-format <format>]\n"
820-
"\t<url> [<enlistment>]"),
830+
"\t[--cache-server-url <url>] [--[verb]-cache-server-url <url>]\n"
831+
"\t[--local-cache-path <path>] <url> [<enlistment>]"),
821832
NULL
822833
};
823834
const char *url;
@@ -979,6 +990,33 @@ static int cmd_clone(int argc, const char **argv)
979990
if (cache_server_url)
980991
fprintf(stderr, "Cache server URL: %s\n",
981992
cache_server_url);
993+
994+
if (prefetch_server &&
995+
set_config("gvfs.prefetch.cache-server=%s", prefetch_server)) {
996+
res = error(_("could not configure prefetch cache server"));
997+
goto cleanup;
998+
}
999+
if (prefetch_server)
1000+
fprintf(stderr, "Prefetch cache server URL: %s\n",
1001+
prefetch_server);
1002+
1003+
if (get_server &&
1004+
set_config("gvfs.get.cache-server=%s", get_server)) {
1005+
res = error(_("could not configure objects GET cache server"));
1006+
goto cleanup;
1007+
}
1008+
if (get_server)
1009+
fprintf(stderr, "Objects GET cache server URL: %s\n",
1010+
get_server);
1011+
1012+
if (post_server &&
1013+
set_config("gvfs.post.cache-server=%s", post_server)) {
1014+
res = error(_("could not configure objects POST cache server"));
1015+
goto cleanup;
1016+
}
1017+
if (post_server)
1018+
fprintf(stderr, "Objects POST cache server URL: %s\n",
1019+
post_server);
9821020
} else {
9831021
if (set_config("core.useGVFSHelper=false") ||
9841022
set_config("remote.origin.promisor=true") ||

t/t9210-scalar.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,47 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
455455
)
456456
'
457457

458+
. "$TEST_DIRECTORY"/lib-gvfs-helper.sh
459+
460+
test_expect_success 'scalar clone: all verbs with different servers' '
461+
git config --global core.askPass true &&
462+
463+
test_when_finished "per_test_cleanup" &&
464+
test_when_finished "scalar delete scalar-clone" &&
465+
466+
start_gvfs_protocol_server 1 &&
467+
start_gvfs_protocol_server 2 &&
468+
start_gvfs_protocol_server 3 &&
469+
470+
# Configure each verb to use a different server:
471+
# - server 0: default (unused in this test; not running.)
472+
# - server 1: prefetch
473+
# - server 2: get
474+
# - server 3: post
475+
scalar -c credential.interactive=true \
476+
clone --full-clone \
477+
--cache-server-url="$(cache_server_url 0)" \
478+
--prefetch-cache-server-url="$(cache_server_url 1)" \
479+
--get-cache-server-url="$(cache_server_url 2)" \
480+
--post-cache-server-url="$(cache_server_url 3)" \
481+
--gvfs-protocol \
482+
-- "http://$HOST_PORT/" scalar-clone 2>err >out &&
483+
484+
test_grep "Cache server URL: $(cache_server_url 0)" err &&
485+
test_grep "Prefetch cache server URL: $(cache_server_url 1)" err &&
486+
test_grep "Objects GET cache server URL: $(cache_server_url 2)" err &&
487+
test_grep "Objects POST cache server URL: $(cache_server_url 3)" err &&
488+
489+
test_cmp_config -C scalar-clone/src "$(cache_server_url 0)" gvfs.cache-server &&
490+
test_cmp_config -C scalar-clone/src "$(cache_server_url 1)" gvfs.prefetch.cache-server &&
491+
test_cmp_config -C scalar-clone/src "$(cache_server_url 2)" gvfs.get.cache-server &&
492+
test_cmp_config -C scalar-clone/src "$(cache_server_url 3)" gvfs.post.cache-server &&
493+
494+
verify_server_was_contacted 1 &&
495+
verify_server_was_contacted 2 &&
496+
verify_server_was_contacted 3
497+
'
498+
458499
test_expect_success 'fetch <non-existent> does not hang in gvfs-helper' '
459500
test_must_fail git -C using-gvfs/src fetch origin does-not-exist
460501
'

0 commit comments

Comments
 (0)