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

Re: [PATCH 1/3] grep: prepare for new header field filter

From
Jeff King <peff@peff.net>
Date
Sep 29, 2012, 05:22 UTC
Message-ID
<20120929052202.GA3330@sigill.intra.peff.net>
In-Reply-To
<1348893689-20240-2-git-send-email-pclouds@gmail.com>
On Sat, Sep 29, 2012 at 11:41:27AM +0700, Nguyen Thai Ngoc Duy wrote:
Show 17 quoted lines
> diff --git a/grep.c b/grep.c
> index 898be6e..8d73995 100644
> --- a/grep.c
> +++ b/grep.c
> @@ -720,7 +720,14 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
>  		if (strncmp(bol, field, len))
>  			return 0;
>  		bol += len;
> -		saved_ch = strip_timestamp(bol, &eol);
> +		switch (p->field) {
> +		case GREP_HEADER_AUTHOR:
> +		case GREP_HEADER_COMMITTER:
> +			saved_ch = strip_timestamp(bol, &eol);
> +			break;
> +		default:
> +			break;
> +		}

Reading this hunk, I wondered what happens to saved_ch if we do not set it here. Fortunately it is initialized to 0, as we already have to handle the non-header case. Then later we do this, which does introduce a new condition (saved_ch was not set, but we trigger the first half of the conditional):

      if (p->token == GREP_PATTERN_HEAD && saved_ch)
                *eol = saved_ch;

However, the second half of that conditional (which previously was only triggered when we tried to split the timestamp, but there was a bogus line with no ">" on it) prevents us from overwriting *eol.

So I think it is good, but it was non-obvious enough that I wanted to save other reviewers from investigating it. The rest of the patch looks good to me, as well.

-Peff
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 14 of 25 in “revision: add --reflog-message=<pattern> to grep reflog messages”
  1. revision: add --reflog-message=<pattern> to grep reflog messagesNguyễn Thái Ngọc Duy, Sep 26, 2012
  2. Junio C HamanoSep 26, 2012
  3. Nguyen Thai Ngoc DuySep 26, 2012
  4. Junio C HamanoSep 26, 2012
  5. revision: add --reflog-message to grep reflog messagesNguyễn Thái Ngọc Duy, Sep 27, 2012
  6. Junio C HamanoSep 27, 2012
  7. Jeff KingSep 27, 2012
  8. Junio C HamanoSep 27, 2012
  9. 1/3 grep: generalize header grep code to accept arbitrary headersNguyễn Thái Ngọc Duy, Sep 28, 2012
  10. 2/3 revision: add --grep-reflog to filter commits by reflog messagesNguyễn Thái Ngọc Duy, Sep 28, 2012
  11. Junio C HamanoSep 28, 2012
  12. Nguyễn Thái Ngọc DuySep 29, 2012
  13. 1/3 grep: prepare for new header field filterNguyễn Thái Ngọc Duy, Sep 29, 2012
  14. Jeff KingSep 29, 2012
  15. 2/3 revision: add --grep-reflog to filter commits by reflog messagesNguyễn Thái Ngọc Duy, Sep 29, 2012
  16. Jeff KingSep 29, 2012
  17. Junio C HamanoSep 29, 2012
  18. Nguyen Thai Ngoc DuySep 29, 2012
  19. Junio C HamanoSep 29, 2012
  20. Nguyen Thai Ngoc DuySep 30, 2012
  21. Jeff KingSep 29, 2012
  22. 3/3 revision: make --grep search in notes too if shownNguyễn Thái Ngọc Duy, Sep 29, 2012
  23. Junio C HamanoSep 29, 2012
  24. 3/3 revision: make --grep search in notes too if shownNguyễn Thái Ngọc Duy, Sep 28, 2012
  25. Junio C HamanoSep 28, 2012

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.