1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

Move the Ref interface from gui/types to models

This is a type that can be useful for model/backend stuff, so move it there. We
are going to use it in the API of the commit loader.
This commit is contained in:
Stefan Haller
2025-07-31 11:20:05 +02:00
parent cc0b5a2f7f
commit 4b9921d0a4
15 changed files with 35 additions and 30 deletions

View File

@ -1,4 +1,4 @@
package types
package models
type Ref interface {
FullRefName() string
@ -7,8 +7,3 @@ type Ref interface {
ParentRefName() string
Description() string
}
type RefRange struct {
From Ref
To Ref
}

View File

@ -59,7 +59,7 @@ func NewBranchesContext(c *ContextCommon) *BranchesContext {
return self
}
func (self *BranchesContext) GetSelectedRef() types.Ref {
func (self *BranchesContext) GetSelectedRef() models.Ref {
branch := self.GetSelected()
if branch == nil {
return nil

View File

@ -96,7 +96,7 @@ func (self *CommitFilesContext) ModelSearchResults(searchStr string, caseSensiti
return nil
}
func (self *CommitFilesContext) ReInit(ref types.Ref, refRange *types.RefRange) {
func (self *CommitFilesContext) ReInit(ref models.Ref, refRange *types.RefRange) {
self.SetRef(ref)
self.SetRefRange(refRange)
if refRange != nil {

View File

@ -164,7 +164,7 @@ func (self *LocalCommitsContext) CanRebase() bool {
return true
}
func (self *LocalCommitsContext) GetSelectedRef() types.Ref {
func (self *LocalCommitsContext) GetSelectedRef() models.Ref {
commit := self.GetSelected()
if commit == nil {
return nil

View File

@ -63,7 +63,7 @@ func (self *ReflogCommitsContext) CanRebase() bool {
return false
}
func (self *ReflogCommitsContext) GetSelectedRef() types.Ref {
func (self *ReflogCommitsContext) GetSelectedRef() models.Ref {
commit := self.GetSelected()
if commit == nil {
return nil

View File

@ -54,7 +54,7 @@ func NewRemoteBranchesContext(
}
}
func (self *RemoteBranchesContext) GetSelectedRef() types.Ref {
func (self *RemoteBranchesContext) GetSelectedRef() models.Ref {
remoteBranch := self.GetSelected()
if remoteBranch == nil {
return nil
@ -62,10 +62,10 @@ func (self *RemoteBranchesContext) GetSelectedRef() types.Ref {
return remoteBranch
}
func (self *RemoteBranchesContext) GetSelectedRefs() ([]types.Ref, int, int) {
func (self *RemoteBranchesContext) GetSelectedRefs() ([]models.Ref, int, int) {
items, startIdx, endIdx := self.GetSelectedItems()
refs := lo.Map(items, func(item *models.RemoteBranch, _ int) types.Ref {
refs := lo.Map(items, func(item *models.RemoteBranch, _ int) models.Ref {
return item
})

View File

@ -53,7 +53,7 @@ func (self *StashContext) CanRebase() bool {
return false
}
func (self *StashContext) GetSelectedRef() types.Ref {
func (self *StashContext) GetSelectedRef() models.Ref {
stash := self.GetSelected()
if stash == nil {
return nil

View File

@ -141,7 +141,7 @@ func NewSubCommitsContext(
type SubCommitsViewModel struct {
// name of the ref that the sub-commits are shown for
ref types.Ref
ref models.Ref
refToShowDivergenceFrom string
*ListViewModel[*models.Commit]
@ -149,11 +149,11 @@ type SubCommitsViewModel struct {
showBranchHeads bool
}
func (self *SubCommitsViewModel) SetRef(ref types.Ref) {
func (self *SubCommitsViewModel) SetRef(ref models.Ref) {
self.ref = ref
}
func (self *SubCommitsViewModel) GetRef() types.Ref {
func (self *SubCommitsViewModel) GetRef() models.Ref {
return self.ref
}
@ -177,7 +177,7 @@ func (self *SubCommitsContext) CanRebase() bool {
return false
}
func (self *SubCommitsContext) GetSelectedRef() types.Ref {
func (self *SubCommitsContext) GetSelectedRef() models.Ref {
commit := self.GetSelected()
if commit == nil {
return nil

View File

@ -52,7 +52,7 @@ func NewTagsContext(
}
}
func (self *TagsContext) GetSelectedRef() types.Ref {
func (self *TagsContext) GetSelectedRef() models.Ref {
tag := self.GetSelected()
if tag == nil {
return nil

View File

@ -174,7 +174,7 @@ func (self *DiffHelper) IgnoringWhitespaceSubTitle() string {
return ""
}
func (self *DiffHelper) OpenDiffToolForRef(selectedRef types.Ref) error {
func (self *DiffHelper) OpenDiffToolForRef(selectedRef models.Ref) error {
to := selectedRef.RefName()
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff("")
_, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj(

View File

@ -24,7 +24,7 @@ func NewSubCommitsHelper(
}
type ViewSubCommitsOpts struct {
Ref types.Ref
Ref models.Ref
RefToShowDivergenceFrom string
TitleRef string
Context types.Context

View File

@ -1,6 +1,7 @@
package controllers
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -11,7 +12,7 @@ var _ types.IController = &SwitchToDiffFilesController{}
type CanSwitchToDiffFiles interface {
types.IListContext
CanRebase() bool
GetSelectedRef() types.Ref
GetSelectedRef() models.Ref
GetSelectedRefRangeForDiffFiles() *types.RefRange
}

View File

@ -1,6 +1,7 @@
package controllers
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
"github.com/jesseduffield/lazygit/pkg/gui/types"
)
@ -9,7 +10,7 @@ var _ types.IController = &SwitchToSubCommitsController{}
type CanSwitchToSubCommits interface {
types.IListContext
GetSelectedRef() types.Ref
GetSelectedRef() models.Ref
ShowBranchHeadsInSubCommits() bool
}
@ -17,7 +18,7 @@ type CanSwitchToSubCommits interface {
// but an attribute on it i.e. the ref of an item.
type SwitchToSubCommitsController struct {
baseController
*ListControllerTrait[types.Ref]
*ListControllerTrait[models.Ref]
c *ControllerCommon
context CanSwitchToSubCommits
}
@ -32,7 +33,7 @@ func NewSwitchToSubCommitsController(
c,
context,
context.GetSelectedRef,
func() ([]types.Ref, int, int) {
func() ([]models.Ref, int, int) {
panic("Not implemented")
},
),

View File

@ -15,8 +15,8 @@ type ICommitFileTreeViewModel interface {
ICommitFileTree
types.IListCursor
GetRef() types.Ref
SetRef(types.Ref)
GetRef() models.Ref
SetRef(models.Ref)
GetRefRange() *types.RefRange // can be nil, in which case GetRef should be used
SetRefRange(*types.RefRange) // should be set to nil when selection is not a range
GetCanRebase() bool
@ -30,7 +30,7 @@ type CommitFileTreeViewModel struct {
// this is e.g. the commit for which we're viewing the files, if there is no
// range selection, or if the range selection can't be used for some reason
ref types.Ref
ref models.Ref
// this is a commit range for which we're viewing the files. Can be nil, in
// which case ref is used.
@ -55,11 +55,11 @@ func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, common *co
}
}
func (self *CommitFileTreeViewModel) GetRef() types.Ref {
func (self *CommitFileTreeViewModel) GetRef() models.Ref {
return self.ref
}
func (self *CommitFileTreeViewModel) SetRef(ref types.Ref) {
func (self *CommitFileTreeViewModel) SetRef(ref models.Ref) {
self.ref = ref
}

View File

@ -0,0 +1,8 @@
package types
import "github.com/jesseduffield/lazygit/pkg/commands/models"
type RefRange struct {
From models.Ref
To models.Ref
}