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

Re: [PATCH 1/2] xdiff-interface: allow consume function to quit early by returning non-zero

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 15, 2011, 19:41 UTC
Message-ID
<7v39h2laxb.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1313376083-24713-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
What is this for? No explanation?
Show 25 quoted lines
> diff --git a/xdiff-interface.c b/xdiff-interface.c
> index 0e2c169..c5684b4 100644
> --- a/xdiff-interface.c
> +++ b/xdiff-interface.c
> @@ -56,7 +56,7 @@ int parse_hunk_header(char *line, int len,
>  	return -!!memcmp(cp, " @@", 3);
>  }
>  
> -static void consume_one(void *priv_, char *s, unsigned long size)
> +static int consume_one(void *priv_, char *s, unsigned long size)
>  {
>  	struct xdiff_emit_state *priv = priv_;
>  	char *ep;
> @@ -64,10 +64,12 @@ static void consume_one(void *priv_, char *s, unsigned long size)
>  		unsigned long this_size;
>  		ep = memchr(s, '\n', size);
>  		this_size = (ep == NULL) ? size : (ep - s + 1);
> -		priv->consume(priv->consume_callback_data, s, this_size);
> +		if (priv->consume(priv->consume_callback_data, s, this_size))
> +			return -1;
>  		size -= this_size;
>  		s += this_size;
>  	}
> +	return 0;
>  }

Returning a negative value implies that this is an error condition. Should all "non-zero" returns from ->consume necessarily be considered error?

The same comment applies to the new "return -1" in the rest of the patch.
Previous: Nguyen Thai Ngoc DuyNext: Nguyen Thai Ngoc Duy
Message 4 of 5 in “xdiff-interface: allow consume function to quit early by returning non-zero”
  1. 1/2 xdiff-interface: allow consume function to quit early by returning non-zeroNguyễn Thái Ngọc Duy, Aug 15, 2011
  2. 2/2 diffcore-pickaxe: terminate grepping as soon as it hitsNguyễn Thái Ngọc Duy, Aug 15, 2011
  3. Nguyen Thai Ngoc DuyAug 17, 2011
  4. Junio C HamanoAug 15, 2011
  5. Nguyen Thai Ngoc DuyAug 17, 2011

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.