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:
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
})
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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(
|
||||
|
@ -24,7 +24,7 @@ func NewSubCommitsHelper(
|
||||
}
|
||||
|
||||
type ViewSubCommitsOpts struct {
|
||||
Ref types.Ref
|
||||
Ref models.Ref
|
||||
RefToShowDivergenceFrom string
|
||||
TitleRef string
|
||||
Context types.Context
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
},
|
||||
),
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
8
pkg/gui/types/ref_range.go
Normal file
8
pkg/gui/types/ref_range.go
Normal file
@ -0,0 +1,8 @@
|
||||
package types
|
||||
|
||||
import "github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
|
||||
type RefRange struct {
|
||||
From models.Ref
|
||||
To models.Ref
|
||||
}
|
Reference in New Issue
Block a user