Skip to content

Commit

Permalink
feat(subcommits): load unlimited sub-commits
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryooooooga committed Feb 27, 2023
1 parent f2aa7e7 commit a624e04
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 9 deletions.
25 changes: 20 additions & 5 deletions pkg/gui/context/sub_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func NewSubCommitsContext(
) *SubCommitsContext {
viewModel := &SubCommitsViewModel{
BasicViewModel: NewBasicViewModel(getModel),
refName: "",
ref: nil,
limitCommits: true,
}

return &SubCommitsContext{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
7 changes: 6 additions & 1 deletion pkg/gui/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion pkg/gui/controllers/switch_to_sub_commits_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions pkg/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/list_context_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
git_commands.NewNullBisectInfo(),
)
},
nil,
OnFocusWrapper(gui.onSubCommitFocus),
gui.withDiffModeCheck(gui.subCommitsRenderToMain),
nil,
gui.c,
Expand Down
22 changes: 22 additions & 0 deletions pkg/gui/refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
19 changes: 18 additions & 1 deletion pkg/gui/sub_commits_panel.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/gui/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a624e04

Please sign in to comment.