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

Re: [PATCH 2/2] checkout-index: omit entries with no tempname from --temp output

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 9, 2021, 21:35 UTC
Message-ID
<xmqqmtwczzyv.fsf@gitster.c.googlers.com>
In-Reply-To
<1275701345b7e198ec83ad4fdcc2dda6d9775ef3.1612812581.git.matheus.bernardino@usp.br>
Matheus Tavares <matheus.bernardino@usp.br> writes:
Show 16 quoted lines
> With --temp (or --stage=all, which implies --temp), checkout-index
> writes a list to stdout associating temporary file names to the entries'
> names. But if it fails to write an entry, and the failure happens before
> even assigning a temporary filename to that entry, we get an odd output
> line. This can be seen when trying to check out a symlink whose blob is
> missing:
>
> $ missing_blob=$(git hash-object --stdin </dev/null)
> $ git update-index --add --cacheinfo 120000,$missing_blob,foo
> $ git checkout-index --temp foo
> error: unable to read sha1 file of foo (e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)
>         foo
>
> The 'TAB foo' line is not much useful and it might break scripts that
> expect the 'tempname TAB foo' output. So let's omit such entries from
> the stdout list (but leaving the error message on stderr).
Makes quite a lot of sense.
Show 44 quoted lines
>  	if (CHECKOUT_ALL == checkout_stage) {
> -		for (i = 1; i < 4; i++) {
> -			if (i > 1)
> -				putchar(' ');
> -			if (topath[i][0])
> -				fputs(topath[i], stdout);
> -			else
> -				putchar('.');
> +		for (i = 1; i < 4; i++)
> +			if (topath[i][0]) {
> +				have_tempname = 1;
> +				break;
> +			}
> +
> +		if (have_tempname) {
> +			for (i = 1; i < 4; i++) {
> +				if (i > 1)
> +					putchar(' ');
> +				if (topath[i][0])
> +					fputs(topath[i], stdout);
> +				else
> +					putchar('.');
> +			}
>  		}
> -	} else
> +	} else if (topath[checkout_stage][0]) {
> +		have_tempname = 1;
>  		fputs(topath[checkout_stage], stdout);
> +	}
>  
> -	putchar('\t');
> -	write_name_quoted_relative(name, prefix, stdout,
> -				   nul_term_line ? '\0' : '\n');
> +	if (have_tempname) {
> +		putchar('\t');
> +		write_name_quoted_relative(name, prefix, stdout,
> +					   nul_term_line ? '\0' : '\n');
>  
> -	for (i = 0; i < 4; i++) {
> -		topath[i][0] = 0;
> +		for (i = 0; i < 4; i++) {
> +			topath[i][0] = 0;
> +		}
>  	}

Hmph, is topath[][] array used after this function gets called and in what way? Whether have_tempname is true or not, wouldn't we want to clear it?

Thanks.
Previous: Matheus TavaresNext: Matheus Tavares Bernardino
Message 6 of 15 in “checkout-index: some cleanups to --temp and --prefix outputs”
  1. 0/2 checkout-index: some cleanups to --temp and --prefix outputsMatheus Tavares, Feb 8, 2021
  2. 1/2 write_entry(): fix misuses of `path` in error messagesMatheus Tavares, Feb 8, 2021
  3. Junio C HamanoFeb 9, 2021
  4. Matheus Tavares BernardinoFeb 9, 2021
  5. 2/2 checkout-index: omit entries with no tempname from --temp outputMatheus Tavares, Feb 8, 2021
  6. Junio C HamanoFeb 9, 2021
  7. Matheus Tavares BernardinoFeb 9, 2021
  8. Junio C HamanoFeb 10, 2021
  9. 0/2 checkout-index: some cleanups to --temp and --prefix outputsMatheus Tavares, Feb 15, 2021
  10. 1/2 write_entry(): fix misuses of `path` in error messagesMatheus Tavares, Feb 15, 2021
  11. Junio C HamanoFeb 16, 2021
  12. 2/2 checkout-index: omit entries with no tempname from --temp outputMatheus Tavares, Feb 15, 2021
  13. 0/2 checkout-index: some cleanups to --temp and --prefix outputsMatheus Tavares, Feb 16, 2021
  14. 2/2 checkout-index: omit entries with no tempname from --temp outputMatheus Tavares, Feb 16, 2021
  15. 1/2 write_entry(): fix misuses of `path` in error messagesMatheus Tavares, Feb 16, 2021

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.