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
@@ -3139,18 +3145,20 @@ static void do_req__with_fallback(const char *url_component,
31393145 *
31403146 * Return server's response buffer. This is probably a raw JSON string.
31413147 */
3142- static void do__http_get__gvfs_config (struct gh__response_status * status ,
3143- struct strbuf * config_data )
3148+ static void do__http_get__simple_endpoint (struct gh__response_status * status ,
3149+ struct strbuf * response ,
3150+ const char * endpoint ,
3151+ const char * tr2_label )
31443152{
31453153 struct gh__request_params params = GH__REQUEST_PARAMS_INIT ;
31463154
3147- strbuf_addstr (& params .tr2_label , "GET/config" );
3155+ strbuf_addstr (& params .tr2_label , tr2_label );
31483156
31493157 params .b_is_post = 0 ;
31503158 params .b_write_to_file = 0 ;
31513159 /* cache-servers do not handle gvfs/config REST calls */
31523160 params .b_permit_cache_server_if_defined = 0 ;
3153- params .buffer = config_data ;
3161+ params .buffer = response ;
31543162 params .objects_mode = GH__OBJECTS_MODE__NONE ;
31553163
31563164 params .object_count = 1 ; /* a bit of a lie */
@@ -3172,15 +3180,22 @@ static void do__http_get__gvfs_config(struct gh__response_status *status,
31723180 * see any need to report progress on the upload side of
31733181 * the GET. So just report progress on the download side.
31743182 */
3175- strbuf_addstr (& params .progress_base_phase3_msg ,
3176- "Receiving gvfs/config" );
3183+ strbuf_addf (& params .progress_base_phase3_msg ,
3184+ "Receiving %s" , endpoint );
31773185 }
31783186
3179- do_req__with_fallback ("gvfs/config" , & params , status );
3187+ do_req__with_fallback (endpoint , & params , status );
31803188
31813189 gh__request_params__release (& params );
31823190}
31833191
3192+ static void do__http_get__gvfs_config (struct gh__response_status * status ,
3193+ struct strbuf * config_data )
3194+ {
3195+ do__http_get__simple_endpoint (status , config_data , "gvfs/config" ,
3196+ "GET/config" );
3197+ }
3198+
31843199static void setup_gvfs_objects_progress (struct gh__request_params * params ,
31853200 unsigned long num , unsigned long den )
31863201{
@@ -3625,6 +3640,35 @@ static enum gh__error_code do_sub_cmd__config(int argc UNUSED, const char **argv
36253640 return ec ;
36263641}
36273642
3643+ static enum gh__error_code do_sub_cmd__endpoint (int argc , const char * * argv )
3644+ {
3645+ struct gh__response_status status = GH__RESPONSE_STATUS_INIT ;
3646+ struct strbuf data = STRBUF_INIT ;
3647+ enum gh__error_code ec = GH__ERROR_CODE__OK ;
3648+ const char * endpoint ;
3649+
3650+ if (argc != 2 )
3651+ return GH__ERROR_CODE__ERROR ;
3652+ endpoint = argv [1 ];
3653+
3654+ trace2_cmd_mode (endpoint );
3655+
3656+ finish_init (0 );
3657+
3658+ do__http_get__simple_endpoint (& status , & data , endpoint , endpoint );
3659+ ec = status .ec ;
3660+
3661+ if (ec == GH__ERROR_CODE__OK )
3662+ printf ("%s\n" , data .buf );
3663+ else
3664+ error ("config: %s" , status .error_message .buf );
3665+
3666+ gh__response_status__release (& status );
3667+ strbuf_release (& data );
3668+
3669+ return ec ;
3670+ }
3671+
36283672/*
36293673 * Read a list of objects from stdin and fetch them as a series of
36303674 * single object HTTP GET requests.
@@ -4117,6 +4161,9 @@ static enum gh__error_code do_sub_cmd(int argc, const char **argv)
41174161 if (!strcmp (argv [0 ], "config" ))
41184162 return do_sub_cmd__config (argc , argv );
41194163
4164+ if (!strcmp (argv [0 ], "endpoint" ))
4165+ return do_sub_cmd__endpoint (argc , argv );
4166+
41204167 if (!strcmp (argv [0 ], "prefetch" ))
41214168 return do_sub_cmd__prefetch (argc , argv );
41224169
0 commit comments