Skip to content

Commit 531ca42

Browse files
committed
scalar: only try GVFS protocol on https:// URLs
Well, technically also the http:// protocol is allowed _when testing_... Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 69f523b commit 531ca42

File tree

1 file changed

+34
-13
lines changed

1 file changed

+34
-13
lines changed

scalar.c

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ static int get_cache_server_url(struct json_iterator *it)
413413
return 0;
414414
}
415415

416+
static int can_url_support_gvfs(const char *url)
417+
{
418+
return starts_with(url, "https://") ||
419+
(git_env_bool("GIT_TEST_ALLOW_GVFS_VIA_HTTP", 0) &&
420+
starts_with(url, "http://"));
421+
}
422+
416423
/*
417424
* If `cache_server_url` is `NULL`, print the list to `stdout`.
418425
*
@@ -424,6 +431,13 @@ static int supports_gvfs_protocol(const char *url, char **cache_server_url)
424431
struct child_process cp = CHILD_PROCESS_INIT;
425432
struct strbuf out = STRBUF_INIT;
426433

434+
/*
435+
* The GVFS protocol is only supported via https://; For testing, we
436+
* also allow http://.
437+
*/
438+
if (!can_url_support_gvfs(url))
439+
return 0;
440+
427441
cp.git_cmd = 1;
428442
strvec_pushl(&cp.args, "-c", "http.version=HTTP/1.1",
429443
"gvfs-helper", "--remote", url, "config", NULL);
@@ -497,19 +511,26 @@ static char *get_cache_key(const char *url)
497511
struct strbuf out = STRBUF_INIT;
498512
char *cache_key = NULL;
499513

500-
cp.git_cmd = 1;
501-
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
502-
"endpoint", "vsts/info", NULL);
503-
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
504-
char *id = NULL;
505-
struct json_iterator it =
506-
JSON_ITERATOR_INIT(out.buf, get_repository_id, &id);
507-
508-
if (iterate_json(&it) < 0)
509-
warning("JSON parse error (%s)", out.buf);
510-
else if (id)
511-
cache_key = xstrfmt("id_%s", id);
512-
free(id);
514+
/*
515+
* The GVFS protocol is only supported via https://; For testing, we
516+
* also allow http://.
517+
*/
518+
if (can_url_support_gvfs(url)) {
519+
cp.git_cmd = 1;
520+
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
521+
"endpoint", "vsts/info", NULL);
522+
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
523+
char *id = NULL;
524+
struct json_iterator it =
525+
JSON_ITERATOR_INIT(out.buf, get_repository_id,
526+
&id);
527+
528+
if (iterate_json(&it) < 0)
529+
warning("JSON parse error (%s)", out.buf);
530+
else if (id)
531+
cache_key = xstrfmt("id_%s", id);
532+
free(id);
533+
}
513534
}
514535

515536
if (!cache_key) {

0 commit comments

Comments
 (0)