Re: [PATCH v6 01/11] grep: allow -F -i combination
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Jun 18, 2016, 00:07 UTC
- Message-ID
- <CACsJy8CKWpLwn=ffEce8TxKuQGk+-2-374DyRmLnE1uP_5NQiw@mail.gmail.com>
- In-Reply-To
- <xmqqk2hnzdkc.fsf@gitster.mtv.corp.google.com>
On Sat, Jun 18, 2016 at 4:54 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 49 quoted lines
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>
>> -F means "no regex", not "case sensitive" so it should not override -i
>
> That logic is flawed, isn't it?
>
> "-F" means "no regex", so it should not touch opt.regflags at all.
>
>> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
>> ---
>> builtin/grep.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/builtin/grep.c b/builtin/grep.c
>> index 5526fd7..4be0df5 100644
>> --- a/builtin/grep.c
>> +++ b/builtin/grep.c
>> @@ -809,7 +809,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>>
>> if (!opt.pattern_list)
>> die(_("no pattern given."));
>> - if (!opt.fixed && opt.ignore_case)
>> + if (opt.ignore_case)
>> opt.regflags |= REG_ICASE;
>>
>> compile_grep_patterns(&opt);
>
> In grep.c, we do this:
>
> static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
> {
> int err;
>
> p->word_regexp = opt->word_regexp;
> p->ignore_case = opt->ignore_case;
>
> if (opt->fixed || is_fixed(p->pattern, p->patternlen))
> p->fixed = 1;
> else
> p->fixed = 0;
>
> if (p->fixed) {
> if (opt->regflags & REG_ICASE || p->ignore_case)
> p->kws = kwsalloc(tolower_trans_tbl);
> else
>
> It is possible that your later changes _depend_ on having REG_ICASE
> set in opt->regflags, but if that is why this commit is needed, then
> you are going in a wrong direction.Yeah.. some commits down the line, we need to avoid kws (because it can't deal with non-ascii) and fall back to regex after all special chars are quoted. Will fix.
-- Duy