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

Re: [PATCH v2 2/4] diff --no-index: die on error reading stdin

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 5, 2023, 21:18 UTC
Message-ID
<xmqqilayxdjx.fsf@gitster.g>
In-Reply-To
<be1d666769f2d6dd028c7d5ade0e9f563e953ab5.1688586536.git.phillip.wood@dunelm.org.uk>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 13 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> If there is an error when reading from stdin then "diff --no-index"
> prints an error message but continues to try and diff a file named "-"
> resulting in an error message that looks like
>
>     error: error while reading from stdin: Invalid argument
>     fatal: stat '-': No such file or directory
>
> assuming that no file named "-" exists. If such a file exists it prints
> the first error message and generates the diff from that file which is
> not what the user wanted. Instead just die() straight away if we cannot
> read from stdin.
Makes sense.
Show 32 quoted lines
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  diff-no-index.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/diff-no-index.c b/diff-no-index.c
> index 77462ac2a9..4470e0271d 100644
> --- a/diff-no-index.c
> +++ b/diff-no-index.c
> @@ -60,20 +60,19 @@ static int get_mode(const char *path, int *mode)
>  	return 0;
>  }
>  
> -static int populate_from_stdin(struct diff_filespec *s)
> +static void populate_from_stdin(struct diff_filespec *s)
>  {
>  	struct strbuf buf = STRBUF_INIT;
>  	size_t size = 0;
>  
>  	if (strbuf_read(&buf, 0, 0) < 0)
> -		return error_errno("error while reading from stdin");
> +		die_errno("error while reading from stdin");
>  
>  	s->should_munmap = 0;
>  	s->data = strbuf_detach(&buf, &size);
>  	s->size = size;
>  	s->should_free = 1;
>  	s->is_stdin = 1;
> -	return 0;
>  }
>  
>  static struct diff_filespec *noindex_filespec(const char *name, int mode)
Previous: Phillip Wood
Message 17 of 17 in “diff --no-index: support reading from named pipes”
  1. 0/3 diff --no-index: support reading from named pipesPhillip Wood, Jun 27, 2023
  2. 1/3 diff --no-index: die on error reading stdinPhillip Wood, Jun 27, 2023
  3. 2/3 t4054: test diff --no-index with stdinPhillip Wood, Jun 27, 2023
  4. 3/3 diff --no-index: support reading from named pipesPhillip Wood, Jun 27, 2023
  5. Junio C HamanoJun 27, 2023
  6. Phillip WoodJun 28, 2023
  7. 0/4 diff --no-index: support reading from named pipesPhillip Wood, Jul 5, 2023
  8. 1/4 diff --no-index: refuse to compare stdin to a directoryPhillip Wood, Jul 5, 2023
  9. Junio C HamanoJul 5, 2023
  10. 3/4 t4054: test diff --no-index with stdinPhillip Wood, Jul 5, 2023
  11. Junio C HamanoJul 5, 2023
  12. 4/4 diff --no-index: support reading from named pipesPhillip Wood, Jul 5, 2023
  13. Junio C HamanoJul 5, 2023
  14. Jeff KingAug 9, 2023
  15. Phillip WoodAug 10, 2023
  16. 2/4 diff --no-index: die on error reading stdinPhillip Wood, Jul 5, 2023
  17. Junio C HamanoJul 5, 2023

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.