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 "cache.h"
@@ -3110,18 +3116,20 @@ static void do_req__with_fallback(const char *url_component,
31103116 *
31113117 * Return server's response buffer. This is probably a raw JSON string.
31123118 */
3113- static void do__http_get__gvfs_config (struct gh__response_status * status ,
3114- struct strbuf * config_data )
3119+ static void do__http_get__simple_endpoint (struct gh__response_status * status ,
3120+ struct strbuf * response ,
3121+ const char * endpoint ,
3122+ const char * tr2_label )
31153123{
31163124 struct gh__request_params params = GH__REQUEST_PARAMS_INIT ;
31173125
3118- strbuf_addstr (& params .tr2_label , "GET/config" );
3126+ strbuf_addstr (& params .tr2_label , tr2_label );
31193127
31203128 params .b_is_post = 0 ;
31213129 params .b_write_to_file = 0 ;
31223130 /* cache-servers do not handle gvfs/config REST calls */
31233131 params .b_permit_cache_server_if_defined = 0 ;
3124- params .buffer = config_data ;
3132+ params .buffer = response ;
31253133 params .objects_mode = GH__OBJECTS_MODE__NONE ;
31263134
31273135 params .object_count = 1 ; /* a bit of a lie */
@@ -3143,15 +3151,22 @@ static void do__http_get__gvfs_config(struct gh__response_status *status,
31433151 * see any need to report progress on the upload side of
31443152 * the GET. So just report progress on the download side.
31453153 */
3146- strbuf_addstr (& params .progress_base_phase3_msg ,
3147- "Receiving gvfs/config" );
3154+ strbuf_addf (& params .progress_base_phase3_msg ,
3155+ "Receiving %s" , endpoint );
31483156 }
31493157
3150- do_req__with_fallback ("gvfs/config" , & params , status );
3158+ do_req__with_fallback (endpoint , & params , status );
31513159
31523160 gh__request_params__release (& params );
31533161}
31543162
3163+ static void do__http_get__gvfs_config (struct gh__response_status * status ,
3164+ struct strbuf * config_data )
3165+ {
3166+ do__http_get__simple_endpoint (status , config_data , "gvfs/config" ,
3167+ "GET/config" );
3168+ }
3169+
31553170static void setup_gvfs_objects_progress (struct gh__request_params * params ,
31563171 unsigned long num , unsigned long den )
31573172{
@@ -3596,6 +3611,35 @@ static enum gh__error_code do_sub_cmd__config(int argc, const char **argv)
35963611 return ec ;
35973612}
35983613
3614+ static enum gh__error_code do_sub_cmd__endpoint (int argc , const char * * argv )
3615+ {
3616+ struct gh__response_status status = GH__RESPONSE_STATUS_INIT ;
3617+ struct strbuf data = STRBUF_INIT ;
3618+ enum gh__error_code ec = GH__ERROR_CODE__OK ;
3619+ const char * endpoint ;
3620+
3621+ if (argc != 2 )
3622+ return GH__ERROR_CODE__ERROR ;
3623+ endpoint = argv [1 ];
3624+
3625+ trace2_cmd_mode (endpoint );
3626+
3627+ finish_init (0 );
3628+
3629+ do__http_get__simple_endpoint (& status , & data , endpoint , endpoint );
3630+ ec = status .ec ;
3631+
3632+ if (ec == GH__ERROR_CODE__OK )
3633+ printf ("%s\n" , data .buf );
3634+ else
3635+ error ("config: %s" , status .error_message .buf );
3636+
3637+ gh__response_status__release (& status );
3638+ strbuf_release (& data );
3639+
3640+ return ec ;
3641+ }
3642+
35993643/*
36003644 * Read a list of objects from stdin and fetch them as a series of
36013645 * single object HTTP GET requests.
@@ -4087,6 +4131,9 @@ static enum gh__error_code do_sub_cmd(int argc, const char **argv)
40874131 if (!strcmp (argv [0 ], "config" ))
40884132 return do_sub_cmd__config (argc , argv );
40894133
4134+ if (!strcmp (argv [0 ], "endpoint" ))
4135+ return do_sub_cmd__endpoint (argc , argv );
4136+
40904137 if (!strcmp (argv [0 ], "prefetch" ))
40914138 return do_sub_cmd__prefetch (argc , argv );
40924139
0 commit comments