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

Re: [PATCH 2/2] grep: use grep_and_expr() in compile_pattern_and()

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 6, 2022, 22:14 UTC
Message-ID
<xmqqlezsbjfs.fsf@gitster.g>
In-Reply-To
<71bd2d1bcc6486f2e21c649708d3f4fa67dc162c.1641498525.git.me@ttaylorr.com>
Taylor Blau <me@ttaylorr.com> writes:
Show 39 quoted lines
> In a similar spirit as a previous commit, use the new `grep_and_expr()`
> to construct the AND node in `compile_pattern_and()`.
>
> Unlike the aforementioned previous commit, this is not about code
> duplication, since this is the only spot in grep.c where an AND node is
> constructed. Rather, this is about visual consistency with the other
> `compile_pattern_xyz()` functions.
>
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
>  grep.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/grep.c b/grep.c
> index d772fe6cc5..ab4fdacaed 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -619,6 +619,11 @@ static struct grep_expr *grep_or_expr(struct grep_expr *left, struct grep_expr *
>  	return grep_binexp(GREP_NODE_OR, left, right);
>  }
>  
> +static struct grep_expr *grep_and_expr(struct grep_expr *left, struct grep_expr *right)
> +{
> +	return grep_binexp(GREP_NODE_AND, left, right);
> +}
> +
>  static struct grep_expr *compile_pattern_or(struct grep_pat **);
>  static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
>  {
> @@ -687,11 +692,7 @@ static struct grep_expr *compile_pattern_and(struct grep_pat **list)
>  		y = compile_pattern_and(list);
>  		if (!y)
>  			die("--and not followed by pattern expression");
> -		CALLOC_ARRAY(z, 1);
> -		z->node = GREP_NODE_AND;
> -		z->u.binary.left = x;
> -		z->u.binary.right = y;
> -		return z;
> +		return grep_and_expr(x, y);

You'd need to remove 'z' from the function to avoid getting yelled at by your compiler for unused variable.

Previous: Taylor BlauNext: Taylor Blau
Message 6 of 13 in “grep: use grep_or_expr() in compile_pattern_or()”
  1. 1/2 grep: use grep_or_expr() in compile_pattern_or()René Scharfe, Jan 6, 2022
  2. 2/2 grep: use grep_not_expr() in compile_pattern_not()René Scharfe, Jan 6, 2022
  3. 0/2 grep: introduce and use grep_and_expr()Taylor Blau, Jan 6, 2022
  4. 1/2 grep: extract grep_binexp() from grep_or_expr()Taylor Blau, Jan 6, 2022
  5. 2/2 grep: use grep_and_expr() in compile_pattern_and()Taylor Blau, Jan 6, 2022
  6. Junio C HamanoJan 6, 2022
  7. Taylor BlauJan 6, 2022
  8. 0/2 grep: introduce and use grep_and_expr()Taylor Blau, Jan 6, 2022
  9. 1/2 grep: extract grep_binexp() from grep_or_expr()Taylor Blau, Jan 6, 2022
  10. 2/2 grep: use grep_and_expr() in compile_pattern_and()Taylor Blau, Jan 6, 2022
  11. René ScharfeJan 7, 2022
  12. Taylor BlauJan 7, 2022
  13. René ScharfeJan 7, 2022

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.