Skip to content

Commit 5360246

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 4562c36 commit 5360246

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
@@ -110,6 +110,26 @@ clone), and `~/.scalarCache` on macOS.
110110
Retrieve missing objects from the specified remote, which is expected to
111111
understand the GVFS protocol.
112112

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

scalar.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ static int cmd_clone(int argc, const char **argv)
698698
int src = 1, tags = 1;
699699
const char *cache_server_url = NULL, *local_cache_root = NULL;
700700
char *default_cache_server_url = NULL, *local_cache_root_abs = NULL;
701+
int gvfs_protocol = -1;
702+
701703
struct option clone_options[] = {
702704
OPT_STRING('b', "branch", &branch, N_("<branch>"),
703705
N_("branch to checkout after clone")),
@@ -710,6 +712,8 @@ static int cmd_clone(int argc, const char **argv)
710712
N_("create repository within 'src' directory")),
711713
OPT_BOOL(0, "tags", &tags,
712714
N_("specify if tags should be fetched during clone")),
715+
OPT_BOOL(0, "gvfs-protocol", &gvfs_protocol,
716+
N_("force enable (or disable) the GVFS Protocol")),
713717
OPT_STRING(0, "cache-server-url", &cache_server_url,
714718
N_("<url>"),
715719
N_("the url or friendly name of the cache server")),
@@ -729,7 +733,6 @@ static int cmd_clone(int argc, const char **argv)
729733
char *enlistment = NULL, *dir = NULL;
730734
struct strbuf buf = STRBUF_INIT;
731735
int res;
732-
int gvfs_protocol;
733736

734737
argc = parse_options(argc, argv, NULL, clone_options, clone_usage, 0);
735738

@@ -842,8 +845,18 @@ static int cmd_clone(int argc, const char **argv)
842845
goto cleanup;
843846
}
844847

845-
gvfs_protocol = cache_server_url ||
846-
supports_gvfs_protocol(url, &default_cache_server_url);
848+
/* Is --[no-]gvfs-protocol unspecified? Infer from url. */
849+
if (gvfs_protocol < 0) {
850+
if (cache_server_url ||
851+
strstr(url, "dev.azure.com") ||
852+
strstr(url, "visualstudio.com"))
853+
gvfs_protocol = 1;
854+
else
855+
gvfs_protocol = 0;
856+
}
857+
858+
if (gvfs_protocol && !supports_gvfs_protocol(url, &default_cache_server_url))
859+
die(_("failed to contact server via GVFS Protocol"));
847860

848861
if (gvfs_protocol) {
849862
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
@@ -371,7 +371,12 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
371371
# We must set credential.interactive=true to bypass a setting
372372
# in "scalar clone" that disables interactive credentials during
373373
# an unattended command.
374-
scalar -c credential.interactive=true clone --single-branch -- http://$HOST_PORT/ using-gvfs &&
374+
GIT_TRACE2_EVENT="$(pwd)/clone-trace-with-gvfs" scalar \
375+
-c credential.interactive=true \
376+
clone --gvfs-protocol \
377+
--single-branch -- http://$HOST_PORT/ using-gvfs &&
378+
379+
grep "GET/config(main)" <clone-trace-with-gvfs &&
375380
376381
: verify that the shared cache has been configured &&
377382
cache_key="url_$(printf "%s" http://$HOST_PORT/ |
@@ -393,6 +398,24 @@ test_expect_success '`scalar clone` with GVFS-enabled server' '
393398
)
394399
'
395400

401+
test_expect_success '`scalar clone --no-gvfs-protocol` skips gvfs/config' '
402+
# the fake cache server requires fake authentication &&
403+
git config --global core.askPass true &&
404+
405+
# We must set credential.interactive=true to bypass a setting
406+
# in "scalar clone" that disables interactive credentials during
407+
# an unattended command.
408+
GIT_TRACE2_EVENT="$(pwd)/clone-trace-no-gvfs" scalar \
409+
-c credential.interactive=true \
410+
clone --no-gvfs-protocol \
411+
--single-branch -- http://$HOST_PORT/ skipping-gvfs &&
412+
413+
! grep "GET/config(main)" <clone-trace-no-gvfs &&
414+
! git -C skipping-gvfs/src config core.gvfs &&
415+
416+
test_config -C skipping-gvfs/src remote.origin.partialclonefilter blob:none
417+
'
418+
396419
test_expect_success '`scalar register` parallel to worktree is unsupported' '
397420
git init test-repo/src &&
398421
mkdir -p test-repo/out &&

0 commit comments

Comments
 (0)