Skip to content

Add search bar at bottom of revlog #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 91 commits into from

Conversation

WizardOhio24
Copy link
Contributor

@WizardOhio24 WizardOhio24 commented Feb 4, 2021

Closes #429, Closes #449, (part of 1.0 todo list)

Adds a search bar at the bottom of the log tab which allows for searching commits. It works, but I'm not sure what keys are best for accessing this. Go to log tab then press s (suggested in #449), the search box will pop up and be in focus, type to search, the results will appear in the log where the arrow keys can scroll through them. Press esc to close the search box, then esc again to cancel the search and return to all commits.

TODO:

  • Async filtering
  • Filter by sha (with :s)
  • Filter by author (with :a)
  • Filter by message (with :m)
  • Filter by tag (with :t)
  • Support for complement (i.e. not) filtering (with :!)
  • Support for union filtering (with ||)
  • Support for intersection filtering (with &&)
  • Support case sensitive filtering (with :c)
  • Support brackets and nested brackets in search
  • Make a wrapper around git_log which supports filtering and have revlog use that instead of git_log, not going to implement because it might not be better right now

Within the search:

  • :s xxx filters only shas for xxx
  • :a xxx filters only authors for xxx
  • :m xxx filters only messages for xxx
  • :t xxx filters only tags for xxx
    These can be combined to :sam(any order works, so :asm or :sma works as well) to search for all, which is equivalent to putting nothing at the start

Complement filtering is possible with :!, which returns anything not containing what was searched for, for example to get all commits whose messages do not contain 'fix' or 'remove':

  • :!m fix &&:!m remove

Case sensitive filtering is possible with :c, for example, to find messages which contain 'Fix' and do not contain 'fix':

  • :c Fix

This also adds support for intersection filtering using &&(i.e only if 'x' and 'y'), for example, to find commits where author name contains 'richard' and the commits message has 'fix' in it:

  • :a richard&&:m fix

And support for union filtering using ||(i.e or), for example to find any commits whose message contains 'fix' or 'move' or any commits which contain aabb':

  • :m fix ||:m move || aabb
    (notice spaces at start and end are irrelevant, they are trimmed, but : must come before a space if filtering by something).

Intersection is currently always higher priority than union, for example, to find commit message which contain 'fix' and 'readme' or contain move = :m fix&&:m readme || move which is equivalent to ((:m fix&&:m readme) || move ).

And so, for a more complex query:

  • :m fix && :m revlog ||:a richard &&:m status ||:s aabb ||:mc Remove || :!cm bigger

For another example, show the commits which have tags where the commits contain 'pre' or ('fix' and 'CD'):

  • :t &&(:m pre ||(:m fix&&:m CD))

Some screenshots

Screenshot_20210213_154144

Screenshot_20210213_152955

Screenshot_20210213_153014

Screenshot_20210213_153851

@WizardOhio24
Copy link
Contributor Author

I'm thinking a good way to implement this could be: in the log tab press : to bring up the search bar then type to search. The up and down arrows should still work in the log. Then press esc to close the search.

@extrawurst
Copy link
Collaborator

@WizardOhio24 I don't see any change in the asyncgit crate which makes me assume you only filter on the local items. I would assume to filter the entire log history and not only the one we store in the application

@extrawurst extrawurst marked this pull request as draft February 4, 2021 12:17
@WizardOhio24
Copy link
Contributor Author

Could you provide an example, when you search for the first commit sha, this is the result:
Screenshot_20210204_125734

The commit number at the top is incorrect, but the commit is correct.
Even just what I should search for, that the search doesn't find.

@extrawurst
Copy link
Collaborator

revlog.rs(37):

static LIMIT_COUNT: usize = 3000;

so we only ever have 3k revision in memory at once. checkout a repo that has more than that and try to find something old, then it won't be searched.

@WizardOhio24
Copy link
Contributor Author

Tried :, but now think s is better. Here's how it works:

Go to log tab
Press s (it's also a command at the bottom)
Type to search (updates dynamically)
Press esc to close the search box
Press esc again (now on log tab), to cancel search.

That seems to work reasonably well.

@WizardOhio24
Copy link
Contributor Author

And it now filters all commits (I think), which might be expensive, so it only does it once when beginning a search, if it must.

@WizardOhio24
Copy link
Contributor Author

Everything seems to work in this now, just need to stop the help message opening when typing into the text input.

@extrawurst
Copy link
Collaborator

@WizardOhio24 can you rebase this onto master?

@extrawurst extrawurst force-pushed the master branch 2 times, most recently from 81a8849 to f84f6f4 Compare March 3, 2021 21:27
@@ -40,6 +40,7 @@ serde = "1.0"
anyhow = "1.0.38"
unicode-width = "0.1"
textwrap = "0.13"
parking_lot = "0.11"
Copy link
Collaborator

Choose a reason for hiding this comment

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

what reasoning went into using Mutex from parking_lot vs using the regular Mutex from std that we use everywhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was because I think it's faster and it's already used as a dependency in some of the crates GitUI uses, happy to use the normal mutexes instead though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah lets keep it consistent

@@ -208,27 +210,21 @@ impl KeyConfig {
| KeyCode::BackTab
| KeyCode::Delete
| KeyCode::Insert
| KeyCode::Esc => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what changed here?

@@ -166,6 +202,160 @@ impl Revlog {
tags.and_then(|tags| tags.get(&commit).cloned())
})
}

fn get_what_to_filter_by(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this giant method could use some doc and test

Self::get_tags(&filter_strings, &mut self.git_tags)?;

rayon_core::spawn(move || {
// Only 1 thread can filter at a time
Copy link
Collaborator

Choose a reason for hiding this comment

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

we use atomics in the other async bits to limit only one running at a time

///
/// vec [vec![A], vec![B, C, D], vec![E]]
#[allow(clippy::too_many_lines)]
pub fn filter(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this needs unittesting

@extrawurst
Copy link
Collaborator

closing in favour of #672

@extrawurst extrawurst closed this May 18, 2021
@c02y
Copy link

c02y commented Apr 28, 2022

I have been using tig for years, now I'm considering switching to lazygit or gitui, don't know which one is better, googled for a while, except for some benchmarks make two years ago, didn't find any useful info, so I tried to use both of them and decide by myself, just try gitui, didn't find a simple search function anywhere, it should be anywhere inside the session like tig or lazygit, so how to can find something in some tab like the list of log?

Sorry, I'm switching to lazygit, or maybe back to tig if I'm not satisfied with lazygit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search commits by sha Search commits for message or author
3 participants