Skip to content

Conversation

gerhardol
Copy link
Member

@gerhardol gerhardol commented Nov 12, 2023

Fixes #4912
Depends on #11590 , only 92d937e (and forward if added later) to be reviewed

Proposed changes

An UI for git-grep, to search commits without checking out those commits. (When working with this I have often used it to view worktree too.)
https://git-scm.com/docs/git-grep

The UI in this PR adds a popup as well as a searchbox to the Diff tab.

The searchbox dropdown has the search history for the GE session, not persistent.
The popup and searchbox are kept in sync.

Search in the popup is done when button is pressed (or Enter),
the diff tab box is searching when typing (similar in the filter).
If there is no -e in the search string, this is added to the search string.
Most git-grep options can be added, including --and etc.

git-grep options to handle case insensitive is available, but most options can be added in the searchbox.
Persistent options can be added too for instance --show-function.

The output of git-grep is always for a commit, including index and worktree.
Note that the selected file in the grep group is not always followed when a new commit is selected, as it is not the primary group. This could be specially handled (but "grep" knowledge need to be added to RevDiff).

Performance
In the Git repo, the git-grep requires about 200 ms for me, the information is added async after normal diff so no visible.
For the Linux repo, git-grep can require several seconds. As the current search is aborted when a new is started, works fine for me.
The processing in the fileviewer is faster than for normal diffs.

Limitations are basically the same as #11590 ,missing

  • Documentation for the changes, how colors etc can be changed by Git config
  • tests for the new functionality. May be postponed to a later PR

Screenshots

After

The popup window and the optional FileStatusList combobox
image

Example usage.
grep-example

Test methodology

Manual

Merge strategy

squash.


✒️ I contribute this code under The Developer Certificate of Origin.

@ghost ghost assigned gerhardol Nov 12, 2023
@gerhardol gerhardol force-pushed the feature/i4912-git-grep-ui branch from 72c412b to e2fef91 Compare November 12, 2023 19:39
@vbjay
Copy link
Contributor

vbjay commented Nov 12, 2023

Just a point. Not saying git grep shouldn't be used. Just saying ripgrep is very speedy. So if searching working directory vs git history.

@gerhardol
Copy link
Member Author

Just a point. Not saying git grep shouldn't be used. Just saying ripgrep is very speedy. So if searching working directory vs git history.

To clarify if someone is wondering: This feature is primarily to search Git commit history without a checkout.

This feature is not really competing with searching in the worktree. Searching in the editor and specific tools will normally be a better choice.
I doubt anyone want to implement a GUI with all search options even (command line options can be provided though).
I have ended up using the feature in the worktree too (for instance a quick way to search and exclude submodules and ignored files) but this is a sideeffect.

@gerhardol
Copy link
Member Author

If noone has any other preferences, I plan to add an extra searchbox to diff.

@gerhardol gerhardol force-pushed the feature/i4912-git-grep-ui branch from e2fef91 to 1ce8926 Compare November 29, 2023 23:05
@mstv
Copy link
Member

mstv commented Dec 3, 2023

My 2ct: This feature seems to be pretty related to the "Find" function - particularly to "Find all" in IDEs.
I would add it to the FindAndReplaceForm (or else have a new one opened using Shift+Ctrl+F). "Find & highlight all" does not work (and does not really apply) if invoked from the FileStatusList. So this button could be replaced with "Find all (git grep)" in this case.
The result as diff group feels appropriate.
There should be a way to discard the grep group.

I guess I would use it more often if the search could be limited to the changes instead of searching the entire file tree of the selected commit (which can be useful in other cases).

The detection of "-e" does not work in all locations. I have tried to ignore the character case:

image

@gerhardol
Copy link
Member Author

My 2ct: This feature seems to be pretty related to the "Find" function - particularly to "Find all" in IDEs.

It is similar to Find all, but only for the files in Git and only for the selected commit, you do not have to check out the commits.

"Find & highlight all" does not work (and does not really apply) if invoked from the FileStatusList.

"Find & highlight all" is only for current file, should be renamed (moved to context menu in fileviewer?).

I would add it to the FindAndReplaceForm (or else have a new one opened using Shift+Ctrl+F). .... So this button could be replaced with "Find all (git grep)" in this case. The result as diff group feels appropriate. There should be a way to discard the grep group.

git-grep works quite different from current find, so a separate popup is probably better than a combined form - maybe a button to switch to the other form.
A context menu item and keyboard shortcut to clear the search maybe.
Shift+Ctrl+F would be the logical shortcut, but it will hide the "find file".

But I may prefer the searchbox anyway, you can search interactively, get feedback faster.

I guess I would use it more often if the search could be limited to the changes instead of searching the entire file tree of the selected commit (which can be useful in other cases).

git-grep cannot search the diff, that would be a completely different algorithm.
It could be possible to combine diff/grep, but the result would maybe be unexpected.

The detection of "-e" does not work in all locations. I have tried to ignore the character case:

Will try to tweak this.
The options could be provided separately too. (But I do not want to implement all options in a gui, including and/or, overkill.)

@mstv
Copy link
Member

mstv commented Dec 3, 2023

But I may prefer the searchbox anyway, you can search interactively, get feedback faster.
git-grep cannot search the diff, that would be a completely different algorithm.

I prefer code browsing in an IDE ("go to definition", "browse references", "exclude unit tests"). So I guess I will use grep rarely and rather save the space in favor of the Git Output Control.
A toolbar button could be added to the Diff search bar in order to switch the toolbar mode to grep or else to show & hide an additional grep bar.

Shift+Ctrl+F would be the logical shortcut, but it will hide the "find file".

I think this is acceptable for the Diff tab - especially as grep is kind of a generalization of "find file". And one can quickly switch to the File Tree.

@gerhardol gerhardol force-pushed the feature/i4912-git-grep-ui branch from 1ce8926 to 6aa88a8 Compare December 17, 2023 19:40
@gerhardol gerhardol changed the title WIP git-grep UI git-grep UI Dec 17, 2023
@gerhardol
Copy link
Member Author

gerhardol commented Dec 17, 2023

Implemented a searchbox.
I believe this ready for review and inclusion, but there are some discussion points:

  • mstv wanted to search with a popup instead. That could be added in addition to the searchbox, the box could be hidden.
  • There are no tests. Will adapt FileStatusListTest.cs if this is accepted, but the tests depends on how it is implemented.
  • If Add GitExtensions.Extensibility #11431 is merged, I prefer to add the methods in GiTModule to some other module (it is shared FileStatusList, GitUIExtensions and GrepHighlightService.
  • documentation

Will squash if mstv agrees

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will squash if mstv agrees

I have not looked into the code yet.

mstv wanted to search with a popup instead. That could be added in addition to the searchbox, the box could be hidden.

My main point is that I do not want this searchbox to consume space all the time because I will rarely use it.
I admit it is really quick and it can be (mis-)used to get all files for the artificial commits (by searching for ".").

Could we add a toggle button right of the Filter files box?
Though it would need to remain visible if there are "No changes".

... which does not look good (distracting) in the current state IMO:

image

SearchWatermarkLabel.Location = new Point(4, 27);
SearchWatermarkLabel.Name = "SearchWatermarkLabel";
SearchWatermarkLabel.Size = new Size(184, 13);
SearchWatermarkLabel.Text = "Search files in revision using a regular expression...";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SearchWatermarkLabel.Text = "Search files in revision using a regular expression...";
SearchWatermarkLabel.Text = "Search text in all files of revision using a regular expression...";

might be clearer

@gerhardol
Copy link
Member Author

Will squash if mstv agrees

I have not looked into the code yet.

If you have not reviewed the previous code, I assume I can squash.

mstv wanted to search with a popup instead. That could be added in addition to the searchbox, the box could be hidden.

My main point is that I do not want this searchbox to consume space all the time because I will rarely use it. I admit it is really quick and it can be (mis-)used to get all files for the artificial commits (by searching for ".").

Could we add a toggle button right of the Filter files box? Though it would need to remain visible if there are "No changes".

I rather have an enable toggle in the context menu as for Show file differences
(Ctrl-shift-f could be shortcut)

popup would be a way to configure the options though, maybe additional control.

@RussKie
Copy link
Member

RussKie commented Dec 19, 2023

I love the feature but the double dropdown doesn't look good...
image

As an idea, maybe we could have a single dropdown (visually, there could be several swapped in and out of the view) for the search, as we currently have, and another one to the right of it which allows picking the mode - i.e., the normal search or grep search?
E.g.:
image

@RussKie RussKie added 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity release-notes-worthy labels Dec 19, 2023
@gerhardol
Copy link
Member Author

gerhardol commented Dec 19, 2023

As an idea, maybe we could have a single dropdown

It is useful to filter grep files too, grep and filter are not exclusive.

The POC I had initially separating with :: was better this way...

Maybe the popup is needed. I still like the extra search bar, may want to keep it as an option.

Edit: Would a hidden feature searching with :: in filter be acceptable for an initial merge, keeping as a hidden feature, to get some way of feedback?

@ghost ghost removed the 📭 needs: author feedback More info/confirmation awaited from OP; issues typically get closed after 30 days of inactivity label Dec 19, 2023
@mstv
Copy link
Member

mstv commented Dec 28, 2023

Having it in one line with "::" feels too cryptic to me.
A toggle button in the upper right corner would make it discoverable. (Please use RuntimeSetting in order to not interfere with other running instances.)
Default search options could be set using a context menu (to be added in a follow-up).

image

image

In case of "no changes", I would always hide the search bar - but not change the setting.

@gerhardol
Copy link
Member Author

Having it in one line with "::" feels too cryptic to me. A toggle button in the upper right corner would make it discoverable. (Please use RuntimeSetting in order to not interfere with other running instances.) Default search options could be set using a context menu (to be added in a follow-up).

I am adding a configuration, default off, maybe even a popup.
Depends on #11472 though, setting this to draft again.

I want the options to be persistent though, not just runtime.
The filter items are instance local, could be be runtime settings.

image

In case of "no changes", I would always hide the search bar - but not change the setting.

Yes, in the same way as the filterbox is hidden if no changes.

@gerhardol gerhardol marked this pull request as draft December 29, 2023 11:40
@mstv
Copy link
Member

mstv commented Dec 29, 2023

I want the options to be persistent though, not just runtime. The filter items are instance local, could be be runtime settings.

That's what RuntimeSetting<> is intended for:

  • no side-effect on other instances
  • default persisted by means of

image


image

  • discoverable with default value true
  • insert below of "Find"?
  • will need a description how to hide it by default

In case of "no changes", I would always hide the search bar - but not change the setting.

Yes, in the same way as the filterbox is hidden if no changes.

Not exactly, the search box still makes sense for empty commits. The user should be able to activate it.

@mstv
Copy link
Member

mstv commented Jan 29, 2024

If the "search commit" combobox is visible, the "filter files" combobox should always be shown, too.
"No changes" shall be hidden, if there are search results.

grafik

@mdonatas
Copy link
Contributor

I've incorporated this branch into my custom build and have already made use of it at least 3 times. Loving it! At the same time I am getting strong vibes that GitExtensions is turning in the kind of software where one needs to watch a youtube video or someone else using it to learn of these power-user features. Regardless, I still welcome this feature!

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works better

Choosing an entry from the dropdown

  • clears the search string of the FileStatusList
  • in the Search form affects the FileStatusList at once - intentionally?
  • should set the cursor behind the search string
  • using cursor keys is not possible (only the first two entries can be reached)

Activating the Search button should keep the cursor position.

@gerhardol
Copy link
Member Author

gerhardol commented Mar 23, 2024

Combobox handling is complex - the toolbar filter comboboxes are horrible.

Choosing an entry from the dropdown

* clears the search string of the FileStatusList

Added back the text assignment in dropdown update, but moving the cursor to the end.

* in the Search form affects the FileStatusList at once - intentionally?

It was intentional, but I changed it to avoid the strange workarounds in FormSearchCommit

* should set the cursor behind the search string

This occurred when the dropdown was updated and in the list but not the latest.

* using cursor keys is not possible (only the first two entries can be reached)

It is either keeping the list as a last-recently used sorted (this toggles the order) or just having a fifo queue.

Activating the Search button should keep the cursor position.

In the popup, occurred when the list was resorted.

The list is not saved in settings and I set it to 30 items, it is maybe not a problem to have it as fifo. Maybe even skip a maximal size, then most special handling can be removed?

Note: popup search is by Enter only. The optional combobox is when typing, both because I prefer it that way and because Enter is not seen by the control.

@mstv
Copy link
Member

mstv commented Mar 24, 2024

Combobox handling is complex

Yes, it is.

It works much better now. I would not switch to FIFO mode and throw away the working code.

Remaining point: When changing the search string using the FileStatusList, only the dropdown of the SearchForm combobox is updated but not its text.
Edit: +translation update

@mstv
Copy link
Member

mstv commented Mar 24, 2024

👍 35bdaec works well.

Just focus the search form on context menu and hotkey yet, please.

@gerhardol
Copy link
Member Author

Just focus the search form on context menu and hotkey yet, please.

Do you mean when the popup is already open?
When opening the first time, the searchbox is focused
(when using menu/hotkey the second time the content is updated from the searchbox since the last update, also when not visible...)

@mstv
Copy link
Member

mstv commented Mar 25, 2024

I mean 563c1cf

@gerhardol
Copy link
Member Author

I mean 563c1cf

Thanks (you could have pushed to my branch directly, if I had not liked it I would revert...)

Setting Location was intentional, to avoid that the popup got lost.
But less risk the popup is lost as the popup is visible once at least.

Also a minor tweak.

I am sure there will be more tweaks to the functionality when there are more users

@gerhardol
Copy link
Member Author

Setting Location was intentional, to avoid that the popup got lost. But less risk the popup is lost as the popup is visible once at least.

Would like to change this back so when using the hotkey/menu to invoke git-grep popup, show it at the default location.
If you see it, you likely not try to show it again. (Only reason would be that the current selection is added to the search box)

@mstv
Copy link
Member

mstv commented Mar 26, 2024

If you see it, you likely not try to show it again.

My usecase: Fingers at keyboard and wanting to focus the search form using Shift+Ctrl+F. 1. Focusing must work (had not before my commit). 2. Form should not jump away (not too important because I don't know how often I will move the form nearer to the FileStatusList).

@gerhardol
Copy link
Member Author

If you see it, you likely not try to show it again.

My usecase: Fingers at keyboard and wanting to focus the search form using Shift+Ctrl+F. 1. Focusing must work (had not before my commit). 2. Form should not jump away (not too important because I don't know how often I will move the form nearer to the FileStatusList).

Not how I use it, but I rather accept this and move on.
(Personally, I am using the searchbox. If find-in-diff was quicker I would like to have similar search there.)

@gerhardol gerhardol merged commit f8c0353 into gitextensions:master Mar 27, 2024
@gerhardol gerhardol deleted the feature/i4912-git-grep-ui branch March 27, 2024 21:06
@RussKie RussKie added this to the vNext milestone Apr 19, 2024
@RussKie
Copy link
Member

RussKie commented Aug 27, 2024

@gerhardol do we have any docs on how to use this feature? It took me awhile to find that I have to use CTRL + SHIFT + F to open the new dialog, and I'm fairly certain our users won't find that easily.

@RussKie
Copy link
Member

RussKie commented Aug 27, 2024

Is this correct placeholder text? Should it be "...using git-grep"?
image

RussKie added a commit to RussKie/gitextensions that referenced this pull request Aug 27, 2024
@gerhardol
Copy link
Member Author

@gerhardol do we have any docs on how to use this feature? It took me awhile to find that I have to use CTRL + SHIFT + F to open the new dialog, and I'm fairly certain our users won't find that easily.

More info in the PR.

Is this correct placeholder text? Should it be "...using git-grep"?

The name of the function settled on "Search files in commit" not including git-grep. Mentioning the Git concept could be good, but "Search files in commit with gith git-grep using a regular expression" is quite long

@RussKie
Copy link
Member

RussKie commented Aug 28, 2024

Mentioning the Git concept could be good, but "Search files in commit with gith git-grep using a regular expression" is quite long

This is a good description for the docs. 😉

RussKie added a commit to RussKie/gitextensions that referenced this pull request Sep 10, 2024
gerhardol pushed a commit to RussKie/gitextensions that referenced this pull request Sep 19, 2024
Align names:
FindInCommitFilesGitGrep in names (not Using)
Find in commit files using git-grep in texts

Addendum to gitextensions#11350
mstv pushed a commit to RussKie/gitextensions that referenced this pull request Sep 27, 2024
Align names:
FindInCommitFilesGitGrep in names (not Using)
Find in commit files using git-grep in texts

Addendum to gitextensions#11350
mstv pushed a commit to RussKie/gitextensions that referenced this pull request Sep 27, 2024
Align names:
FindInCommitFilesGitGrep in names (not Using)
Find in commit files using git-grep in texts

Refs: gitextensions#11858, addendum to gitextensions#11350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search in repository (enhanced UI for git grep)
5 participants