git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] fetch-pack: write effective filter to trace2

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 18, 2022, 19:47 UTC
Message-ID
<xmqqwncadwzh.fsf@gitster.g>
In-Reply-To
<20220718170027.3993042-1-jonathantanmy@google.com>
Jonathan Tan <jonathantanmy@google.com> writes:
Show 22 quoted lines
> +static void write_and_trace_filter(struct fetch_pack_args *args,
> +				   struct strbuf *req_buf,
> +				   int server_supports_filter)
> +{
> +	if (args->filter_options.choice) {
> +		const char *spec =
> +			expand_list_objects_filter_spec(&args->filter_options);
> +		if (server_supports_filter) {
> +			print_verbose(args, _("Server supports filter"));
> +			packet_buf_write(req_buf, "filter %s", spec);
> +			trace2_data_string("fetch", the_repository,
> +					   "filter/effective", spec);
> +		} else {
> +			warning("filtering not recognized by server, ignoring");
> +			trace2_data_string("fetch", the_repository,
> +					   "filter/unsupported", spec);
> +		}
> +	} else {
> +		trace2_data_string("fetch", the_repository,
> +				   "filter/none", "");
> +	}
> +}

The previous round already had the same issue, but this makes it even worse by introducing a function that makes it clear that it mixes quite unrelated two features (i.e. write the filter to the other end, which MUST be done for correct operation of the protocol, and write a log to trace2, which may not be even necessary when we are not logging at all).

Can we make the code a bit better structured, I have to wonder, by having two separate phases of processing, one for the operation proper, and the other for the logging/debugging?

In a sense, we can say that the only purpose this helper function is to tell the server end what the filter we use is by renaming it; it is OK to have debugging statements and logging code as part of the implementation of such a function.

I actually like that direction better. A helper function may exist *ONLY* to trace, in which case, having "trace" in its name would make perfect sense. A helper function may exist to perform the real work, but it may log what it did to perform the real work as well. I think the latter shouldn't have "trace" in its name at all, or our helpers will all be called do_FOO_and_trace(), do_BAR_and_debug(), etc., which is nonsense. Just calling do_FOO() and do_BAR(), and then having them log or trace as needed, is fine.

Will queue, anyway.
Thanks.
Previous: Jonathan TanNext: Junio C Hamano
Message 12 of 15 in “fetch-pack: write effective filter to trace2”
  1. fetch-pack: write effective filter to trace2Jonathan Tan, Jul 15, 2022
  2. Jeff HostetlerJul 15, 2022
  3. Junio C HamanoJul 15, 2022
  4. Jonathan TanJul 15, 2022
  5. Junio C HamanoJul 15, 2022
  6. Jonathan TanJul 15, 2022
  7. Jeff HostetlerJul 18, 2022
  8. Junio C HamanoJul 18, 2022
  9. Jonathan TanJul 18, 2022
  10. Junio C HamanoJul 18, 2022
  11. fetch-pack: write effective filter to trace2Jonathan Tan, Jul 18, 2022
  12. Junio C HamanoJul 18, 2022
  13. Junio C HamanoJul 25, 2022
  14. Jonathan TanJul 26, 2022
  15. fetch-pack: write effective filter to trace2Jonathan Tan, Jul 26, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.