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
@@ -3128,18 +3134,20 @@ static void do_req__with_fallback(const char *url_component,
31283134 *
31293135 * Return server's response buffer. This is probably a raw JSON string.
31303136 */
3131- static void do__http_get__gvfs_config (struct gh__response_status * status ,
3132- struct strbuf * config_data )
3137+ static void do__http_get__simple_endpoint (struct gh__response_status * status ,
3138+ struct strbuf * response ,
3139+ const char * endpoint ,
3140+ const char * tr2_label )
31333141{
31343142 struct gh__request_params params = GH__REQUEST_PARAMS_INIT ;
31353143
3136- strbuf_addstr (& params .tr2_label , "GET/config" );
3144+ strbuf_addstr (& params .tr2_label , tr2_label );
31373145
31383146 params .b_is_post = 0 ;
31393147 params .b_write_to_file = 0 ;
31403148 /* cache-servers do not handle gvfs/config REST calls */
31413149 params .b_permit_cache_server_if_defined = 0 ;
3142- params .buffer = config_data ;
3150+ params .buffer = response ;
31433151 params .objects_mode = GH__OBJECTS_MODE__NONE ;
31443152
31453153 params .object_count = 1 ; /* a bit of a lie */
@@ -3161,15 +3169,22 @@ static void do__http_get__gvfs_config(struct gh__response_status *status,
31613169 * see any need to report progress on the upload side of
31623170 * the GET. So just report progress on the download side.
31633171 */
3164- strbuf_addstr (& params .progress_base_phase3_msg ,
3165- "Receiving gvfs/config" );
3172+ strbuf_addf (& params .progress_base_phase3_msg ,
3173+ "Receiving %s" , endpoint );
31663174 }
31673175
3168- do_req__with_fallback ("gvfs/config" , & params , status );
3176+ do_req__with_fallback (endpoint , & params , status );
31693177
31703178 gh__request_params__release (& params );
31713179}
31723180
3181+ static void do__http_get__gvfs_config (struct gh__response_status * status ,
3182+ struct strbuf * config_data )
3183+ {
3184+ do__http_get__simple_endpoint (status , config_data , "gvfs/config" ,
3185+ "GET/config" );
3186+ }
3187+
31733188static void setup_gvfs_objects_progress (struct gh__request_params * params ,
31743189 unsigned long num , unsigned long den )
31753190{
@@ -3614,6 +3629,35 @@ static enum gh__error_code do_sub_cmd__config(int argc UNUSED, const char **argv
36143629 return ec ;
36153630}
36163631
3632+ static enum gh__error_code do_sub_cmd__endpoint (int argc , const char * * argv )
3633+ {
3634+ struct gh__response_status status = GH__RESPONSE_STATUS_INIT ;
3635+ struct strbuf data = STRBUF_INIT ;
3636+ enum gh__error_code ec = GH__ERROR_CODE__OK ;
3637+ const char * endpoint ;
3638+
3639+ if (argc != 2 )
3640+ return GH__ERROR_CODE__ERROR ;
3641+ endpoint = argv [1 ];
3642+
3643+ trace2_cmd_mode (endpoint );
3644+
3645+ finish_init (0 );
3646+
3647+ do__http_get__simple_endpoint (& status , & data , endpoint , endpoint );
3648+ ec = status .ec ;
3649+
3650+ if (ec == GH__ERROR_CODE__OK )
3651+ printf ("%s\n" , data .buf );
3652+ else
3653+ error ("config: %s" , status .error_message .buf );
3654+
3655+ gh__response_status__release (& status );
3656+ strbuf_release (& data );
3657+
3658+ return ec ;
3659+ }
3660+
36173661/*
36183662 * Read a list of objects from stdin and fetch them as a series of
36193663 * single object HTTP GET requests.
@@ -4106,6 +4150,9 @@ static enum gh__error_code do_sub_cmd(int argc, const char **argv)
41064150 if (!strcmp (argv [0 ], "config" ))
41074151 return do_sub_cmd__config (argc , argv );
41084152
4153+ if (!strcmp (argv [0 ], "endpoint" ))
4154+ return do_sub_cmd__endpoint (argc , argv );
4155+
41094156 if (!strcmp (argv [0 ], "prefetch" ))
41104157 return do_sub_cmd__prefetch (argc , argv );
41114158
0 commit comments