From c1a65546ad7c881e8e34aabafe11161569be3dba Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Mon, 20 May 2024 19:01:05 +0200 Subject: [PATCH] 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. --- pkg/gui/controllers/helpers/fixup_helper.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index f57e8f2f9..e816f425d 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -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 + }) +}