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

Re: [PATCH/RFC 0/4] grep: support to match by line number

From
Bert Wesarg <bert.wesarg@googlemail.com>
Date
May 2, 2011, 12:20 UTC
Message-ID
<BANLkTikvYLKKj_Wd0EOxZh+vANxju4CV6Q@mail.gmail.com>
In-Reply-To
<BANLkTi=NOaWN56qBACoTE2WQWFM3rHXfWA@mail.gmail.com>
On Mon, May 2, 2011 at 13:54, Sverre Rabbelier <srabbelier@gmail.com> wrote:
Show 10 quoted lines
> Heya,
>
> On Mon, May 2, 2011 at 13:39, Bert Wesarg <bert.wesarg@googlemail.com> wrote:
>> This series will teach git grep to match at specified line numbers. This is
>> particular usefull, if you want to see the lines which emits warnings or errors
>> from a build run (where you only get the line number) and present it nicely to
>> the user with function and context lines.
>
> Can you give a concrete example of how you'd use this? I'm not sure I
> understand the described use case.

I parse the output of compiling a file, there may be warnings or even errors, I collect the given line numbers, and then call 'git grep -p -C -n (-@ <lno>)+ -- <path>' to show me what these warnings are about.

For example clang 2.9 (while clang is a bad example, because it prints the offending line already, but gcc does not generate any warnings on master currently) gives the following warning (which is probably worth a patch, btw):

    CC grep.o
grep.c:231:16: warning: comparison of unsigned enum expression < 0 is
always false [-Wtautological-compare]
                if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)
                    ~~~~~~~~ ^ ~
1 warning generated.
I can than call 'git grep -3 -n -h -p -@ 231 -- grep.c', and get:

218=static struct grep_expr *prep_header_patterns(struct grep_opt *opt) -- 228- for (p = opt->header_list; p; p = p->next) { 229- if (p->token != GREP_PATTERN_HEAD) 230- die("bug: a non-header pattern in grep header list."); 231: if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field) 232- die("bug: unknown header field %d", p->field); 233- compile_regexp(p, opt); 234- }

Another use case would be to restrict the matching to a block of lines, this would need the mentioned patch 5, which than will support line ranges, so that you can say 'match foo, but only in the first 10 lines'.

Bert
Show 6 quoted lines
>
> --
> Cheers,
>
> Sverre Rabbelier
>
Previous: Sverre RabbelierNext: Junio C Hamano
Message 14 of 22 in “grep: support to match by line number”
  1. 0/4 grep: support to match by line numberBert Wesarg, May 2, 2011
  2. 1/4 grep: prepare for re-using the space of the regexp member in struct grep_patBert Wesarg, May 2, 2011
  3. 2/4 grep: pass current line number down to match_one_patternBert Wesarg, May 2, 2011
  4. 3/4 grep: introduce pattern which matches at line numberBert Wesarg, May 2, 2011
  5. 4/4 grep: provide option to match line numberBert Wesarg, May 2, 2011
  6. Thiago FarinaMay 2, 2011
  7. Bert WesargMay 2, 2011
  8. Thiago FarinaMay 2, 2011
  9. Bert WesargMay 2, 2011
  10. Junio C HamanoMay 2, 2011
  11. Thiago FarinaMay 2, 2011
  12. Bert WesargMay 2, 2011
  13. Sverre RabbelierMay 2, 2011
  14. Bert WesargMay 2, 2011
  15. Junio C HamanoMay 2, 2011
  16. Bert WesargMay 2, 2011
  17. Junio C HamanoMay 2, 2011
  18. Junio C HamanoMay 2, 2011
  19. Jakub NarebskiMay 2, 2011
  20. Bert WesargMay 2, 2011
  21. Junio C HamanoMay 2, 2011
  22. Bert WesargMay 2, 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.