Skip to contentSkip to conversation

git grep -O -i: if the pager is 'less', pass the '-i' option

PATCH In review Stepan Kasal 6 participants 14 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 git grep -O -i: if the pager is 'less', pass the '-i' option

From: Johannes Schindelin <[email protected]>
Date: Tue, 8 Feb 2011 00:17:24 -0600

---
Hi,
this patch has been in msysgit for 3 1/4 years.
Stepan

 builtin/grep.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/grep.c +3 -0
index 8073fbe..6c82a29 100644
@@ -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");
+
 		if (!strcmp("less", pager) || !strcmp("vi", pager)) {
 			struct strbuf buf = STRBUF_INIT;
 			strbuf_addf(&buf, "+/%s%s",
Signature · 21 lines
1.9.2.msysgit.0.335.gd2a461f

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#1 lore raw
Quoted 18 lines · Stepan Kasal

From: Johannes Schindelin <[email protected]>
Date: Tue, 8 Feb 2011 00:17:24 -0600

---
Hi,
this patch has been in msysgit for 3 1/4 years.
Stepan

 builtin/grep.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/grep.c +0 -0
index 8073fbe..6c82a29 100644

builtin/grep.c int cmd_grep(int argc, const char **argv, const char *prefix) · line 901

Quoted 5 lines
builtin/grep.c +2 -0
@@ -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.

Quoted 7 lines
builtin/grep.c +0 -0
 		if (!strcmp("less", pager) || !strcmp("vi", pager)) {
 			struct strbuf buf = STRBUF_INIT;
 			strbuf_addf(&buf, "+/%s%s",
Signature · 3 lines
1.9.2.msysgit.0.335.gd2a461f

-- 
Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#2 lore raw

Hi,

Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Stepan Kasal
builtin/grep.c +0 -0
@@ -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;
 
Quoted 7 lines

builtin/grep.c int cmd_grep(int argc, const char **argv, const char *prefix) · line 901

Quoted 2 lines
builtin/grep.c +2 -0
+		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

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#3 lore raw

Hello,

Quoted 2 lines · Jonathan Nieder

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

indeed, "-I" would match the semantics of git-grep -i .

Stepan

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#4 lore raw
In reply to Jonathan Nieder
Quoted 11 lines · Jonathan Nieder

"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.

We've already found the lines of interest to the user. It would be nice if we could somehow point the pager at them by number, rather than repeating the (slightly incompatible) search.

We can do "less +25", but that only points it to the first instance (and doesn't highlight it), whereas the current code lets the repeat-search find other instances. I don't think there's a way to queue up a set of interesting lines to visit in less. At least I could not think of one.

This is more or less how I ended up at the design of contrib/git-jump, which uses quickfix lists to make such a queue (only editors understand those, not pagers, but I consider being dumped into the editor a feature :) ).

Quoted 2 lines

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

Agreed. Thanks for the list of problematic options.

-Peff

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#8 lore raw
In reply to Jonathan Nieder
Quoted 8 lines · Jonathan Nieder
Quoted 7 lines

builtin/grep.c int cmd_grep(int argc, const char **argv, const char *prefix) · line 901

Quoted 2 lines
builtin/grep.c +2 -0
+		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.

Quoted 4 lines

It's just missing an explanation.
...
(That's -I, not -i, because it ought to work even when the pattern contains capital letters.)

Spot on. The change, especially with "-I", makes sense.

Thanks.

#13 lore raw
In reply to Junio C Hamano
Quoted 23 lines · Junio C Hamano
Quoted 21 lines · Stepan Kasal

From: Johannes Schindelin <[email protected]>
Date: Tue, 8 Feb 2011 00:17:24 -0600

---
Hi,
this patch has been in msysgit for 3 1/4 years.
Stepan

 builtin/grep.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/grep.c +0 -0
index 8073fbe..6c82a29 100644
@@ -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;
 
Quoted 7 lines

builtin/grep.c int cmd_grep(int argc, const char **argv, const char *prefix) · line 901

Quoted 2 lines
builtin/grep.c +2 -0
+		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.

I had the same feeling about "we're doing magic in corner-cases, makes it hard for the user to understand what's going on". But the patch actually makes a lot of sense. Without the patch, I get

  $ git grep -O -i no_openssl
  Pattern not found  (press RETURN)

with the patch, I do get a file opened and NO_OPENSSL selected.

The lines right below the ones of the patch are aleady (documented) less+vi magic, which actually require the patch to behave well in the presence of -i.

Signature · 2 lines
Matthieu Moy
http://www-verimag.imag.fr/~moy/
#5 lore raw
In reply to Jeff King

Hi Peff,

Quoted 11 lines · Jeff King
Quoted 9 lines · Jonathan Nieder

"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>

Quoted 6 lines
Quoted 2 lines

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.

We've already found the lines of interest to the user. It would be nice if we could somehow point the pager at them by number, rather than repeating the (slightly incompatible) search.

FWIW it is exactly that type of "I want your patch to do more than you do" type of comments that makes it impossible for myself to contribute patches anymore. It just does not fit inside my Git time budget anymore.

Besides, it breaks exactly the intended usage. My intent is not just to see the matching lines in the pager, but to be able to adjust the search pattern further if needed. Your suggestion completely breaks that usage.

Ciao,
Johannes

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#6 lore raw
Quoted 9 lines · Johannes Schindelin
Quoted 3 lines · Jeff King

We've already found the lines of interest to the user. It would be nice if we could somehow point the pager at them by number, rather than repeating the (slightly incompatible) search.

FWIW it is exactly that type of "I want your patch to do more than you do" type of comments that makes it impossible for myself to contribute patches anymore.

I think you're overreacting to Peff's "It would be nice".

It is a way of talking about where this lies in a design space that also includes the git-jump tool that Peff worked on. Maybe the tools can learn from each other. It is not a reason not to apply the patch.

Jonathan

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#9 lore raw
In reply to Junio C Hamano

Hi Junio,

Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Jonathan Nieder
Quoted 7 lines

builtin/grep.c int cmd_grep(int argc, const char **argv, const char *prefix) · line 901

Quoted 2 lines
builtin/grep.c +2 -0
+		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.

Quoted 6 lines
Quoted 4 lines

It's just missing an explanation.
...
(That's -I, not -i, because it ought to work even when the pattern contains capital letters.)

Spot on. The change, especially with "-I", makes sense.

Except that it was not tested with -I. If you change it that way and it stops working on Windows, it's useless to me.

Ciao,
Johannes

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#10 lore raw

Hi,

Quoted 6 lines · Johannes Schindelin
Quoted 1 line · Junio C Hamano

Spot on. The change, especially with "-I", makes sense.

Except that it was not tested with -I. If you change it that way and it stops working on Windows, it's useless to me.

Are you saying that less on Windows doesn't have an "-I" option? version.c tells me it was added in v266 (1994-12-26).

If "-I' is in fact broken on Windows, that would be useful to know, but it's not clear to me. Or if I have misunderstood what

git grep -i -Oless -eGit_

is supposed to do, that would help, too.

Puzzled,
Jonathan

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#7 lore raw
In reply to Johannes Schindelin
Quoted 7 lines · Johannes Schindelin
Quoted 3 lines

We've already found the lines of interest to the user. It would be nice if we could somehow point the pager at them by number, rather than repeating the (slightly incompatible) search.

FWIW it is exactly that type of "I want your patch to do more than you do" type of comments that makes it impossible for myself to contribute patches anymore. It just does not fit inside my Git time budget anymore.

I'm sorry you took it that way. What I meant to say was "it would be nice if we could do it this other way, which is more robust, but I don't

Quoted 4 lines · when I later
Quoted 4 lines
Quoted 2 lines

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

Agreed. Thanks for the list of problematic options.

the "agreed" there is with "it seems like a good change".

And I also wanted to point people to existing work, if they did want to explore doing it that other way. I really didn't expect anything from you (beyond s/i/I/, as Jonathan suggested).

Quoted 3 lines

Besides, it breaks exactly the intended usage. My intent is not just to see the matching lines in the pager, but to be able to adjust the search pattern further if needed. Your suggestion completely breaks that usage.

Thanks, this is a point I hadn't considered.

-Peff

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#11 lore raw
In reply to Jonathan Nieder

Hi,

Quoted 9 lines · Jonathan Nieder
Quoted 6 lines · Johannes Schindelin
Quoted 1 line · Junio C Hamano

Spot on. The change, especially with "-I", makes sense.

Except that it was not tested with -I. If you change it that way and it stops working on Windows, it's useless to me.

Are you saying that less on Windows doesn't have an "-I" option?

I did not say that.

Quoted 1 line

version.c tells me it was added in v266 (1994-12-26).

Thanks. That was the thing I was really looking for: an indication that -I is not a new-fangled thing but a well-tested option that even old greps have.

Ciao,
Dscho

Signature · 18 lines
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
#12 lore raw
In reply to Johannes Schindelin
Quoted 15 lines · Johannes Schindelin
Quoted 15 lines
Quoted 12 lines · Jonathan Nieder
Quoted 7 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		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.
...
(That's -I, not -i, because it ought to work even when the pattern contains capital letters.)

Quoted 4 lines
Quoted 1 line

Spot on. The change, especially with "-I", makes sense.

Except that it was not tested with -I. If you change it that way and it stops working on Windows, it's useless to me.

That is all true, and I didn't test on Windows, but it seems that the feature is very old in the upstream that we can rely on, so let's take Jonathan's explanation and queue somethink like this.

-- >8 --
From: Johannes Schindelin <[email protected]>
Date: Tue, 8 Feb 2011 00:17:24 -0600
Subject: [PATCH] git grep -O -i: if the pager is 'less', pass the '-I' option

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, i.e.

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

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.

The original patch came from msysgit and used "-i", but that was not due to lack of support for "-I" but it merely overlooked that it ought to work even when the pattern contains capital letters.

---
 builtin/grep.c | 3 +++
 1 file changed, 3 insertions(+)
builtin/grep.c +3 -0
index 63f8603..c0573d0 100644
@@ -876,6 +876,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");
+
 		if (!strcmp("less", pager) || !strcmp("vi", pager)) {
 			struct strbuf buf = STRBUF_INIT;
 			strbuf_addf(&buf, "+/%s%s",
Signature · 21 lines
2.0.0-rc3-419-gdb851f2

-- 
-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

--- 
You received this message because you are subscribed to the Google Groups "msysGit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.