Re: [PATCH] git grep -O -i: if the pager is 'less', pass the '-i' option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Junio C Hamano wrote:
> Stepan Kasal <kasal@xxxxxx> writes:

>> --- a/builtin/grep.c
>> +++ b/builtin/grep.c
>> @@ -897,6 +897,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
>>  		if (len > 4 && is_dir_sep(pager[len - 5]))
>>  			pager += len - 4;
>>  
>> +		if (opt.ignore_case && !strcmp("less", pager))
>> +			string_list_append(&path_list, "-i");
>
> I have a feeling that this goes against the recent trend of not
> mucking with the expectation of the users on their pagers, if I
> recall correctly the arguments for dropping S from the default given
> to an unconfigured LESS environment variable.

It's just missing an explanation.

When <command> happens to be the magic string "less", today

	git grep -O<command> -e<pattern>

helpfully passes +/<pattern> to less so you can navigate through
the results within a file using the n and shift+n keystrokes.

Alas, that doesn't do the right thing for a case-insensitive match.
For that case we should pass --IGNORE-CASE to "less" so that n and
shift+n can move between results ignoring case in the pattern.
(That's -I, not -i, because it ought to work even when the pattern
contains capital letters.)

"git grep" has other options that affect interpretation of the pattern
which this patch does not help with:

 * -v / --ignore-match: probably should disable this feature of -O.
 * -E / --extended-regexp
 * -P / --perl-regexp
 * -F / --fixed-strings: ideally would auto-escape regex specials.
 * -e<pattern1> --or -e<pattern2>

And git grep -Ovi has a similar bug, for which the fix is to add
\c to the pattern instead of passing an -I option.

But as is, it's an improvement, so (except that "-i" should be
replaced by "-I") it seems like a good change.

Hope that helps,
Jonathan
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]