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

Re: [PATCH 2/3] diff: omit found pointer from emit_callback

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 8, 2016, 20:53 UTC
Message-ID
<xmqqpooef706.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160907233648.5162-4-sbeller@google.com>
Stefan Beller <sbeller@google.com> writes:
Show 11 quoted lines
> diff --git a/diff.c b/diff.c
> index 4a6501c..79ad91d 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -354,7 +354,6 @@ struct emit_callback {
>  	const char **label_path;
>  	struct diff_words_data *diff_words;
>  	struct diff_options *opt;
> -	int *found_changesp;
>  	struct strbuf *header;
>  };

I briefly wondered if we have some callsites that do not want o->found_changes to be modified (hence pointing this field at elsewhere), but the fact that you can _remove_ this field means that there is no such use case, which is good.

Show 20 quoted lines
> @@ -722,7 +721,6 @@ static void emit_rewrite_diff(const char *name_a,
>  
>  	memset(&ecbdata, 0, sizeof(ecbdata));
>  	ecbdata.color_diff = want_color(o->use_color);
> -	ecbdata.found_changesp = &o->found_changes;
>  	ecbdata.ws_rule = whitespace_rule(name_b);
>  	ecbdata.opt = o;
>  	if (ecbdata.ws_rule & WS_BLANK_AT_EOF) {
> @@ -1215,13 +1213,13 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
>  	const char *reset = diff_get_color(ecbdata->color_diff, DIFF_RESET);
>  	struct diff_options *o = ecbdata->opt;
>  	const char *line_prefix = diff_line_prefix(o);
> +	o->found_changes = 1;
>  
>  	if (ecbdata->header) {
>  		fprintf(o->file, "%s", ecbdata->header->buf);
>  		strbuf_reset(ecbdata->header);
>  		ecbdata->header = NULL;
>  	}
> -	*(ecbdata->found_changesp) = 1;

Is there a good reason to move the assignment up? "The fact that this function was called even once means we found some change" is probably a good argument, but then I'd prefer to have a blank before it to separate it (the first statement) from the block of decls.

No need to resend.  Thanks.
Previous: Stefan BellerNext: Stefan Beller
Message 6 of 9 in “preparatory diff improvements for moved color detection”
  1. 0/3 preparatory diff improvements for moved color detectionStefan Beller, Sep 7, 2016
  2. 1/3 diff.c: use diff_options directlyStefan Beller, Sep 7, 2016
  3. Jacob KellerSep 8, 2016
  4. 1/2 diff: omit found pointer from emit_callbackStefan Beller, Sep 7, 2016
  5. 2/3 diff: omit found pointer from emit_callbackStefan Beller, Sep 7, 2016
  6. Junio C HamanoSep 8, 2016
  7. 3/3 diff: remove dead codeStefan Beller, Sep 7, 2016
  8. Junio C HamanoSep 8, 2016
  9. 2/2 diff: remove dead codeStefan Beller, Sep 7, 2016

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.