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

Re: [PATCH] grep: add known breakage of coloring when using extended patterns

From
Junio C Hamano <gitster@pobox.com>
Date
May 2, 2011, 22:04 UTC
Message-ID
<7vwri8kbcy.fsf@alter.siamese.dyndns.org>
In-Reply-To
<4DBF1D2A.6030807@lsrfire.ath.cx>
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
Show 7 quoted lines
> Aggregating the set of matching characters and passing them back
> during expression evaluation can be more efficient, yes, as it would
> avoid calling regexec() on the printed lines again only to find out
> what to color.  But I wouldn't call it easy.  E.g. how to return the
> set of matching characters in the following case?
>
> 	$ git grep --color -e foo --and -e bar

I would naïvely expect each of the "grep_expr" in the parsed grep tree to have not just a one-bit "hit", but rm_so/rm_eo pair, but as I said, I was asleep while "coloring the parts that matched" discussion was in progress ;-)

But
> Also GNU grep doesn't only color the first sufficient match.
> E.g. this will color both b and d:
>
> 	$ echo abcde | grep --color -e b -e d

that is probably a useful thing to have. Obviously, my suggestion should optimize away the match with 'd' to begin with, so keeping rm_so/rm_eo pair would not help painting d at all. Worse yet, I would expect that

	$ echo abcdeabcde | grep --color -e b -e d

would need to paint all occurrences for such a purpose, so obviously you would need an extra pass to find all potential hits. Ugly and makes me personally wonder if it is really worth it, but the user is explicitly asking for --color and is prepared to pay the price, so it probably is Ok.

Previous: René ScharfeNext: René Scharfe
Message 7 of 8 in “grep: add known breakage of coloring when using extended patterns”
  1. grep: add known breakage of coloring when using extended patternsBert Wesarg, May 2, 2011
  2. Johannes SixtMay 2, 2011
  3. Bert WesargMay 2, 2011
  4. René ScharfeMay 2, 2011
  5. Junio C HamanoMay 2, 2011
  6. René ScharfeMay 2, 2011
  7. Junio C HamanoMay 2, 2011
  8. René ScharfeMay 3, 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.