1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-11-28 09:08:41 +02:00

feat(subcommits): load unlimited sub-commits

This commit is contained in:
Ryooooooga 2023-02-10 21:44:15 +09:00
parent f2aa7e7e28
commit a624e0457f
No known key found for this signature in database
GPG Key ID: 07CF200DFCC20C25
8 changed files with 71 additions and 9 deletions

View File

@ -30,7 +30,8 @@ func NewSubCommitsContext(
) *SubCommitsContext {
viewModel := &SubCommitsViewModel{
BasicViewModel: NewBasicViewModel(getModel),
refName: "",
ref: nil,
limitCommits: true,
}
return &SubCommitsContext{
@ -60,12 +61,18 @@ func NewSubCommitsContext(
type SubCommitsViewModel struct {
// name of the ref that the sub-commits are shown for
refName string
ref types.Ref
*BasicViewModel[*models.Commit]
limitCommits bool
}
func (self *SubCommitsViewModel) SetRefName(refName string) {
self.refName = refName
func (self *SubCommitsViewModel) SetRef(ref types.Ref) {
self.ref = ref
}
func (self *SubCommitsViewModel) GetRef() types.Ref {
return self.ref
}
func (self *SubCommitsContext) GetSelectedItemId() string {
@ -94,5 +101,13 @@ func (self *SubCommitsContext) GetCommits() []*models.Commit {
}
func (self *SubCommitsContext) Title() string {
return fmt.Sprintf(self.c.Tr.SubCommitsDynamicTitle, utils.TruncateWithEllipsis(self.refName, 50))
return fmt.Sprintf(self.c.Tr.SubCommitsDynamicTitle, utils.TruncateWithEllipsis(self.ref.RefName(), 50))
}
func (self *SubCommitsContext) SetLimitCommits(value bool) {
self.limitCommits = value
}
func (self *SubCommitsContext) GetLimitCommits() bool {
return self.limitCommits
}

View File

@ -133,7 +133,12 @@ func (gui *Gui) resetControllers() {
patchBuildingController := controllers.NewPatchBuildingController(common)
snakeController := controllers.NewSnakeController(common, func() *snake.Game { return gui.snakeGame })
setSubCommits := func(commits []*models.Commit) { gui.State.Model.SubCommits = commits }
setSubCommits := func(commits []*models.Commit) {
gui.Mutexes.SubCommitsMutex.Lock()
defer gui.Mutexes.SubCommitsMutex.Unlock()
gui.State.Model.SubCommits = commits
}
for _, context := range []controllers.CanSwitchToSubCommits{
gui.State.Contexts.Branches,

View File

@ -75,7 +75,8 @@ func (self *SwitchToSubCommitsController) viewCommits() error {
self.contexts.SubCommits.SetParentContext(self.context)
self.contexts.SubCommits.SetWindowName(self.context.GetWindowName())
self.contexts.SubCommits.SetTitleRef(ref.Description())
self.contexts.SubCommits.SetRefName(ref.RefName())
self.contexts.SubCommits.SetRef(ref)
self.contexts.SubCommits.SetLimitCommits(true)
err = self.c.PostRefreshUpdate(self.contexts.SubCommits)
if err != nil {

View File

@ -380,6 +380,7 @@ func NewGui(
RefreshingStatusMutex: &deadlock.Mutex{},
SyncMutex: &deadlock.Mutex{},
LocalCommitsMutex: &deadlock.Mutex{},
SubCommitsMutex: &deadlock.Mutex{},
SubprocessMutex: &deadlock.Mutex{},
PopupMutex: &deadlock.Mutex{},
PtyMutex: &deadlock.Mutex{},

View File

@ -165,7 +165,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
git_commands.NewNullBisectInfo(),
)
},
nil,
OnFocusWrapper(gui.onSubCommitFocus),
gui.withDiffModeCheck(gui.subCommitsRenderToMain),
nil,
gui.c,

View File

@ -720,3 +720,25 @@ func (gui *Gui) refreshMergePanel(isFocused bool) error {
},
})
}
func (gui *Gui) refreshSubCommitsWithLimit() error {
gui.Mutexes.SubCommitsMutex.Lock()
defer gui.Mutexes.SubCommitsMutex.Unlock()
context := gui.State.Contexts.SubCommits
commits, err := gui.git.Loaders.CommitLoader.GetCommits(
git_commands.GetCommitsOptions{
Limit: context.GetLimitCommits(),
FilterPath: gui.State.Modes.Filtering.GetPath(),
IncludeRebaseCommits: false,
RefName: context.GetRef().FullRefName(),
},
)
if err != nil {
return err
}
gui.State.Model.SubCommits = commits
return gui.c.PostRefreshUpdate(gui.State.Contexts.SubCommits)
}

View File

@ -1,9 +1,26 @@
package gui
import "github.com/jesseduffield/lazygit/pkg/gui/types"
import (
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
// list panel functions
func (gui *Gui) onSubCommitFocus() error {
context := gui.State.Contexts.SubCommits
if context.GetSelectedLineIdx() > COMMIT_THRESHOLD && context.GetLimitCommits() {
context.SetLimitCommits(false)
go utils.Safe(func() {
if err := gui.refreshSubCommitsWithLimit(); err != nil {
_ = gui.c.Error(err)
}
})
}
return nil
}
func (gui *Gui) subCommitsRenderToMain() error {
commit := gui.State.Contexts.SubCommits.GetSelected()
var task types.UpdateTask

View File

@ -169,6 +169,7 @@ type Mutexes struct {
RefreshingStatusMutex *deadlock.Mutex
SyncMutex *deadlock.Mutex
LocalCommitsMutex *deadlock.Mutex
SubCommitsMutex *deadlock.Mutex
SubprocessMutex *deadlock.Mutex
PopupMutex *deadlock.Mutex
PtyMutex *deadlock.Mutex