Skip to content

Commit ee2f8cb

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 62fe732 commit ee2f8cb

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
@@ -412,6 +412,13 @@ static int get_cache_server_url(struct json_iterator *it)
412412
return 0;
413413
}
414414

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

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

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

514535
if (!cache_key) {

0 commit comments

Comments
 (0)