diff options
author | Ryooooooga <eial5q265e5@gmail.com> | 2023-02-10 21:44:15 +0900 |
---|---|---|
committer | Ryooooooga <eial5q265e5@gmail.com> | 2023-02-27 15:29:00 +0900 |
commit | a624e0457f419f353b57bf5e81955438fa4541fc (patch) | |
tree | a2238d4e08fd18901acf1992c480b08952d9bd7a | |
parent | f2aa7e7e284c0634d30fd0c80e5421fb1e0dd13c (diff) |
feat(subcommits): load unlimited sub-commits
-rw-r--r-- | pkg/gui/context/sub_commits_context.go | 25 | ||||
-rw-r--r-- | pkg/gui/controllers.go | 7 | ||||
-rw-r--r-- | pkg/gui/controllers/switch_to_sub_commits_controller.go | 3 | ||||
-rw-r--r-- | pkg/gui/gui.go | 1 | ||||
-rw-r--r-- | pkg/gui/list_context_config.go | 2 | ||||
-rw-r--r-- | pkg/gui/refresh.go | 22 | ||||
-rw-r--r-- | pkg/gui/sub_commits_panel.go | 19 | ||||
-rw-r--r-- | pkg/gui/types/common.go | 1 |
8 files changed, 71 insertions, 9 deletions
diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 4070f0390..5fdea8e6d 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -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) SetRef(ref types.Ref) { + self.ref = ref } -func (self *SubCommitsViewModel) SetRefName(refName string) { - self.refName = refName +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 } diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index d7f6647c7..80b7d9e80 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -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, diff --git a/pkg/gui/controllers/switch_to_sub_commits_controller.go b/pkg/gui/controllers/switch_to_sub_commits_controller.go index dfc538ee8..2e9d25e09 100644 --- a/pkg/gui/controllers/switch_to_sub_commits_controller.go +++ b/pkg/gui/controllers/switch_to_sub_commits_controller.go @@ -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 { diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index bcc3400e3..3dcf146dc 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -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{}, diff --git a/pkg/gui/list_context_config.go b/pkg/gui/list_context_config.go index d463c2ac5..7d783b3d0 100644 --- a/pkg/gui/list_context_config.go +++ b/pkg/gui/list_context_config.go @@ -165,7 +165,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext { git_commands.NewNullBisectInfo(), ) }, - nil, + OnFocusWrapper(gui.onSubCommitFocus), gui.withDiffModeCheck(gui.subCommitsRenderToMain), nil, gui.c, diff --git a/pkg/gui/refresh.go b/pkg/gui/refresh.go index 77dea9e86..654905e46 100644 --- a/pkg/gui/refresh.go +++ b/pkg/gui/refresh.go @@ -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) +} diff --git a/pkg/gui/sub_commits_panel.go b/pkg/gui/sub_commits_panel.go index f68678008..bcc63bbb7 100644 --- a/pkg/gui/sub_commits_panel.go +++ b/pkg/gui/sub_commits_panel.go @@ -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 diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index ab8f6b2b8..fc8f00f12 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -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 |