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

Re: [PATCH 1/4] filter_ref: avoid overwriting ref->old_sha1 with garbage

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 19, 2015, 21:09 UTC
Message-ID
<xmqq7fucitif.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20150319203451.GA7666@peff.net>
Jeff King <peff@peff.net> writes:
> I wonder if the thinking in the original was that it was our
> responsibility here to make sure that ref->old_sha1 was filled in.

I am reasonably sure that is the (perhaps mistaken) reasoning behind the use of old_sha1 as the second parameter to get_sha1_hex().

Show 5 quoted lines
> It is
> always filled in by the caller who gives us "sought", which makes sense
> to me (this matches the rest of the "sought" entries, which come from
> reading the remote's ref list, and of course must fill in old_sha1 from
> that list).

I see that sought is populated by reading the command line of "git fetch-pack", and for a 40-hex request ref->old_sha1 is already filled there, so I agree that it is redundant to try filling it in filter_refs().

Thanks.
Show 23 quoted lines
>  fetch-pack.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/fetch-pack.c b/fetch-pack.c
> index 655ee64..058c258 100644
> --- a/fetch-pack.c
> +++ b/fetch-pack.c
> @@ -544,10 +544,14 @@ static void filter_refs(struct fetch_pack_args *args,
>  	/* Append unmatched requests to the list */
>  	if (allow_tip_sha1_in_want) {
>  		for (i = 0; i < nr_sought; i++) {
> +			unsigned char sha1[20];
> +
>  			ref = sought[i];
>  			if (ref->matched)
>  				continue;
> -			if (get_sha1_hex(ref->name, ref->old_sha1))
> +			if (get_sha1_hex(ref->name, sha1) ||
> +			    ref->name[40] != '\0' ||
> +			    hashcmp(sha1, ref->old_sha1))
>  				continue;
>  
>  			ref->matched = 1;
Previous: Jeff KingNext: Jeff King
Message 11 of 14 in “Bug in fetch-pack.c, please confirm”
  1. Kyle J. McKayMar 15, 2015
  2. Junio C HamanoMar 15, 2015
  3. Junio C HamanoMar 15, 2015
  4. Kyle J. McKayMar 15, 2015
  5. Jeff KingMar 16, 2015
  6. Junio C HamanoMar 19, 2015
  7. Jeff KingMar 19, 2015
  8. Junio C HamanoMar 19, 2015
  9. Jeff KingMar 19, 2015
  10. 1/4 filter_ref: avoid overwriting ref->old_sha1 with garbageJeff King, Mar 19, 2015
  11. Junio C HamanoMar 19, 2015
  12. 2/4 filter_ref: make a copy of extra "sought" entriesJeff King, Mar 19, 2015
  13. 3/4 fetch_refs_via_pack: free extra copy of refsJeff King, Mar 19, 2015
  14. 4/4 fetch-pack: remove dead assignment to ref->new_sha1Jeff King, Mar 19, 2015

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.