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 {
|
type Ref interface {
|
||||||
FullRefName() string
|
FullRefName() string
|
||||||
@ -7,8 +7,3 @@ type Ref interface {
|
|||||||
ParentRefName() string
|
ParentRefName() string
|
||||||
Description() string
|
Description() string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefRange struct {
|
|
||||||
From Ref
|
|
||||||
To Ref
|
|
||||||
}
|
|
@ -59,7 +59,7 @@ func NewBranchesContext(c *ContextCommon) *BranchesContext {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BranchesContext) GetSelectedRef() types.Ref {
|
func (self *BranchesContext) GetSelectedRef() models.Ref {
|
||||||
branch := self.GetSelected()
|
branch := self.GetSelected()
|
||||||
if branch == nil {
|
if branch == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -96,7 +96,7 @@ func (self *CommitFilesContext) ModelSearchResults(searchStr string, caseSensiti
|
|||||||
return nil
|
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.SetRef(ref)
|
||||||
self.SetRefRange(refRange)
|
self.SetRefRange(refRange)
|
||||||
if refRange != nil {
|
if refRange != nil {
|
||||||
|
@ -164,7 +164,7 @@ func (self *LocalCommitsContext) CanRebase() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *LocalCommitsContext) GetSelectedRef() types.Ref {
|
func (self *LocalCommitsContext) GetSelectedRef() models.Ref {
|
||||||
commit := self.GetSelected()
|
commit := self.GetSelected()
|
||||||
if commit == nil {
|
if commit == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -63,7 +63,7 @@ func (self *ReflogCommitsContext) CanRebase() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ReflogCommitsContext) GetSelectedRef() types.Ref {
|
func (self *ReflogCommitsContext) GetSelectedRef() models.Ref {
|
||||||
commit := self.GetSelected()
|
commit := self.GetSelected()
|
||||||
if commit == nil {
|
if commit == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -54,7 +54,7 @@ func NewRemoteBranchesContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RemoteBranchesContext) GetSelectedRef() types.Ref {
|
func (self *RemoteBranchesContext) GetSelectedRef() models.Ref {
|
||||||
remoteBranch := self.GetSelected()
|
remoteBranch := self.GetSelected()
|
||||||
if remoteBranch == nil {
|
if remoteBranch == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -62,10 +62,10 @@ func (self *RemoteBranchesContext) GetSelectedRef() types.Ref {
|
|||||||
return remoteBranch
|
return remoteBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *RemoteBranchesContext) GetSelectedRefs() ([]types.Ref, int, int) {
|
func (self *RemoteBranchesContext) GetSelectedRefs() ([]models.Ref, int, int) {
|
||||||
items, startIdx, endIdx := self.GetSelectedItems()
|
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
|
return item
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ func (self *StashContext) CanRebase() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *StashContext) GetSelectedRef() types.Ref {
|
func (self *StashContext) GetSelectedRef() models.Ref {
|
||||||
stash := self.GetSelected()
|
stash := self.GetSelected()
|
||||||
if stash == nil {
|
if stash == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -141,7 +141,7 @@ 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
|
||||||
ref types.Ref
|
ref models.Ref
|
||||||
refToShowDivergenceFrom string
|
refToShowDivergenceFrom string
|
||||||
*ListViewModel[*models.Commit]
|
*ListViewModel[*models.Commit]
|
||||||
|
|
||||||
@ -149,11 +149,11 @@ type SubCommitsViewModel struct {
|
|||||||
showBranchHeads bool
|
showBranchHeads bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SubCommitsViewModel) SetRef(ref types.Ref) {
|
func (self *SubCommitsViewModel) SetRef(ref models.Ref) {
|
||||||
self.ref = ref
|
self.ref = ref
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SubCommitsViewModel) GetRef() types.Ref {
|
func (self *SubCommitsViewModel) GetRef() models.Ref {
|
||||||
return self.ref
|
return self.ref
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ func (self *SubCommitsContext) CanRebase() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *SubCommitsContext) GetSelectedRef() types.Ref {
|
func (self *SubCommitsContext) GetSelectedRef() models.Ref {
|
||||||
commit := self.GetSelected()
|
commit := self.GetSelected()
|
||||||
if commit == nil {
|
if commit == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -52,7 +52,7 @@ func NewTagsContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *TagsContext) GetSelectedRef() types.Ref {
|
func (self *TagsContext) GetSelectedRef() models.Ref {
|
||||||
tag := self.GetSelected()
|
tag := self.GetSelected()
|
||||||
if tag == nil {
|
if tag == nil {
|
||||||
return nil
|
return nil
|
||||||
|
@ -174,7 +174,7 @@ func (self *DiffHelper) IgnoringWhitespaceSubTitle() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *DiffHelper) OpenDiffToolForRef(selectedRef types.Ref) error {
|
func (self *DiffHelper) OpenDiffToolForRef(selectedRef models.Ref) error {
|
||||||
to := selectedRef.RefName()
|
to := selectedRef.RefName()
|
||||||
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff("")
|
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff("")
|
||||||
_, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj(
|
_, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj(
|
||||||
|
@ -24,7 +24,7 @@ func NewSubCommitsHelper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ViewSubCommitsOpts struct {
|
type ViewSubCommitsOpts struct {
|
||||||
Ref types.Ref
|
Ref models.Ref
|
||||||
RefToShowDivergenceFrom string
|
RefToShowDivergenceFrom string
|
||||||
TitleRef string
|
TitleRef string
|
||||||
Context types.Context
|
Context types.Context
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -11,7 +12,7 @@ var _ types.IController = &SwitchToDiffFilesController{}
|
|||||||
type CanSwitchToDiffFiles interface {
|
type CanSwitchToDiffFiles interface {
|
||||||
types.IListContext
|
types.IListContext
|
||||||
CanRebase() bool
|
CanRebase() bool
|
||||||
GetSelectedRef() types.Ref
|
GetSelectedRef() models.Ref
|
||||||
GetSelectedRefRangeForDiffFiles() *types.RefRange
|
GetSelectedRefRangeForDiffFiles() *types.RefRange
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
@ -9,7 +10,7 @@ var _ types.IController = &SwitchToSubCommitsController{}
|
|||||||
|
|
||||||
type CanSwitchToSubCommits interface {
|
type CanSwitchToSubCommits interface {
|
||||||
types.IListContext
|
types.IListContext
|
||||||
GetSelectedRef() types.Ref
|
GetSelectedRef() models.Ref
|
||||||
ShowBranchHeadsInSubCommits() bool
|
ShowBranchHeadsInSubCommits() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ type CanSwitchToSubCommits interface {
|
|||||||
// but an attribute on it i.e. the ref of an item.
|
// but an attribute on it i.e. the ref of an item.
|
||||||
type SwitchToSubCommitsController struct {
|
type SwitchToSubCommitsController struct {
|
||||||
baseController
|
baseController
|
||||||
*ListControllerTrait[types.Ref]
|
*ListControllerTrait[models.Ref]
|
||||||
c *ControllerCommon
|
c *ControllerCommon
|
||||||
context CanSwitchToSubCommits
|
context CanSwitchToSubCommits
|
||||||
}
|
}
|
||||||
@ -32,7 +33,7 @@ func NewSwitchToSubCommitsController(
|
|||||||
c,
|
c,
|
||||||
context,
|
context,
|
||||||
context.GetSelectedRef,
|
context.GetSelectedRef,
|
||||||
func() ([]types.Ref, int, int) {
|
func() ([]models.Ref, int, int) {
|
||||||
panic("Not implemented")
|
panic("Not implemented")
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -15,8 +15,8 @@ type ICommitFileTreeViewModel interface {
|
|||||||
ICommitFileTree
|
ICommitFileTree
|
||||||
types.IListCursor
|
types.IListCursor
|
||||||
|
|
||||||
GetRef() types.Ref
|
GetRef() models.Ref
|
||||||
SetRef(types.Ref)
|
SetRef(models.Ref)
|
||||||
GetRefRange() *types.RefRange // can be nil, in which case GetRef should be used
|
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
|
SetRefRange(*types.RefRange) // should be set to nil when selection is not a range
|
||||||
GetCanRebase() bool
|
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
|
// 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
|
// 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
|
// this is a commit range for which we're viewing the files. Can be nil, in
|
||||||
// which case ref is used.
|
// 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
|
return self.ref
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitFileTreeViewModel) SetRef(ref types.Ref) {
|
func (self *CommitFileTreeViewModel) SetRef(ref models.Ref) {
|
||||||
self.ref = 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