Skip to content

Commit 1007557

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bbea4dc commit 1007557

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

fetch-pack.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,29 @@ static void mark_tips(struct fetch_negotiator *negotiator,
292292
return;
293293
}
294294

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+
295318
static int find_common(struct fetch_negotiator *negotiator,
296319
struct fetch_pack_args *args,
297320
int fd[2], struct object_id *result_oid,
@@ -389,11 +412,7 @@ static int find_common(struct fetch_negotiator *negotiator,
389412
packet_buf_write(&req_buf, "deepen-not %s", s->string);
390413
}
391414
}
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);
397416
packet_buf_flush(&req_buf);
398417
state_len = req_buf.len;
399418

@@ -1323,15 +1342,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
13231342
die(_("Server does not support shallow requests"));
13241343

13251344
/* 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));
13351347

13361348
if (server_supports_feature("fetch", "packfile-uris", 0)) {
13371349
int i;

0 commit comments

Comments
 (0)