mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
This in itself is not an improvement, because hashes are unique (they are shared between real commits and rebase todos, but there are so few of those that it doesn't matter). However, it becomes an improvement once we also store parent hashes in the same pool; but the real motivation for this change is to also reuse the hash pointers in Pipe objects later in the branch. This will be a big win because in a merge-heavy git repo there are many more Pipe instances than commits.
75 lines
2.3 KiB
Go
75 lines
2.3 KiB
Go
package helpers
|
|
|
|
import (
|
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
)
|
|
|
|
type SubCommitsHelper struct {
|
|
c *HelperCommon
|
|
|
|
refreshHelper *RefreshHelper
|
|
setSubCommits func([]*models.Commit)
|
|
}
|
|
|
|
func NewSubCommitsHelper(
|
|
c *HelperCommon,
|
|
refreshHelper *RefreshHelper,
|
|
setSubCommits func([]*models.Commit),
|
|
) *SubCommitsHelper {
|
|
return &SubCommitsHelper{
|
|
c: c,
|
|
refreshHelper: refreshHelper,
|
|
setSubCommits: setSubCommits,
|
|
}
|
|
}
|
|
|
|
type ViewSubCommitsOpts struct {
|
|
Ref types.Ref
|
|
RefToShowDivergenceFrom string
|
|
TitleRef string
|
|
Context types.Context
|
|
ShowBranchHeads bool
|
|
}
|
|
|
|
func (self *SubCommitsHelper) ViewSubCommits(opts ViewSubCommitsOpts) error {
|
|
commits, err := self.c.Git().Loaders.CommitLoader.GetCommits(
|
|
git_commands.GetCommitsOptions{
|
|
Limit: true,
|
|
FilterPath: self.c.Modes().Filtering.GetPath(),
|
|
FilterAuthor: self.c.Modes().Filtering.GetAuthor(),
|
|
IncludeRebaseCommits: false,
|
|
RefName: opts.Ref.FullRefName(),
|
|
RefForPushedStatus: opts.Ref.FullRefName(),
|
|
RefToShowDivergenceFrom: opts.RefToShowDivergenceFrom,
|
|
MainBranches: self.c.Model().MainBranches,
|
|
HashPool: self.c.Model().HashPool,
|
|
},
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
self.setSubCommits(commits)
|
|
self.refreshHelper.RefreshAuthors(commits)
|
|
|
|
subCommitsContext := self.c.Contexts().SubCommits
|
|
subCommitsContext.SetSelection(0)
|
|
subCommitsContext.SetParentContext(opts.Context)
|
|
subCommitsContext.SetWindowName(opts.Context.GetWindowName())
|
|
subCommitsContext.SetTitleRef(utils.TruncateWithEllipsis(opts.TitleRef, 50))
|
|
subCommitsContext.SetRef(opts.Ref)
|
|
subCommitsContext.SetRefToShowDivergenceFrom(opts.RefToShowDivergenceFrom)
|
|
subCommitsContext.SetLimitCommits(true)
|
|
subCommitsContext.SetShowBranchHeads(opts.ShowBranchHeads)
|
|
subCommitsContext.ClearSearchString()
|
|
subCommitsContext.GetView().ClearSearch()
|
|
subCommitsContext.GetView().TitlePrefix = opts.Context.GetView().TitlePrefix
|
|
|
|
self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
|
|
|
|
self.c.Context().Push(self.c.Contexts().SubCommits, types.OnFocusOpts{})
|
|
return nil
|
|
}
|