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

[PATCH 0/2] builtin/grep.c: teach '-o', '--only-matching'

From
Taylor Blau <me@ttaylorr.com>
Date
May 5, 2018, 04:03 UTC
Message-ID
<cover.1525492696.git.me@ttaylorr.com>
Hi,

Attached is a series to teach 'git-grep(1)' how to respond to '--only-matching' (a-la GNU grep(1)'s --only-matching, including an '-o' synonym) to only print the matching component(s) of a line. It is based on v4 of tb/grep-colno, which was sent in [1].

This was suggested to me by Ævar in [2].

This change was fairly straightforward, as Ævar suggests in [3], with the only complication being that we must print a line header multiple times when there are >1 matches per-line. This requirement pushes the implementation towards the extraction of a show_line_header() function, and some minor changes in show_line() to reflect.

Thank you in advance for your review.

Thanks, Taylor

[1]: https://public-inbox.org/git/cover.1525488108.git.me@ttaylorr.com [2]: https://public-inbox.org/git/874lk2e4he.fsf@evledraar.gmail.com [3]: https://public-inbox.org/git/87in9ucsbb.fsf@evledraar.gmail.com

Taylor Blau (2):
  grep.c: extract show_line_header()
  builtin/grep.c: teach '-o', '--only-matching' to 'git-grep'
 Documentation/git-grep.txt |  6 +++-
 builtin/grep.c             |  1 +
 grep.c                     | 67 +++++++++++++++++++++++++-------------
 grep.h                     |  1 +
 t/t7810-grep.sh            | 33 +++++++++++++++++++
 5 files changed, 85 insertions(+), 23 deletions(-)

-- 2.17.0

Next: Taylor Blau
Message 1 of 14 in “builtin/grep.c: teach '-o', '--only-matching'”
  1. 0/2 builtin/grep.c: teach '-o', '--only-matching'Taylor Blau, May 5, 2018
  2. 1/2 grep.c: extract show_line_header()Taylor Blau, May 5, 2018
  3. Eric SunshineMay 5, 2018
  4. Taylor BlauMay 8, 2018
  5. 2/2 builtin/grep.c: teach '-o', '--only-matching' to 'git-grep'Taylor Blau, May 5, 2018
  6. Ævar Arnfjörð BjarmasonMay 5, 2018
  7. Jeff KingMay 8, 2018
  8. Taylor BlauMay 10, 2018
  9. Jeff KingMay 10, 2018
  10. Eric SunshineMay 5, 2018
  11. Taylor BlauMay 8, 2018
  12. 0/2 builtin/grep.c: teach '-o', '--only-matching'Taylor Blau, May 12, 2018
  13. 1/2 grep.c: extract show_line_header()Taylor Blau, May 12, 2018
  14. 2/2 builtin/grep.c: teach '-o', '--only-matching' to 'git-grep'Taylor Blau, May 12, 2018

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.