Skip to content

Commit 8bd4288

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 0ac4838 commit 8bd4288

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
#define USE_THE_REPOSITORY_VARIABLE
@@ -3150,18 +3156,20 @@ static void do_req__with_fallback(const char *url_component,
31503156
*
31513157
* Return server's response buffer. This is probably a raw JSON string.
31523158
*/
3153-
static void do__http_get__gvfs_config(struct gh__response_status *status,
3154-
struct strbuf *config_data)
3159+
static void do__http_get__simple_endpoint(struct gh__response_status *status,
3160+
struct strbuf *response,
3161+
const char *endpoint,
3162+
const char *tr2_label)
31553163
{
31563164
struct gh__request_params params = GH__REQUEST_PARAMS_INIT;
31573165

3158-
strbuf_addstr(&params.tr2_label, "GET/config");
3166+
strbuf_addstr(&params.tr2_label, tr2_label);
31593167

31603168
params.b_is_post = 0;
31613169
params.b_write_to_file = 0;
31623170
/* cache-servers do not handle gvfs/config REST calls */
31633171
params.b_permit_cache_server_if_defined = 0;
3164-
params.buffer = config_data;
3172+
params.buffer = response;
31653173
params.objects_mode = GH__OBJECTS_MODE__NONE;
31663174

31673175
params.object_count = 1; /* a bit of a lie */
@@ -3183,15 +3191,22 @@ static void do__http_get__gvfs_config(struct gh__response_status *status,
31833191
* see any need to report progress on the upload side of
31843192
* the GET. So just report progress on the download side.
31853193
*/
3186-
strbuf_addstr(&params.progress_base_phase3_msg,
3187-
"Receiving gvfs/config");
3194+
strbuf_addf(&params.progress_base_phase3_msg,
3195+
"Receiving %s", endpoint);
31883196
}
31893197

3190-
do_req__with_fallback("gvfs/config", &params, status);
3198+
do_req__with_fallback(endpoint, &params, status);
31913199

31923200
gh__request_params__release(&params);
31933201
}
31943202

3203+
static void do__http_get__gvfs_config(struct gh__response_status *status,
3204+
struct strbuf *config_data)
3205+
{
3206+
do__http_get__simple_endpoint(status, config_data, "gvfs/config",
3207+
"GET/config");
3208+
}
3209+
31953210
static void setup_gvfs_objects_progress(struct gh__request_params *params,
31963211
unsigned long num, unsigned long den)
31973212
{
@@ -3636,6 +3651,35 @@ static enum gh__error_code do_sub_cmd__config(int argc UNUSED, const char **argv
36363651
return ec;
36373652
}
36383653

3654+
static enum gh__error_code do_sub_cmd__endpoint(int argc, const char **argv)
3655+
{
3656+
struct gh__response_status status = GH__RESPONSE_STATUS_INIT;
3657+
struct strbuf data = STRBUF_INIT;
3658+
enum gh__error_code ec = GH__ERROR_CODE__OK;
3659+
const char *endpoint;
3660+
3661+
if (argc != 2)
3662+
return GH__ERROR_CODE__ERROR;
3663+
endpoint = argv[1];
3664+
3665+
trace2_cmd_mode(endpoint);
3666+
3667+
finish_init(0);
3668+
3669+
do__http_get__simple_endpoint(&status, &data, endpoint, endpoint);
3670+
ec = status.ec;
3671+
3672+
if (ec == GH__ERROR_CODE__OK)
3673+
printf("%s\n", data.buf);
3674+
else
3675+
error("config: %s", status.error_message.buf);
3676+
3677+
gh__response_status__release(&status);
3678+
strbuf_release(&data);
3679+
3680+
return ec;
3681+
}
3682+
36393683
/*
36403684
* Read a list of objects from stdin and fetch them as a series of
36413685
* single object HTTP GET requests.
@@ -4162,6 +4206,9 @@ static enum gh__error_code do_sub_cmd(int argc, const char **argv)
41624206
if (!strcmp(argv[0], "config"))
41634207
return do_sub_cmd__config(argc, argv);
41644208

4209+
if (!strcmp(argv[0], "endpoint"))
4210+
return do_sub_cmd__endpoint(argc, argv);
4211+
41654212
if (!strcmp(argv[0], "prefetch"))
41664213
return do_sub_cmd__prefetch(argc, argv);
41674214

0 commit comments

Comments
 (0)