Skip to content

Commit 2b03f40

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 <[email protected]>
1 parent 97b19f8 commit 2b03f40

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
@@ -3141,18 +3147,20 @@ static void do_req__with_fallback(const char *url_component,
31413147
*
31423148
* Return server's response buffer. This is probably a raw JSON string.
31433149
*/
3144-
static void do__http_get__gvfs_config(struct gh__response_status *status,
3145-
struct strbuf *config_data)
3150+
static void do__http_get__simple_endpoint(struct gh__response_status *status,
3151+
struct strbuf *response,
3152+
const char *endpoint,
3153+
const char *tr2_label)
31463154
{
31473155
struct gh__request_params params = GH__REQUEST_PARAMS_INIT;
31483156

3149-
strbuf_addstr(&params.tr2_label, "GET/config");
3157+
strbuf_addstr(&params.tr2_label, tr2_label);
31503158

31513159
params.b_is_post = 0;
31523160
params.b_write_to_file = 0;
31533161
/* cache-servers do not handle gvfs/config REST calls */
31543162
params.b_permit_cache_server_if_defined = 0;
3155-
params.buffer = config_data;
3163+
params.buffer = response;
31563164
params.objects_mode = GH__OBJECTS_MODE__NONE;
31573165

31583166
params.object_count = 1; /* a bit of a lie */
@@ -3174,15 +3182,22 @@ static void do__http_get__gvfs_config(struct gh__response_status *status,
31743182
* see any need to report progress on the upload side of
31753183
* the GET. So just report progress on the download side.
31763184
*/
3177-
strbuf_addstr(&params.progress_base_phase3_msg,
3178-
"Receiving gvfs/config");
3185+
strbuf_addf(&params.progress_base_phase3_msg,
3186+
"Receiving %s", endpoint);
31793187
}
31803188

3181-
do_req__with_fallback("gvfs/config", &params, status);
3189+
do_req__with_fallback(endpoint, &params, status);
31823190

31833191
gh__request_params__release(&params);
31843192
}
31853193

3194+
static void do__http_get__gvfs_config(struct gh__response_status *status,
3195+
struct strbuf *config_data)
3196+
{
3197+
do__http_get__simple_endpoint(status, config_data, "gvfs/config",
3198+
"GET/config");
3199+
}
3200+
31863201
static void setup_gvfs_objects_progress(struct gh__request_params *params,
31873202
unsigned long num, unsigned long den)
31883203
{
@@ -3627,6 +3642,35 @@ static enum gh__error_code do_sub_cmd__config(int argc UNUSED, const char **argv
36273642
return ec;
36283643
}
36293644

3645+
static enum gh__error_code do_sub_cmd__endpoint(int argc, const char **argv)
3646+
{
3647+
struct gh__response_status status = GH__RESPONSE_STATUS_INIT;
3648+
struct strbuf data = STRBUF_INIT;
3649+
enum gh__error_code ec = GH__ERROR_CODE__OK;
3650+
const char *endpoint;
3651+
3652+
if (argc != 2)
3653+
return GH__ERROR_CODE__ERROR;
3654+
endpoint = argv[1];
3655+
3656+
trace2_cmd_mode(endpoint);
3657+
3658+
finish_init(0);
3659+
3660+
do__http_get__simple_endpoint(&status, &data, endpoint, endpoint);
3661+
ec = status.ec;
3662+
3663+
if (ec == GH__ERROR_CODE__OK)
3664+
printf("%s\n", data.buf);
3665+
else
3666+
error("config: %s", status.error_message.buf);
3667+
3668+
gh__response_status__release(&status);
3669+
strbuf_release(&data);
3670+
3671+
return ec;
3672+
}
3673+
36303674
/*
36313675
* Read a list of objects from stdin and fetch them as a series of
36323676
* single object HTTP GET requests.
@@ -4119,6 +4163,9 @@ static enum gh__error_code do_sub_cmd(int argc, const char **argv)
41194163
if (!strcmp(argv[0], "config"))
41204164
return do_sub_cmd__config(argc, argv);
41214165

4166+
if (!strcmp(argv[0], "endpoint"))
4167+
return do_sub_cmd__endpoint(argc, argv);
4168+
41224169
if (!strcmp(argv[0], "prefetch"))
41234170
return do_sub_cmd__prefetch(argc, argv);
41244171

0 commit comments

Comments
 (0)