mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
feat(subcommits): load unlimited sub-commits
This commit is contained in:
parent
f2aa7e7e28
commit
a624e0457f
8 changed files with 71 additions and 9 deletions
|
@ -30,7 +30,8 @@ func NewSubCommitsContext(
|
||||||
) *SubCommitsContext {
|
) *SubCommitsContext {
|
||||||
viewModel := &SubCommitsViewModel{
|
viewModel := &SubCommitsViewModel{
|
||||||
BasicViewModel: NewBasicViewModel(getModel),
|
BasicViewModel: NewBasicViewModel(getModel),
|
||||||
refName: "",
|
ref: nil,
|
||||||
|
limitCommits: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &SubCommitsContext{
|
return &SubCommitsContext{
|
||||||
|
@ -60,12 +61,18 @@ func NewSubCommitsContext(
|
||||||
|
|
||||||
type SubCommitsViewModel struct {
|
type SubCommitsViewModel struct {
|
||||||
// name of the ref that the sub-commits are shown for
|
// name of the ref that the sub-commits are shown for
|
||||||
refName string
|
ref types.Ref
|
||||||
*BasicViewModel[*models.Commit]
|
*BasicViewModel[*models.Commit]
|
||||||
|
|
||||||
|
limitCommits bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SubCommitsViewModel) SetRefName(refName string) {
|
func (self *SubCommitsViewModel) SetRef(ref types.Ref) {
|
||||||
self.refName = refName
|
self.ref = ref
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SubCommitsViewModel) GetRef() types.Ref {
|
||||||
|
return self.ref
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SubCommitsContext) GetSelectedItemId() string {
|
func (self *SubCommitsContext) GetSelectedItemId() string {
|
||||||
|
@ -94,5 +101,13 @@ func (self *SubCommitsContext) GetCommits() []*models.Commit {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SubCommitsContext) Title() string {
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,12 @@ func (gui *Gui) resetControllers() {
|
||||||
patchBuildingController := controllers.NewPatchBuildingController(common)
|
patchBuildingController := controllers.NewPatchBuildingController(common)
|
||||||
snakeController := controllers.NewSnakeController(common, func() *snake.Game { return gui.snakeGame })
|
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{
|
for _, context := range []controllers.CanSwitchToSubCommits{
|
||||||
gui.State.Contexts.Branches,
|
gui.State.Contexts.Branches,
|
||||||
|
|
|
@ -75,7 +75,8 @@ func (self *SwitchToSubCommitsController) viewCommits() error {
|
||||||
self.contexts.SubCommits.SetParentContext(self.context)
|
self.contexts.SubCommits.SetParentContext(self.context)
|
||||||
self.contexts.SubCommits.SetWindowName(self.context.GetWindowName())
|
self.contexts.SubCommits.SetWindowName(self.context.GetWindowName())
|
||||||
self.contexts.SubCommits.SetTitleRef(ref.Description())
|
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)
|
err = self.c.PostRefreshUpdate(self.contexts.SubCommits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -380,6 +380,7 @@ func NewGui(
|
||||||
RefreshingStatusMutex: &deadlock.Mutex{},
|
RefreshingStatusMutex: &deadlock.Mutex{},
|
||||||
SyncMutex: &deadlock.Mutex{},
|
SyncMutex: &deadlock.Mutex{},
|
||||||
LocalCommitsMutex: &deadlock.Mutex{},
|
LocalCommitsMutex: &deadlock.Mutex{},
|
||||||
|
SubCommitsMutex: &deadlock.Mutex{},
|
||||||
SubprocessMutex: &deadlock.Mutex{},
|
SubprocessMutex: &deadlock.Mutex{},
|
||||||
PopupMutex: &deadlock.Mutex{},
|
PopupMutex: &deadlock.Mutex{},
|
||||||
PtyMutex: &deadlock.Mutex{},
|
PtyMutex: &deadlock.Mutex{},
|
||||||
|
|
|
@ -165,7 +165,7 @@ func (gui *Gui) subCommitsListContext() *context.SubCommitsContext {
|
||||||
git_commands.NewNullBisectInfo(),
|
git_commands.NewNullBisectInfo(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
nil,
|
OnFocusWrapper(gui.onSubCommitFocus),
|
||||||
gui.withDiffModeCheck(gui.subCommitsRenderToMain),
|
gui.withDiffModeCheck(gui.subCommitsRenderToMain),
|
||||||
nil,
|
nil,
|
||||||
gui.c,
|
gui.c,
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
|
@ -1,9 +1,26 @@
|
||||||
package gui
|
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
|
// 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 {
|
func (gui *Gui) subCommitsRenderToMain() error {
|
||||||
commit := gui.State.Contexts.SubCommits.GetSelected()
|
commit := gui.State.Contexts.SubCommits.GetSelected()
|
||||||
var task types.UpdateTask
|
var task types.UpdateTask
|
||||||
|
|
|
@ -169,6 +169,7 @@ type Mutexes struct {
|
||||||
RefreshingStatusMutex *deadlock.Mutex
|
RefreshingStatusMutex *deadlock.Mutex
|
||||||
SyncMutex *deadlock.Mutex
|
SyncMutex *deadlock.Mutex
|
||||||
LocalCommitsMutex *deadlock.Mutex
|
LocalCommitsMutex *deadlock.Mutex
|
||||||
|
SubCommitsMutex *deadlock.Mutex
|
||||||
SubprocessMutex *deadlock.Mutex
|
SubprocessMutex *deadlock.Mutex
|
||||||
PopupMutex *deadlock.Mutex
|
PopupMutex *deadlock.Mutex
|
||||||
PtyMutex *deadlock.Mutex
|
PtyMutex *deadlock.Mutex
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue