Skip to content

Commit d3620e3

Browse files
committed
gvfs-helper: add the endpoint command
We already have the `config` command that accesses the `gvfs/config` endpoint. To implement `scalar`, we also need to be able to access the `vsts/info` endpoint. Let's add a command to do precisely that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 5165a4e commit d3620e3

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

gvfs-helper.c

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@
202202
// [2] Documentation/technical/long-running-process-protocol.txt
203203
// [3] See GIT_TRACE_PACKET
204204
//
205+
// endpoint
206+
//
207+
// Fetch the given endpoint from the main Git server (specifying
208+
// `gvfs/config` as endpoint is idempotent to the `config`
209+
// command mentioned above).
210+
//
205211
//////////////////////////////////////////////////////////////////
206212

207213
#include "git-compat-util.h"
@@ -3121,18 +3127,20 @@ static void do_req__with_fallback(const char *url_component,
31213127
*
31223128
* Return server's response buffer. This is probably a raw JSON string.
31233129
*/
3124-
static void do__http_get__gvfs_config(struct gh__response_status *status,
3125-
struct strbuf *config_data)
3130+
static void do__http_get__simple_endpoint(struct gh__response_status *status,
3131+
struct strbuf *response,
3132+
const char *endpoint,
3133+
const char *tr2_label)
31263134
{
31273135
struct gh__request_params params = GH__REQUEST_PARAMS_INIT;
31283136

3129-
strbuf_addstr(&params.tr2_label, "GET/config");
3137+
strbuf_addstr(&params.tr2_label, tr2_label);
31303138

31313139
params.b_is_post = 0;
31323140
params.b_write_to_file = 0;
31333141
/* cache-servers do not handle gvfs/config REST calls */
31343142
params.b_permit_cache_server_if_defined = 0;
3135-
params.buffer = config_data;
3143+
params.buffer = response;
31363144
params.objects_mode = GH__OBJECTS_MODE__NONE;
31373145

31383146
params.object_count = 1; /* a bit of a lie */
@@ -3154,15 +3162,22 @@ static void do__http_get__gvfs_config(struct gh__response_status *status,
31543162
* see any need to report progress on the upload side of
31553163
* the GET. So just report progress on the download side.
31563164
*/
3157-
strbuf_addstr(&params.progress_base_phase3_msg,
3158-
"Receiving gvfs/config");
3165+
strbuf_addf(&params.progress_base_phase3_msg,
3166+
"Receiving %s", endpoint);
31593167
}
31603168

3161-
do_req__with_fallback("gvfs/config", &params, status);
3169+
do_req__with_fallback(endpoint, &params, status);
31623170

31633171
gh__request_params__release(&params);
31643172
}
31653173

3174+
static void do__http_get__gvfs_config(struct gh__response_status *status,
3175+
struct strbuf *config_data)
3176+
{
3177+
do__http_get__simple_endpoint(status, config_data, "gvfs/config",
3178+
"GET/config");
3179+
}
3180+
31663181
static void setup_gvfs_objects_progress(struct gh__request_params *params,
31673182
unsigned long num, unsigned long den)
31683183
{
@@ -3607,6 +3622,35 @@ static enum gh__error_code do_sub_cmd__config(int argc, const char **argv)
36073622
return ec;
36083623
}
36093624

3625+
static enum gh__error_code do_sub_cmd__endpoint(int argc, const char **argv)
3626+
{
3627+
struct gh__response_status status = GH__RESPONSE_STATUS_INIT;
3628+
struct strbuf data = STRBUF_INIT;
3629+
enum gh__error_code ec = GH__ERROR_CODE__OK;
3630+
const char *endpoint;
3631+
3632+
if (argc != 2)
3633+
return GH__ERROR_CODE__ERROR;
3634+
endpoint = argv[1];
3635+
3636+
trace2_cmd_mode(endpoint);
3637+
3638+
finish_init(0);
3639+
3640+
do__http_get__simple_endpoint(&status, &data, endpoint, endpoint);
3641+
ec = status.ec;
3642+
3643+
if (ec == GH__ERROR_CODE__OK)
3644+
printf("%s\n", data.buf);
3645+
else
3646+
error("config: %s", status.error_message.buf);
3647+
3648+
gh__response_status__release(&status);
3649+
strbuf_release(&data);
3650+
3651+
return ec;
3652+
}
3653+
36103654
/*
36113655
* Read a list of objects from stdin and fetch them as a series of
36123656
* single object HTTP GET requests.
@@ -4098,6 +4142,9 @@ static enum gh__error_code do_sub_cmd(int argc, const char **argv)
40984142
if (!strcmp(argv[0], "config"))
40994143
return do_sub_cmd__config(argc, argv);
41004144

4145+
if (!strcmp(argv[0], "endpoint"))
4146+
return do_sub_cmd__endpoint(argc, argv);
4147+
41014148
if (!strcmp(argv[0], "prefetch"))
41024149
return do_sub_cmd__prefetch(argc, argv);
41034150

0 commit comments

Comments
 (0)