From: Stefan Sperling Subject: Re: got: log: -g grep-pattern To: Klemens Nanni Cc: gameoftrees@openbsd.org Date: Fri, 29 Nov 2019 14:28:14 -0700 On Fri, Nov 29, 2019 at 10:11:01PM +0100, Klemens Nanni wrote: > Here's a preliminary diff to allow filtering commits based on their log > message; this is the pendant to `git log --grep='. > > There's an XXX in there regarding error handling, it can probably be > improved, but `got log -g grep-pattern' already does work as expected. In my mind, Git's use of term 'grep' for searching log messages seems misplaced. I believe we should reserve the term "grep" for an operation which searches content of blobs in a given commit/tree, as an analogy to how regular UNIX grep(1) searches files on disk. So I would prefer the term "search" over "grep", and option -s over -g. And all variable and function names should also be adapted to use a search_ prefix instead of a grep_ prefix. Apart from that, this looks good to me. > const struct got_error *err; > struct got_commit_graph *graph; > + regex_t regex; > + int have_match; > > + if (grep_pattern && > + regcomp(®ex, grep_pattern, REG_EXTENDED | REG_NOSUB | REG_NEWLINE)) > + /* XXX handle error? how? */ Something like this? See add_color() in tog.c for a complete example. err = got_error_msg(GOT_ERR_REGEX, grep_pattern); if (err) goto done; > + errx(1, "regcomp"); > +