Skip to content

Commit 0794f78

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 f9722c3 commit 0794f78

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
@@ -376,6 +376,13 @@ static int get_cache_server_url(struct json_iterator *it)
376376
return 0;
377377
}
378378

379+
static int can_url_support_gvfs(const char *url)
380+
{
381+
return starts_with(url, "https://") ||
382+
(git_env_bool("GIT_TEST_ALLOW_GVFS_VIA_HTTP", 0) &&
383+
starts_with(url, "http://"));
384+
}
385+
379386
/*
380387
* If `cache_server_url` is `NULL`, print the list to `stdout`.
381388
*
@@ -387,6 +394,13 @@ static int supports_gvfs_protocol(const char *url, char **cache_server_url)
387394
struct child_process cp = CHILD_PROCESS_INIT;
388395
struct strbuf out = STRBUF_INIT;
389396

397+
/*
398+
* The GVFS protocol is only supported via https://; For testing, we
399+
* also allow http://.
400+
*/
401+
if (!can_url_support_gvfs(url))
402+
return 0;
403+
390404
cp.git_cmd = 1;
391405
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url, "config", NULL);
392406
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
@@ -455,19 +469,26 @@ static char *get_cache_key(const char *url)
455469
struct strbuf out = STRBUF_INIT;
456470
char *cache_key = NULL;
457471

458-
cp.git_cmd = 1;
459-
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
460-
"endpoint", "vsts/info", NULL);
461-
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
462-
char *id = NULL;
463-
struct json_iterator it =
464-
JSON_ITERATOR_INIT(out.buf, get_repository_id, &id);
465-
466-
if (iterate_json(&it) < 0)
467-
warning("JSON parse error (%s)", out.buf);
468-
else if (id)
469-
cache_key = xstrfmt("id_%s", id);
470-
free(id);
472+
/*
473+
* The GVFS protocol is only supported via https://; For testing, we
474+
* also allow http://.
475+
*/
476+
if (can_url_support_gvfs(url)) {
477+
cp.git_cmd = 1;
478+
strvec_pushl(&cp.args, "gvfs-helper", "--remote", url,
479+
"endpoint", "vsts/info", NULL);
480+
if (!pipe_command(&cp, NULL, 0, &out, 512, NULL, 0)) {
481+
char *id = NULL;
482+
struct json_iterator it =
483+
JSON_ITERATOR_INIT(out.buf, get_repository_id,
484+
&id);
485+
486+
if (iterate_json(&it) < 0)
487+
warning("JSON parse error (%s)", out.buf);
488+
else if (id)
489+
cache_key = xstrfmt("id_%s", id);
490+
free(id);
491+
}
471492
}
472493

473494
if (!cache_key) {

0 commit comments

Comments
 (0)