Skip to content

Commit f0c9d30

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 <johannes.schindelin@gmx.de>
1 parent cffd005 commit f0c9d30

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

‎scalar.c‎

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,13 @@ static int get_cache_server_url(struct json_iterator *it)
423423
return 0;
424424
}
425425

426+
static int can_url_support_gvfs(const char *url)
427+
{
428+
return starts_with(url, "https://") ||
429+
(git_env_bool("GIT_TEST_ALLOW_GVFS_VIA_HTTP", 0) &&
430+
starts_with(url, "http://"));
431+
}
432+
426433
/*
427434
* If `cache_server_url` is `NULL`, print the list to `stdout`.
428435
*
@@ -434,6 +441,13 @@ static int supports_gvfs_protocol(const char *url, char **cache_server_url)
434441
struct child_process cp = CHILD_PROCESS_INIT;
435442
struct strbuf out = STRBUF_INIT;
436443

444+
/*
445+
* The GVFS protocol is only supported via https://; For testing, we
446+
* also allow http://.
447+
*/
448+
if (!can_url_support_gvfs(url))
449+
return 0;
450+
437451
cp.git_cmd = 1;
438452
strvec_pushl(&cp.args, "-c", "http.version=HTTP/1.1",
439453
"gvfs-helper", "--remote", url, "config", NULL);
@@ -512,19 +526,26 @@ static char *get_cache_key(const char *url)
512526
struct strbuf out = STRBUF_INIT;
513527
char *cache_key = NULL;
514528

515-
cp.git_cmd = 1;
516-
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
517-
"endpoint", "vsts/info", NULL);
518-
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
519-
char *id = NULL;
520-
struct json_iterator it =
521-
JSON_ITERATOR_INIT(out.buf, get_repository_id, &id);
522-
523-
if (iterate_json(&it) < 0)
524-
warning("JSON parse error (%s)", out.buf);
525-
else if (id)
526-
cache_key = xstrfmt("id_%s", id);
527-
free(id);
529+
/*
530+
* The GVFS protocol is only supported via https://; For testing, we
531+
* also allow http://.
532+
*/
533+
if (can_url_support_gvfs(url)) {
534+
cp.git_cmd = 1;
535+
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
536+
"endpoint", "vsts/info", NULL);
537+
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
538+
char *id = NULL;
539+
struct json_iterator it =
540+
JSON_ITERATOR_INIT(out.buf, get_repository_id,
541+
&id);
542+
543+
if (iterate_json(&it) < 0)
544+
warning("JSON parse error (%s)", out.buf);
545+
else if (id)
546+
cache_key = xstrfmt("id_%s", id);
547+
free(id);
548+
}
528549
}
529550

530551
if (!cache_key) {

0 commit comments

Comments
 (0)