Skip to content

Commit 7353dea

Browse files
derrickstoleedscho
authored andcommitted
scalar: make GVFS Protocol a forced choice
In the Office monorepo, we've recently had an uptick in issues with `scalar clone`. These issues didn't make sense at first and seemed like the users weren't using `microsoft/git` but instead the upstream version's `scalar clone`. Instead of using GVFS cache servers, they were attempting to use the Git protocol's partial clone (which times out). It turns out that what's actually happening is that some network issue is causing the connection with Azure DevOps to error out during the `/gvfs/config` request. In the Git traces, we see the following error during this request: (curl:56) Failure when receiving data from the peer [transient] This isn't 100% of the time, but has increased enough to cause problems for a variety of users. The solution being proposed in this pull request is to remove the fall-back mechanism and instead have an explicit choice to use the GVFS protocol. To avoid significant disruption to Azure DevOps customers (the vast majority of `microsoft/git` users who use `scalar clone` based on my understanding), I added some inferring of a default value from the clone URL. This fallback mechanism was first implemented in the C# version of Scalar in microsoft/scalar#339. This was an attempt to make the Scalar client interesting to non-Azure DevOps customers, especially as GitHub was about to launch the availability of partial clones. Now that the `scalar` client is available upstream, users don't need the GVFS-enabled version to get these benefits. In addition, this will resolve #384 since those requests won't happen against non-ADO URLs unless requested. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 21a375b commit 7353dea

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed

Documentation/scalar.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,26 @@ clone), and `~/.scalarCache` on macOS.
116116
Retrieve missing objects from the specified remote, which is expected to
117117
understand the GVFS protocol.
118118

119+
--[no-]gvfs-protocol::
120+
When cloning from a `<url>` with either `dev.azure.com` or
121+
`visualstudio.com` in the name, `scalar clone` will attempt to use the GVFS
122+
Protocol to access Git objects, specifically from a cache server when
123+
available, and will fail to clone if there is an error over that protocol.
124+
125+
To enable the GVFS Protocol regardless of the origin `<url>`, use
126+
`--gvfs-protocol`. This will cause `scalar clone` to fail when the origin
127+
server fails to provide a valid response to the `gvfs/config` endpoint.
128+
129+
To disable the GVFS Protocol, use `--no-gvfs-protocol` and `scalar clone`
130+
will only use the Git protocol, starting with a partial clone. This can be
131+
helpful if your `<url>` points to Azure Repos but the repository does not
132+
have GVFS cache servers enabled. It is likely more efficient to use its
133+
partial clone functionality through the Git protocol.
134+
135+
Previous versions of `scalar clone` could fall back to a partial clone over
136+
the Git protocol if there is any issue gathering GVFS configuration
137+
information from the origin server.
138+
119139
List
120140
~~~~
121141

scalar.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ static int cmd_clone(int argc, const char **argv)
713713
int src = 1, tags = 1, maintenance = 1;
714714
const char *cache_server_url = NULL, *local_cache_root = NULL;
715715
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
716+
int gvfs_protocol = -1;
717+
716718
struct option clone_options[] = {
717719
OPT_STRING('b', "branch", &branch, N_("<branch>"),
718720
N_("branch to checkout after clone")),
@@ -727,6 +729,8 @@ static int cmd_clone(int argc, const char **argv)
727729
N_("specify if tags should be fetched during clone")),
728730
OPT_BOOL(0, "maintenance", &maintenance,
729731
N_("specify if background maintenance should be enabled")),
732+
OPT_BOOL(0, "gvfs-protocol", &gvfs_protocol,
733+
N_("force enable (or disable) the GVFS Protocol")),
730734
OPT_STRING(0, "cache-server-url", &cache_server_url,
731735
N_("<url>"),
732736
N_("the url or friendly name of the cache server")),
@@ -746,7 +750,6 @@ static int cmd_clone(int argc, const char **argv)
746750
char *enlistment = NULL, *dir = NULL;
747751
struct strbuf buf = STRBUF_INIT;
748752
int res;
749-
int gvfs_protocol;
750753

751754
argc = parse_options(argc, argv, NULL, clone_options, clone_usage, 0);
752755

@@ -859,8 +862,18 @@ static int cmd_clone(int argc, const char **argv)
859862
goto cleanup;
860863
}
861864

862-
gvfs_protocol = cache_server_url ||
863-
supports_gvfs_protocol(url, &default_cache_server_url);
865+
/* Is --[no-]gvfs-protocol unspecified? Infer from url. */
866+
if (gvfs_protocol < 0) {
867+
if (cache_server_url ||
868+
strstr(url, "dev.azure.com") ||
869+
strstr(url, "visualstudio.com"))
870+
gvfs_protocol = 1;
871+
else
872+
gvfs_protocol = 0;
873+
}
874+
875+
if (gvfs_protocol && !supports_gvfs_protocol(url, &default_cache_server_url))
876+
die(_("failed to contact server via GVFS Protocol"));
864877

865878
if (gvfs_protocol) {
866879
if ((res = init_shared_object_cache(url, local_cache_root)))

t/t9210-scalar.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,12 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
393393
# We must set credential.interactive=true to bypass a setting
394394
# in "scalar clone" that disables interactive credentials during
395395
# an unattended command.
396-
scalar -c credential.interactive=true clone --single-branch -- http://$HOST_PORT/ using-gvfs &&
396+
GIT_TRACE2_EVENT="$(pwd)/clone-trace-with-gvfs" scalar \
397+
-c credential.interactive=true \
398+
clone --gvfs-protocol \
399+
--single-branch -- http://$HOST_PORT/ using-gvfs &&
400+
401+
grep "GET/config(main)" <clone-trace-with-gvfs &&
397402
398403
: verify that the shared cache has been configured &&
399404
cache_key="url_$(printf "%s" http://$HOST_PORT/ |
@@ -415,6 +420,24 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
415420
)
416421
'
417422

423+
test_expect_success '`scalar clone --no-gvfs-protocol` skips gvfs/config' '
424+
# the fake cache server requires fake authentication &&
425+
git config --global core.askPass true &&
426+
427+
# We must set credential.interactive=true to bypass a setting
428+
# in "scalar clone" that disables interactive credentials during
429+
# an unattended command.
430+
GIT_TRACE2_EVENT="$(pwd)/clone-trace-no-gvfs" scalar \
431+
-c credential.interactive=true \
432+
clone --no-gvfs-protocol \
433+
--single-branch -- http://$HOST_PORT/ skipping-gvfs &&
434+
435+
! grep "GET/config(main)" <clone-trace-no-gvfs &&
436+
! git -C skipping-gvfs/src config core.gvfs &&
437+
438+
test_config -C skipping-gvfs/src remote.origin.partialclonefilter blob:none
439+
'
440+
418441
test_expect_success '`scalar register` parallel to worktree is unsupported' '
419442
git init test-repo/src &&
420443
mkdir -p test-repo/out &&

0 commit comments

Comments
 (0)