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

Re: [PATCH v4 1/2] remote-curl: fall back to default hash outside repo

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 24, 2026, 04:25 UTC
Message-ID
<xmqqfr5p3lbe.fsf@gitster.g>
In-Reply-To
<20260324015734.18470-1-jayatheerthkulkarni2005@gmail.com>
K Jayatheerth <jayatheerthkulkarni2005@gmail.com> writes:
Show 6 quoted lines
> Instead of pushing a NULL-guard workaround down into parse_refspec(),
> fix this by mirroring the ls-remote workaround directly in
> remote-curl.c. If we are operating outside a repository, initialize
> the_hash_algo to GIT_HASH_DEFAULT. This keeps the HTTP transport
> consistent with non-HTTP transports that execute in-process, preventing
> crashes without altering the generic refspec parsing logic.
Thanks.
Show 44 quoted lines
>
> Reported-by: Jo Liss <joliss@gmail.com>
> Helped-by: Jeff King <peff@peff.net>
> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
> ---
> Thanks Peff and Junio this has been informative.
> I understood a lot of things here.
>
>  remote-curl.c               | 5 +++++
>  t/t5551-http-fetch-smart.sh | 7 +++++++
>  2 files changed, 12 insertions(+)
>
> diff --git a/remote-curl.c b/remote-curl.c
> index 92e40bb682..60774af929 100644
> --- a/remote-curl.c
> +++ b/remote-curl.c
> @@ -1552,6 +1552,11 @@ int cmd_main(int argc, const char **argv)
>  		goto cleanup;
>  	}
>  
> +	/* yuck, see 9e89dcb66a (builtin/ls-remote: fall back to SHA1 outside
> +	 * of a repo, 2024-08-02) */
> +	if (nongit)
> +		repo_set_hash_algo(the_repository, GIT_HASH_DEFAULT);
> +
>  	options.verbosity = 1;
>  	options.progress = !!isatty(2);
>  	options.thin = 1;
> diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
> index 73cf531580..a26b6c2844 100755
> --- a/t/t5551-http-fetch-smart.sh
> +++ b/t/t5551-http-fetch-smart.sh
> @@ -782,4 +782,11 @@ test_expect_success 'tag following always works over v0 http' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success 'ls-remote outside repo does not segfault with fetch refspec' '
> +	nongit git \
> +		-c remote.origin.url="$HTTPD_URL/smart/repo.git" \
> +		-c remote.origin.fetch=anything \
> +		ls-remote origin
> +'
> +
>  test_done
Previous: K JayatheerthNext: Jeff King
Message 14 of 17 in “remote-curl: segfault parsing remote.<name>.fetch outside a repository”
  1. Jo LissMar 21, 2026
  2. remote-curl: set fallback hash algorithm outside repoK Jayatheerth, Mar 21, 2026
  3. brian m. carlsonMar 21, 2026
  4. refspec: safely parse refspecs outside a repositoryK Jayatheerth, Mar 22, 2026
  5. Junio C HamanoMar 22, 2026
  6. Jeff KingMar 22, 2026
  7. 1/2 refspec: safely parse refspecs outside a repositoryK Jayatheerth, Mar 22, 2026
  8. 2/2 refspec: fix typo in commentK Jayatheerth, Mar 22, 2026
  9. Junio C HamanoMar 23, 2026
  10. Jeff KingMar 23, 2026
  11. Junio C HamanoMar 23, 2026
  12. 1/2 remote-curl: fall back to default hash outside repoK Jayatheerth, Mar 24, 2026
  13. 2/2 refspec: fix typo in commentK Jayatheerth, Mar 24, 2026
  14. Junio C HamanoMar 24, 2026
  15. Jeff KingMar 21, 2026
  16. Junio C HamanoMar 22, 2026
  17. Jeff KingMar 22, 2026

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.