From 4bcf3e181cad97b90e6ce8e8f9341a6d2b1ee2f5 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 15 Jan 2026 20:18:35 +0100 Subject: [PATCH] Extract a helper method getCommitsForHashes --- pkg/gui/controllers/helpers/fixup_helper.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/gui/controllers/helpers/fixup_helper.go b/pkg/gui/controllers/helpers/fixup_helper.go index 054a5bbf1..c670b9dfb 100644 --- a/pkg/gui/controllers/helpers/fixup_helper.go +++ b/pkg/gui/controllers/helpers/fixup_helper.go @@ -144,20 +144,27 @@ func (self *FixupHelper) HandleFindBaseCommitForFixupPress() error { }) } -func getHashesAndSubjects(commits []*models.Commit, hashes []string) string { +func getCommitsForHashes(commits []*models.Commit, hashes []string) []*models.Commit { // This is called only for the NOT_MERGED commits, and we know that all of them are contained in // the commits slice. commitsSet := set.NewFromSlice(hashes) - subjects := make([]string, 0, len(hashes)) + result := make([]*models.Commit, 0, len(hashes)) for _, c := range commits { if commitsSet.Includes(c.Hash()) { - subjects = append(subjects, fmt.Sprintf("%s %s", c.ShortRefName(), c.Name)) + result = append(result, c) commitsSet.Remove(c.Hash()) if commitsSet.Len() == 0 { break } } } + return result +} + +func getHashesAndSubjects(commits []*models.Commit, hashes []string) string { + subjects := lo.Map(getCommitsForHashes(commits, hashes), func(c *models.Commit, _ int) string { + return fmt.Sprintf("%s %s", c.ShortRefName(), c.Name) + }) return strings.Join(subjects, "\n") }