Skip to content

Commit 919a59f

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 e5cc4cf commit 919a59f

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
@@ -391,6 +391,13 @@ static int get_cache_server_url(struct json_iterator *it)
391391
return 0;
392392
}
393393

394+
static int can_url_support_gvfs(const char *url)
395+
{
396+
return starts_with(url, "https://") ||
397+
(git_env_bool("GIT_TEST_ALLOW_GVFS_VIA_HTTP", 0) &&
398+
starts_with(url, "http://"));
399+
}
400+
394401
/*
395402
* If `cache_server_url` is `NULL`, print the list to `stdout`.
396403
*
@@ -402,6 +409,13 @@ static int supports_gvfs_protocol(const char *url, char **cache_server_url)
402409
struct child_process cp = CHILD_PROCESS_INIT;
403410
struct strbuf out = STRBUF_INIT;
404411

412+
/*
413+
* The GVFS protocol is only supported via https://; For testing, we
414+
* also allow http://.
415+
*/
416+
if (!can_url_support_gvfs(url))
417+
return 0;
418+
405419
cp.git_cmd = 1;
406420
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url, "config", NULL);
407421
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
@@ -470,19 +484,26 @@ static char *get_cache_key(const char *url)
470484
struct strbuf out = STRBUF_INIT;
471485
char *cache_key = NULL;
472486

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

488509
if (!cache_key) {

0 commit comments

Comments
 (0)