mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55:47 +02:00
Remove bool return value of GetParentContext()
The comments that I'm deleting here explain why we need the bool; however, in our case that's a theoretical issue. It would only arise if we ever were to pass a nil context to SetParentContext, which we never do.
This commit is contained in:
parent
d570552206
commit
1eb5d89f1d
5 changed files with 9 additions and 13 deletions
|
@ -4,17 +4,14 @@ import "github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
|
|
||||||
type ParentContextMgr struct {
|
type ParentContextMgr struct {
|
||||||
ParentContext types.Context
|
ParentContext types.Context
|
||||||
// we can't know on the calling end whether a Context is actually a nil value without reflection, so we're storing this flag here to tell us. There has got to be a better way around this
|
|
||||||
hasParent bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ types.ParentContexter = (*ParentContextMgr)(nil)
|
var _ types.ParentContexter = (*ParentContextMgr)(nil)
|
||||||
|
|
||||||
func (self *ParentContextMgr) SetParentContext(context types.Context) {
|
func (self *ParentContextMgr) SetParentContext(context types.Context) {
|
||||||
self.ParentContext = context
|
self.ParentContext = context
|
||||||
self.hasParent = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ParentContextMgr) GetParentContext() (types.Context, bool) {
|
func (self *ParentContextMgr) GetParentContext() types.Context {
|
||||||
return self.ParentContext, self.hasParent
|
return self.ParentContext
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,8 +178,8 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error {
|
func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error {
|
||||||
parentContext, ok := self.c.Context().Current().GetParentContext()
|
parentContext := self.c.Context().Current().GetParentContext()
|
||||||
if !ok || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY {
|
if parentContext == nil || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY {
|
||||||
return errors.New(self.c.Tr.CanOnlyDiscardFromLocalCommits)
|
return errors.New(self.c.Tr.CanOnlyDiscardFromLocalCommits)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -276,8 +276,8 @@ func (self *RefreshHelper) refreshReflogAndBranches(refreshWorktrees bool, keepB
|
||||||
|
|
||||||
func (self *RefreshHelper) refreshCommitsAndCommitFiles() {
|
func (self *RefreshHelper) refreshCommitsAndCommitFiles() {
|
||||||
_ = self.refreshCommitsWithLimit()
|
_ = self.refreshCommitsWithLimit()
|
||||||
ctx, ok := self.c.Contexts().CommitFiles.GetParentContext()
|
ctx := self.c.Contexts().CommitFiles.GetParentContext()
|
||||||
if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
|
if ctx != nil && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
|
||||||
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit hash at the same position.
|
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit hash at the same position.
|
||||||
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
|
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
|
||||||
// showing the contents of a different commit than the one we initially entered.
|
// showing the contents of a different commit than the one we initially entered.
|
||||||
|
|
|
@ -71,8 +71,8 @@ func (self *QuitActions) Escape() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parentContext, hasParent := currentContext.GetParentContext()
|
parentContext := currentContext.GetParentContext()
|
||||||
if hasParent && currentContext != nil && parentContext != nil {
|
if parentContext != nil {
|
||||||
// TODO: think about whether this should be marked as a return rather than adding to the stack
|
// TODO: think about whether this should be marked as a return rather than adding to the stack
|
||||||
return self.c.Context().Push(parentContext)
|
return self.c.Context().Push(parentContext)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,7 @@ const (
|
||||||
|
|
||||||
type ParentContexter interface {
|
type ParentContexter interface {
|
||||||
SetParentContext(Context)
|
SetParentContext(Context)
|
||||||
// we return a bool here to tell us whether or not the returned value just wraps a nil
|
GetParentContext() Context
|
||||||
GetParentContext() (Context, bool)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type NeedsRerenderOnWidthChangeLevel int
|
type NeedsRerenderOnWidthChangeLevel int
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue