Skip to content

Commit

Permalink
Remove bool return value of GetParentContext()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stefanhaller committed Aug 17, 2024
1 parent d570552 commit 1eb5d89
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
7 changes: 2 additions & 5 deletions pkg/gui/context/parent_context_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import "github.com/jesseduffield/lazygit/pkg/gui/types"

type ParentContextMgr struct {
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)

func (self *ParentContextMgr) SetParentContext(context types.Context) {
self.ParentContext = context
self.hasParent = true
}

func (self *ParentContextMgr) GetParentContext() (types.Context, bool) {
return self.ParentContext, self.hasParent
func (self *ParentContextMgr) GetParentContext() types.Context {
return self.ParentContext
}
4 changes: 2 additions & 2 deletions pkg/gui/controllers/commits_files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ func (self *CommitFilesController) checkout(node *filetree.CommitFileNode) error
}

func (self *CommitFilesController) discard(selectedNodes []*filetree.CommitFileNode) error {
parentContext, ok := self.c.Context().Current().GetParentContext()
if !ok || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY {
parentContext := self.c.Context().Current().GetParentContext()
if parentContext == nil || parentContext.GetKey() != context.LOCAL_COMMITS_CONTEXT_KEY {
return errors.New(self.c.Tr.CanOnlyDiscardFromLocalCommits)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/controllers/helpers/refresh_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ func (self *RefreshHelper) refreshReflogAndBranches(refreshWorktrees bool, keepB

func (self *RefreshHelper) refreshCommitsAndCommitFiles() {
_ = self.refreshCommitsWithLimit()
ctx, ok := self.c.Contexts().CommitFiles.GetParentContext()
if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY {
ctx := self.c.Contexts().CommitFiles.GetParentContext()
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.
// 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.
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/controllers/quit_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ func (self *QuitActions) Escape() error {
}
}

parentContext, hasParent := currentContext.GetParentContext()
if hasParent && currentContext != nil && parentContext != nil {
parentContext := currentContext.GetParentContext()
if parentContext != nil {
// TODO: think about whether this should be marked as a return rather than adding to the stack
return self.c.Context().Push(parentContext)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/gui/types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const (

type ParentContexter interface {
SetParentContext(Context)
// we return a bool here to tell us whether or not the returned value just wraps a nil
GetParentContext() (Context, bool)
GetParentContext() Context
}

type NeedsRerenderOnWidthChangeLevel int
Expand Down

0 comments on commit 1eb5d89

Please sign in to comment.