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

Re: [PATCH v2 5/6] grep: remove regflags from the public grep_opt API

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 30, 2017, 17:20 UTC
Message-ID
<xmqqwp7ts88k.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20170629222222.4694-6-avarab@gmail.com>
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:
Show 21 quoted lines
> @@ -169,6 +167,24 @@ void grep_init(struct grep_opt *opt, const char *prefix)
>  
>  static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, struct grep_opt *opt)
>  {
> +	/*
> +	 * When committing to the pattern type by setting the relevant
> +	 * fields in grep_opt it's generally not necessary to zero out
> +	 * the fields we're not choosing, since they won't have been
> +	 * set by anything. The extended_regexp_option field is the
> +	 * only exception to this.
> +	 *
> +	 * This is because in the process of parsing grep.patternType
> +	 * & grep.extendedRegexp we set opt->pattern_type_option and
> +	 * opt->extended_regexp_option, respectively. We then
> +	 * internally use opt->extended_regexp_option to see if we're
> +	 * compiling an ERE. It must be unset if that's not actually
> +	 * the case.
> +	 */
> +	if (pattern_type != GREP_PATTERN_TYPE_ERE &&
> +	    opt->extended_regexp_option)
> +		opt->extended_regexp_option = 0;

Good to have the reasoning in an in-code comment like the above. But after reading these two paragraphs and then before reading the three line code, a more natural embodiment in the code of the commentary that came to my mind was

	if (pattern_type != GREP_PATTERN_TYPE_ERE)
		opt->extended_regexp_option = 0;

The end-result is the same as yours, of course, but I somehow found it match the reasoning better.

Now, I wonder if this can further be tweaked to
	opt->extended_regexp_option = (pattern_type == GREP_PATTERN_TYPE_ERE);

which might lead us in a direction to really unify the two related fields extended_regexp_option and pattern_type_option.

Even if that were a good longer term direction to go in, it is outside the scope of this step, of course. I am merely bringing it up as an conversation item ;-).

Previous: Ævar Arnfjörð Bjarmason
Message 19 of 19 in “grep: remove redundant code & reflags from API”
  1. 0/5 grep: remove redundant code & reflags from APIÆvar Arnfjörð Bjarmason, Jun 28, 2017
  2. 1/5 grep: remove redundant double assignment to 0Ævar Arnfjörð Bjarmason, Jun 28, 2017
  3. 3/5 grep: remove redundant "fixed" field re-assignment to 0Ævar Arnfjörð Bjarmason, Jun 28, 2017
  4. Stefan BellerJun 29, 2017
  5. 2/5 grep: remove redundant grep pattern type assignmentÆvar Arnfjörð Bjarmason, Jun 28, 2017
  6. Stefan BellerJun 29, 2017
  7. Ævar Arnfjörð BjarmasonJun 29, 2017
  8. 4/5 grep: remove redundant and verbose re-assignments to 0Ævar Arnfjörð Bjarmason, Jun 28, 2017
  9. 5/5 grep: remove regflags from the public grep_opt APIÆvar Arnfjörð Bjarmason, Jun 28, 2017
  10. Stefan BellerJun 29, 2017
  11. Ævar Arnfjörð BjarmasonJun 29, 2017
  12. 0/6 grep: remove redundant code & reflags from APIÆvar Arnfjörð Bjarmason, Jun 29, 2017
  13. 1/6 grep: remove redundant double assignment to 0Ævar Arnfjörð Bjarmason, Jun 29, 2017
  14. 2/6 grep: adjust a redundant grep pattern type assignmentÆvar Arnfjörð Bjarmason, Jun 29, 2017
  15. 3/6 grep: remove redundant "fixed" field re-assignment to 0Ævar Arnfjörð Bjarmason, Jun 29, 2017
  16. 4/6 grep: remove redundant and verbose re-assignments to 0Ævar Arnfjörð Bjarmason, Jun 29, 2017
  17. 6/6 grep: remove redundant REG_NEWLINE when compiling fixed regexÆvar Arnfjörð Bjarmason, Jun 29, 2017
  18. 5/6 grep: remove regflags from the public grep_opt APIÆvar Arnfjörð Bjarmason, Jun 29, 2017
  19. Junio C HamanoJun 30, 2017

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.