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

Re: [PATCH 2/5] grep: remove redundant grep pattern type assignment

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 29, 2017, 17:50 UTC
Message-ID
<871sq2k7jp.fsf@gmail.com>
In-Reply-To
<CAGZ79kb0a2EEALj3eEAMUwQSWamhGuOFOYPrWbv6uCtC7EXgAw@mail.gmail.com>
On Thu, Jun 29 2017, Stefan Beller jotted:
Show 47 quoted lines
> On Wed, Jun 28, 2017 at 2:58 PM, Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>> Remove a redundant assignment to extended_regexp_option to make it
>> zero if grep.extendedRegexp is not set. This is always called right
>> after init_grep_defaults() which memsets the entire structure to 0.
>>
>> This is a logical follow-up to my commit to remove redundant regflags
>> assignments[1]. This logic was originally introduced in [2], but as
>> explained in the former commit it's working around a pattern in our
>> code that no longer exists, and is now confusing as it leads the
>> reader to think that this needs to be flipped back & forth.
>>
>> 1. e0b9f8ae09 ("grep: remove redundant regflags assignments",
>>    2017-05-25)
>> 2. b22520a37c ("grep: allow -E and -n to be turned on by default via
>>    configuration", 2011-03-30)
>>
>> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
>> ---
>>  grep.c | 2 --
>>  1 file changed, 2 deletions(-)
>>
>> diff --git a/grep.c b/grep.c
>> index 29439886e7..6614042fdc 100644
>> --- a/grep.c
>> +++ b/grep.c
>> @@ -80,8 +80,6 @@ int grep_config(const char *var, const char *value, void *cb)
>>         if (!strcmp(var, "grep.extendedregexp")) {
>>                 if (git_config_bool(var, value))
>>                         opt->extended_regexp_option = 1;
>> -               else
>> -                       opt->extended_regexp_option = 0;
>>                 return 0;
>
> Instead of having a condition here, have you considered to remove the
> condition alltogether?
>
>     if (!strcmp(var, "grep.extendedregexp")) {
>         opt->extended_regexp_option = git_config_bool(var, value);
>         return 0;
>     }
>
> This does not have the effect of not assigning the value in case of 0,
> but it may be easier to reason about when reading the code.
>
> This would also conform to the code below in that function, that parses
> grep.linenumber or grep.fullname
I didn't think about that. Good point. I'll do that instead in v2.
Previous: Stefan BellerNext: Ævar Arnfjörð Bjarmason
Message 7 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.