202
202
// [2] Documentation/technical/long-running-process-protocol.txt
203
203
// [3] See GIT_TRACE_PACKET
204
204
//
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
+ //
205
211
//////////////////////////////////////////////////////////////////
206
212
207
213
#include "git-compat-util.h"
@@ -3121,18 +3127,20 @@ static void do_req__with_fallback(const char *url_component,
3121
3127
*
3122
3128
* Return server's response buffer. This is probably a raw JSON string.
3123
3129
*/
3124
- static void do__http_get__gvfs_config (struct gh__response_status * status ,
3125
- struct strbuf * config_data )
3130
+ static void do__http_get__simple_endpoint (struct gh__response_status * status ,
3131
+ struct strbuf * response ,
3132
+ const char * endpoint ,
3133
+ const char * tr2_label )
3126
3134
{
3127
3135
struct gh__request_params params = GH__REQUEST_PARAMS_INIT ;
3128
3136
3129
- strbuf_addstr (& params .tr2_label , "GET/config" );
3137
+ strbuf_addstr (& params .tr2_label , tr2_label );
3130
3138
3131
3139
params .b_is_post = 0 ;
3132
3140
params .b_write_to_file = 0 ;
3133
3141
/* cache-servers do not handle gvfs/config REST calls */
3134
3142
params .b_permit_cache_server_if_defined = 0 ;
3135
- params .buffer = config_data ;
3143
+ params .buffer = response ;
3136
3144
params .objects_mode = GH__OBJECTS_MODE__NONE ;
3137
3145
3138
3146
params .object_count = 1 ; /* a bit of a lie */
@@ -3154,15 +3162,22 @@ static void do__http_get__gvfs_config(struct gh__response_status *status,
3154
3162
* see any need to report progress on the upload side of
3155
3163
* the GET. So just report progress on the download side.
3156
3164
*/
3157
- strbuf_addstr (& params .progress_base_phase3_msg ,
3158
- "Receiving gvfs/config" );
3165
+ strbuf_addf (& params .progress_base_phase3_msg ,
3166
+ "Receiving %s" , endpoint );
3159
3167
}
3160
3168
3161
- do_req__with_fallback ("gvfs/config" , & params , status );
3169
+ do_req__with_fallback (endpoint , & params , status );
3162
3170
3163
3171
gh__request_params__release (& params );
3164
3172
}
3165
3173
3174
+ static void do__http_get__gvfs_config (struct gh__response_status * status ,
3175
+ struct strbuf * config_data )
3176
+ {
3177
+ do__http_get__simple_endpoint (status , config_data , "gvfs/config" ,
3178
+ "GET/config" );
3179
+ }
3180
+
3166
3181
static void setup_gvfs_objects_progress (struct gh__request_params * params ,
3167
3182
unsigned long num , unsigned long den )
3168
3183
{
@@ -3607,6 +3622,35 @@ static enum gh__error_code do_sub_cmd__config(int argc, const char **argv)
3607
3622
return ec ;
3608
3623
}
3609
3624
3625
+ static enum gh__error_code do_sub_cmd__endpoint (int argc , const char * * argv )
3626
+ {
3627
+ struct gh__response_status status = GH__RESPONSE_STATUS_INIT ;
3628
+ struct strbuf data = STRBUF_INIT ;
3629
+ enum gh__error_code ec = GH__ERROR_CODE__OK ;
3630
+ const char * endpoint ;
3631
+
3632
+ if (argc != 2 )
3633
+ return GH__ERROR_CODE__ERROR ;
3634
+ endpoint = argv [1 ];
3635
+
3636
+ trace2_cmd_mode (endpoint );
3637
+
3638
+ finish_init (0 );
3639
+
3640
+ do__http_get__simple_endpoint (& status , & data , endpoint , endpoint );
3641
+ ec = status .ec ;
3642
+
3643
+ if (ec == GH__ERROR_CODE__OK )
3644
+ printf ("%s\n" , data .buf );
3645
+ else
3646
+ error ("config: %s" , status .error_message .buf );
3647
+
3648
+ gh__response_status__release (& status );
3649
+ strbuf_release (& data );
3650
+
3651
+ return ec ;
3652
+ }
3653
+
3610
3654
/*
3611
3655
* Read a list of objects from stdin and fetch them as a series of
3612
3656
* single object HTTP GET requests.
@@ -4098,6 +4142,9 @@ static enum gh__error_code do_sub_cmd(int argc, const char **argv)
4098
4142
if (!strcmp (argv [0 ], "config" ))
4099
4143
return do_sub_cmd__config (argc , argv );
4100
4144
4145
+ if (!strcmp (argv [0 ], "endpoint" ))
4146
+ return do_sub_cmd__endpoint (argc , argv );
4147
+
4101
4148
if (!strcmp (argv [0 ], "prefetch" ))
4102
4149
return do_sub_cmd__prefetch (argc , argv );
4103
4150
0 commit comments