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

Re: [PATCH 1/2] fetch-pack: call prepare_shallow_info only if v0

From
Jeff King <peff@peff.net>
Date
Mar 26, 2019, 05:00 UTC
Message-ID
<20190326050011.GA1933@sigill.intra.peff.net>
In-Reply-To
<d2eb101709cc9b300e38151b14c97f96a2b14188.1553546216.git.jonathantanmy@google.com>
On Mon, Mar 25, 2019 at 01:43:22PM -0700, Jonathan Tan wrote:
Show 8 quoted lines
> In fetch_pack(), be clearer that there is no shallow information before
> the fetch when v2 is used - memset the struct shallow_info to 0 instead
> of calling prepare_shallow_info().
> 
> This patch is in preparation for a future patch in which a v2 fetch
> might call prepare_shallow_info() after shallow info has been retrieved
> during the fetch, so I needed to ensure that prepare_shallow_info() is
> not called before the fetch.
Makes sense.
I wondered here:
Show 16 quoted lines
> diff --git a/fetch-pack.c b/fetch-pack.c
> index e69993b2eb..a0eb268dfc 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -1648,13 +1648,17 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
>  		packet_flush(fd[1]);
>  		die(_("no matching remote head"));
>  	}
> -	prepare_shallow_info(&si, shallow);
> -	if (version == protocol_v2)
> +	if (version == protocol_v2) {
> +		if (shallow && shallow->nr)
> +			BUG("Protocol V2 does not provide shallows at this point in the fetch");
> +		memset(&si, 0, sizeof(si));
>  		ref_cpy = do_fetch_pack_v2(args, fd, ref, sought, nr_sought,
>  					   pack_lockfile);

...who actually might set "shallow". Specifically, I was curious whether a v2 server could erroneously send us shallow lines, which would trigger our BUG(), when in fact we should be complaining about the server.

But the answer is no, they have no opportunity. AFAICT, this would only be set by a call to get_remote_heads(), which we do only for v0/v1 protocols. So there's no way to trigger the BUG. Good.

-Peff
Previous: Jonathan TanNext: Jonathan Tan
Message 3 of 18 in “Last big GIT_TEST_PROTOCOL_VERSION=2 fix, hopefully”
  1. 0/2 Last big GIT_TEST_PROTOCOL_VERSION=2 fix, hopefullyJonathan Tan, Mar 25, 2019
  2. 1/2 fetch-pack: call prepare_shallow_info only if v0Jonathan Tan, Mar 25, 2019
  3. Jeff KingMar 26, 2019
  4. 2/2 fetch-pack: respect --no-update-shallow in v2Jonathan Tan, Mar 25, 2019
  5. Jeff KingMar 26, 2019
  6. Duy NguyenMar 26, 2019
  7. Jeff KingMar 26, 2019
  8. Duy NguyenMar 26, 2019
  9. Jonathan TanMar 26, 2019
  10. Jeff KingMar 26, 2019
  11. 0/2 Last big GIT_TEST_PROTOCOL_VERSION=2 fix, hopefullyJonathan Tan, Mar 26, 2019
  12. 1/2 fetch-pack: call prepare_shallow_info only if v0Jonathan Tan, Mar 26, 2019
  13. 2/2 fetch-pack: respect --no-update-shallow in v2Jonathan Tan, Mar 26, 2019
  14. Jeff KingMar 26, 2019
  15. Jeff KingMar 26, 2019
  16. 0/2 Last big GIT_TEST_PROTOCOL_VERSION=2 fix, hopefullyJonathan Tan, Mar 26, 2019
  17. 1/2 fetch-pack: call prepare_shallow_info only if v0Jonathan Tan, Mar 26, 2019
  18. 2/2 fetch-pack: respect --no-update-shallow in v2Jonathan Tan, Mar 26, 2019

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.