1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-04 23:37:41 +02:00

Extract a function findCommit

It's not much code, but it turns three lines of code into one, and since we need
to do this a few more times in the next commit, it's worth it.
This commit is contained in:
Stefan Haller 2024-05-20 19:01:05 +02:00
parent 2c9bca8b57
commit c1a65546ad

View File

@ -76,9 +76,7 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error {
return fmt.Errorf("%s\n\n%s", message, subjects)
}
commit, index, ok := lo.FindIndexOf(self.c.Model().Commits, func(commit *models.Commit) bool {
return commit.Hash == hashes[0]
})
commit, index, ok := self.findCommit(hashes[0])
if !ok {
commits := self.c.Model().Commits
if commits[len(commits)-1].Status == models.StatusMerged {
@ -221,3 +219,9 @@ func (self *FixupHelper) blameDeletedLines(deletedLineHunks []*hunk) ([]string,
return result.ToSlice(), errg.Wait()
}
func (self *FixupHelper) findCommit(hash string) (*models.Commit, int, bool) {
return lo.FindIndexOf(self.c.Model().Commits, func(commit *models.Commit) bool {
return commit.Hash == hash
})
}