fetch-pack: write effective filter to trace2

Administrators of a managed Git environment (like the one at $DAYJOB) might want to quantify the performance change of fetches with and without filters from the client's point of view, and also detect if a server does not support it. Therefore, log the filter information being sent to the server whenever a fetch (or clone) occurs. Note that this is not necessarily the same as what's specified on the CLI, because during a fetch, the configured filter is used whenever a filter is not specified on the CLI. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jul 26, 2022 at 09:27 UTC 1007557a4e6faf93339f5477b69bd42979c20a30
1 file changed +26 -14
fetch-pack.c
+26 -14
@@ -292,6 +292,29 @@ static void mark_tips(struct fetch_negotiator *negotiator,
292 return;
293 }
294
295 +static void send_filter(struct fetch_pack_args *args,
296 + struct strbuf *req_buf,
297 + int server_supports_filter)
298 +{
299 + if (args->filter_options.choice) {
300 + const char *spec =
301 + expand_list_objects_filter_spec(&args->filter_options);
302 + if (server_supports_filter) {
303 + print_verbose(args, _("Server supports filter"));
304 + packet_buf_write(req_buf, "filter %s", spec);
305 + trace2_data_string("fetch", the_repository,
306 + "filter/effective", spec);
307 + } else {
308 + warning("filtering not recognized by server, ignoring");
309 + trace2_data_string("fetch", the_repository,
310 + "filter/unsupported", spec);
311 + }
312 + } else {
313 + trace2_data_string("fetch", the_repository,
314 + "filter/none", "");
315 + }
316 +}
317 +
318 static int find_common(struct fetch_negotiator *negotiator,
319 struct fetch_pack_args *args,
320 int fd[2], struct object_id *result_oid,
@@ -389,11 +412,7 @@ static int find_common(struct fetch_negotiator *negotiator,
412 packet_buf_write(&req_buf, "deepen-not %s", s->string);
413 }
414 }
392 - if (server_supports_filtering && args->filter_options.choice) {
393 - const char *spec =
394 - expand_list_objects_filter_spec(&args->filter_options);
395 - packet_buf_write(&req_buf, "filter %s", spec);
396 - }
415 + send_filter(args, &req_buf, server_supports_filtering);
416 packet_buf_flush(&req_buf);
417 state_len = req_buf.len;
418
@@ -1323,15 +1342,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1342 die(_("Server does not support shallow requests"));
1343
1344 /* Add filter */
1326 - if (server_supports_feature("fetch", "filter", 0) &&
1327 - args->filter_options.choice) {
1328 - const char *spec =
1329 - expand_list_objects_filter_spec(&args->filter_options);
1330 - print_verbose(args, _("Server supports filter"));
1331 - packet_buf_write(&req_buf, "filter %s", spec);
1332 - } else if (args->filter_options.choice) {
1333 - warning("filtering not recognized by server, ignoring");
1334 - }
1345 + send_filter(args, &req_buf,
1346 + server_supports_feature("fetch", "filter", 0));
1347
1348 if (server_supports_feature("fetch", "packfile-uris", 0)) {
1349 int i;