-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add option to filter by changes (-S flag) #4383
base: master
Are you sure you want to change the base?
Conversation
@r-darwish could you please explain what this PR intends to do in the PR description. 'changes' is ambiguous |
Done 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking forward to having this in the codebase. Mostly we need to update the naming to be more aligned with git's own terminology i.e. 'pickaxe search', 'pickaxe string'.
@@ -46,6 +46,24 @@ type ModeStatus struct { | |||
Reset func() error | |||
} | |||
|
|||
func (self *ModeHelper) getFilter() string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return two strings: one for the type of thing we're filtering by, and one for the value. That removes the ambiguity
self.c.Prompt(types.PromptOpts{ | ||
Title: self.c.Tr.EnterChanges, | ||
HandleConfirm: func(response string) error { | ||
return self.setFilteringChanges(strings.TrimSpace(response)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we shouldn't trim space now that we support filtering by patch content. Often you actually do care about trailing/leading space when doing that.
@@ -23,7 +23,7 @@ func NewReflogCommitLoader(common *common.Common, cmd oscommands.ICmdObjBuilder) | |||
|
|||
// GetReflogCommits only returns the new reflog commits since the given lastReflogCommit | |||
// if none is passed (i.e. it's value is nil) then we get all the reflog commits | |||
func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string, filterAuthor string) ([]*models.Commit, bool, error) { | |||
func (self *ReflogCommitLoader) GetReflogCommits(lastReflogCommit *models.Commit, filterPath string, filterAuthor string, filterChanges string) ([]*models.Commit, bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now has too many positional parameters: let's introduce a CommitFilters struct which contains Path, Author, and PickaxeString fields.
Seems Pickaxe is the official term (https://git-scm.com/book/en/v2/Git-Tools-Searching):
we can use the -S option (colloquially referred to as the Git “pickaxe” option) to tell Git to show us only those commits that changed the number of occurrences of that string.
EnterFileName: "Enter path:", | ||
EnterAuthor: "Enter author:", | ||
EnterChanges: "Enter changes:", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EnterChanges: "Enter changes:", | |
EnterChanges: "Enter string:", |
@@ -1637,8 +1639,10 @@ func EnglishTranslationSet() *TranslationSet { | |||
ExitFilterMode: "Stop filtering", | |||
FilterPathOption: "Enter path to filter by", | |||
FilterAuthorOption: "Enter author to filter by", | |||
FilterChangesOption: "Enter changes to filter by", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FilterChangesOption: "Enter changes to filter by", | |
FilterChangesOption: "Enter patch string to filter by (pickaxe search)", |
1. Start lazygit with the -f flag e.g. `lazygit -f my/path` | ||
2. From within lazygit, press `<c-s>` and then enter the path of the file you want to filter by | ||
|
||
## Filtering by changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Filtering by changes | |
## Filtering by patch content (pickaxe search) |
return err | ||
} | ||
|
||
if self.c.Modes().Filtering.Active() { | ||
if err := refresh(&model.FilteredReflogCommits, self.c.Modes().Filtering.GetPath(), self.c.Modes().Filtering.GetAuthor()); err != nil { | ||
if err := refresh(&model.FilteredReflogCommits, self.c.Modes().Filtering.GetPath(), self.c.Modes().Filtering.GetAuthor(), self.c.Modes().Filtering.GetChanges()); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even here I'd just go self.c.Modes().Filtering.GetFilters()
and have that return a CommitFilters struct.
SetupConfig: func(config *config.AppConfig) { | ||
}, | ||
SetupRepo: func(shell *Shell) { | ||
shell.CreateNCommits(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to explicitly add files and associated commits, just to make this more readable. At the moment the reader has to look up the definition of CreateNCommits to see the relationship between the commit messages and their corresponding file changes. The shell.CreateNCommits
is really a convenience function for when you just need multiple commits, but in this case we specifically want to be filtering based on the contents of those commits.
This PR introduces the ability to filter logs by specific strings that appear in the patch itself. It uses Git's
-S
flag under the hood.go generate ./...
)