1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Pass common.Common to file trees instead of just the Log

We will need a user config in the file tree in the next commit, and passing the
entire common is the easiest way to do that while ensuring hot-reloading when
users change the config while lazygit is running.
This commit is contained in:
Stefan Haller
2025-05-24 15:18:05 +02:00
parent da32b59e11
commit ffb8586795
7 changed files with 21 additions and 18 deletions

View File

@ -29,7 +29,7 @@ var (
func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext { func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext {
viewModel := filetree.NewCommitFileTreeViewModel( viewModel := filetree.NewCommitFileTreeViewModel(
func() []*models.CommitFile { return c.Model().CommitFiles }, func() []*models.CommitFile { return c.Model().CommitFiles },
c.Log, c.Common,
c.UserConfig().Gui.ShowFileTree, c.UserConfig().Gui.ShowFileTree,
) )

View File

@ -24,7 +24,7 @@ var (
func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext { func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
viewModel := filetree.NewFileTreeViewModel( viewModel := filetree.NewFileTreeViewModel(
func() []*models.File { return c.Model().Files }, func() []*models.File { return c.Model().Files },
c.Log, c.Common,
c.UserConfig().Gui.ShowFileTree, c.UserConfig().Gui.ShowFileTree,
) )

View File

@ -2,9 +2,9 @@ package filetree
import ( import (
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/sirupsen/logrus"
) )
type ICommitFileTree interface { type ICommitFileTree interface {
@ -21,7 +21,7 @@ type CommitFileTree struct {
getFiles func() []*models.CommitFile getFiles func() []*models.CommitFile
tree *Node[models.CommitFile] tree *Node[models.CommitFile]
showTree bool showTree bool
log *logrus.Entry common *common.Common
collapsedPaths *CollapsedPaths collapsedPaths *CollapsedPaths
} }
@ -41,10 +41,10 @@ func (self *CommitFileTree) ExpandAll() {
var _ ICommitFileTree = &CommitFileTree{} var _ ICommitFileTree = &CommitFileTree{}
func NewCommitFileTree(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTree { func NewCommitFileTree(getFiles func() []*models.CommitFile, common *common.Common, showTree bool) *CommitFileTree {
return &CommitFileTree{ return &CommitFileTree{
getFiles: getFiles, getFiles: getFiles,
log: log, common: common,
showTree: showTree, showTree: showTree,
collapsedPaths: NewCollapsedPaths(), collapsedPaths: NewCollapsedPaths(),
} }

View File

@ -5,10 +5,10 @@ import (
"sync" "sync"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/context/traits" "github.com/jesseduffield/lazygit/pkg/gui/context/traits"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/sirupsen/logrus"
) )
type ICommitFileTreeViewModel interface { type ICommitFileTreeViewModel interface {
@ -43,8 +43,8 @@ type CommitFileTreeViewModel struct {
var _ ICommitFileTreeViewModel = &CommitFileTreeViewModel{} var _ ICommitFileTreeViewModel = &CommitFileTreeViewModel{}
func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTreeViewModel { func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, common *common.Common, showTree bool) *CommitFileTreeViewModel {
fileTree := NewCommitFileTree(getFiles, log, showTree) fileTree := NewCommitFileTree(getFiles, common, showTree)
listCursor := traits.NewListCursor(fileTree.Len) listCursor := traits.NewListCursor(fileTree.Len)
return &CommitFileTreeViewModel{ return &CommitFileTreeViewModel{
ICommitFileTree: fileTree, ICommitFileTree: fileTree,

View File

@ -4,9 +4,9 @@ import (
"fmt" "fmt"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/sirupsen/logrus"
) )
type FileTreeDisplayFilter int type FileTreeDisplayFilter int
@ -54,17 +54,17 @@ type FileTree struct {
getFiles func() []*models.File getFiles func() []*models.File
tree *Node[models.File] tree *Node[models.File]
showTree bool showTree bool
log *logrus.Entry common *common.Common
filter FileTreeDisplayFilter filter FileTreeDisplayFilter
collapsedPaths *CollapsedPaths collapsedPaths *CollapsedPaths
} }
var _ IFileTree = &FileTree{} var _ IFileTree = &FileTree{}
func NewFileTree(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTree { func NewFileTree(getFiles func() []*models.File, common *common.Common, showTree bool) *FileTree {
return &FileTree{ return &FileTree{
getFiles: getFiles, getFiles: getFiles,
log: log, common: common,
showTree: showTree, showTree: showTree,
filter: DisplayAll, filter: DisplayAll,
collapsedPaths: NewCollapsedPaths(), collapsedPaths: NewCollapsedPaths(),

View File

@ -5,11 +5,11 @@ import (
"sync" "sync"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/context/traits" "github.com/jesseduffield/lazygit/pkg/gui/context/traits"
"github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
"github.com/samber/lo" "github.com/samber/lo"
"github.com/sirupsen/logrus"
) )
type IFileTreeViewModel interface { type IFileTreeViewModel interface {
@ -28,8 +28,8 @@ type FileTreeViewModel struct {
var _ IFileTreeViewModel = &FileTreeViewModel{} var _ IFileTreeViewModel = &FileTreeViewModel{}
func NewFileTreeViewModel(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTreeViewModel { func NewFileTreeViewModel(getFiles func() []*models.File, common *common.Common, showTree bool) *FileTreeViewModel {
fileTree := NewFileTree(getFiles, log, showTree) fileTree := NewFileTree(getFiles, common, showTree)
listCursor := traits.NewListCursor(fileTree.Len) listCursor := traits.NewListCursor(fileTree.Len)
return &FileTreeViewModel{ return &FileTreeViewModel{
IFileTree: fileTree, IFileTree: fileTree,

View File

@ -7,6 +7,7 @@ import (
"github.com/gookit/color" "github.com/gookit/color"
"github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/commands/patch"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/config" "github.com/jesseduffield/lazygit/pkg/config"
"github.com/jesseduffield/lazygit/pkg/gui/filetree" "github.com/jesseduffield/lazygit/pkg/gui/filetree"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
@ -87,7 +88,8 @@ func TestRenderFileTree(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
t.Run(s.name, func(t *testing.T) { t.Run(s.name, func(t *testing.T) {
viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, utils.NewDummyLog(), true) common := common.NewDummyCommon()
viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, common, true)
viewModel.SetTree() viewModel.SetTree()
for _, path := range s.collapsedPaths { for _, path := range s.collapsedPaths {
viewModel.ToggleCollapsed(path) viewModel.ToggleCollapsed(path)
@ -151,7 +153,8 @@ func TestRenderCommitFileTree(t *testing.T) {
t.Run(s.name, func(t *testing.T) { t.Run(s.name, func(t *testing.T) {
hashPool := &utils.StringPool{} hashPool := &utils.StringPool{}
viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, utils.NewDummyLog(), true) common := common.NewDummyCommon()
viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, common, true)
viewModel.SetRef(models.NewCommit(hashPool, models.NewCommitOpts{Hash: "1234"})) viewModel.SetRef(models.NewCommit(hashPool, models.NewCommitOpts{Hash: "1234"}))
viewModel.SetTree() viewModel.SetTree()
for _, path := range s.collapsedPaths { for _, path := range s.collapsedPaths {