Skip to content

Commit d8c36e2

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 e522659 commit d8c36e2

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
@@ -397,6 +397,13 @@ static int get_cache_server_url(struct json_iterator *it)
397397
return 0;
398398
}
399399

400+
static int can_url_support_gvfs(const char *url)
401+
{
402+
return starts_with(url, "https://") ||
403+
(git_env_bool("GIT_TEST_ALLOW_GVFS_VIA_HTTP", 0) &&
404+
starts_with(url, "http://"));
405+
}
406+
400407
/*
401408
* If `cache_server_url` is `NULL`, print the list to `stdout`.
402409
*
@@ -408,6 +415,13 @@ static int supports_gvfs_protocol(const char *url, char **cache_server_url)
408415
struct child_process cp = CHILD_PROCESS_INIT;
409416
struct strbuf out = STRBUF_INIT;
410417

418+
/*
419+
* The GVFS protocol is only supported via https://; For testing, we
420+
* also allow http://.
421+
*/
422+
if (!can_url_support_gvfs(url))
423+
return 0;
424+
411425
cp.git_cmd = 1;
412426
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url, "config", NULL);
413427
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
@@ -476,19 +490,26 @@ static char *get_cache_key(const char *url)
476490
struct strbuf out = STRBUF_INIT;
477491
char *cache_key = NULL;
478492

479-
cp.git_cmd = 1;
480-
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
481-
"endpoint", "vsts/info", NULL);
482-
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
483-
char *id = NULL;
484-
struct json_iterator it =
485-
JSON_ITERATOR_INIT(out.buf, get_repository_id, &id);
486-
487-
if (iterate_json(&it) < 0)
488-
warning("JSON parse error (%s)", out.buf);
489-
else if (id)
490-
cache_key = xstrfmt("id_%s", id);
491-
free(id);
493+
/*
494+
* The GVFS protocol is only supported via https://; For testing, we
495+
* also allow http://.
496+
*/
497+
if (can_url_support_gvfs(url)) {
498+
cp.git_cmd = 1;
499+
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
500+
"endpoint", "vsts/info", NULL);
501+
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
502+
char *id = NULL;
503+
struct json_iterator it =
504+
JSON_ITERATOR_INIT(out.buf, get_repository_id,
505+
&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);
512+
}
492513
}
493514

494515
if (!cache_key) {

0 commit comments

Comments
 (0)