Skip to content

Commit ffb8586

Browse files
committed
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.
1 parent da32b59 commit ffb8586

File tree

7 files changed

+21
-18
lines changed

7 files changed

+21
-18
lines changed

pkg/gui/context/commit_files_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var (
2929
func NewCommitFilesContext(c *ContextCommon) *CommitFilesContext {
3030
viewModel := filetree.NewCommitFileTreeViewModel(
3131
func() []*models.CommitFile { return c.Model().CommitFiles },
32-
c.Log,
32+
c.Common,
3333
c.UserConfig().Gui.ShowFileTree,
3434
)
3535

pkg/gui/context/working_tree_context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
func NewWorkingTreeContext(c *ContextCommon) *WorkingTreeContext {
2525
viewModel := filetree.NewFileTreeViewModel(
2626
func() []*models.File { return c.Model().Files },
27-
c.Log,
27+
c.Common,
2828
c.UserConfig().Gui.ShowFileTree,
2929
)
3030

pkg/gui/filetree/commit_file_tree.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package filetree
22

33
import (
44
"github.com/jesseduffield/lazygit/pkg/commands/models"
5+
"github.com/jesseduffield/lazygit/pkg/common"
56
"github.com/jesseduffield/lazygit/pkg/gui/types"
67
"github.com/samber/lo"
7-
"github.com/sirupsen/logrus"
88
)
99

1010
type ICommitFileTree interface {
@@ -21,7 +21,7 @@ type CommitFileTree struct {
2121
getFiles func() []*models.CommitFile
2222
tree *Node[models.CommitFile]
2323
showTree bool
24-
log *logrus.Entry
24+
common *common.Common
2525
collapsedPaths *CollapsedPaths
2626
}
2727

@@ -41,10 +41,10 @@ func (self *CommitFileTree) ExpandAll() {
4141

4242
var _ ICommitFileTree = &CommitFileTree{}
4343

44-
func NewCommitFileTree(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTree {
44+
func NewCommitFileTree(getFiles func() []*models.CommitFile, common *common.Common, showTree bool) *CommitFileTree {
4545
return &CommitFileTree{
4646
getFiles: getFiles,
47-
log: log,
47+
common: common,
4848
showTree: showTree,
4949
collapsedPaths: NewCollapsedPaths(),
5050
}

pkg/gui/filetree/commit_file_tree_view_model.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"sync"
66

77
"github.com/jesseduffield/lazygit/pkg/commands/models"
8+
"github.com/jesseduffield/lazygit/pkg/common"
89
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
910
"github.com/jesseduffield/lazygit/pkg/gui/types"
1011
"github.com/samber/lo"
11-
"github.com/sirupsen/logrus"
1212
)
1313

1414
type ICommitFileTreeViewModel interface {
@@ -43,8 +43,8 @@ type CommitFileTreeViewModel struct {
4343

4444
var _ ICommitFileTreeViewModel = &CommitFileTreeViewModel{}
4545

46-
func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileTreeViewModel {
47-
fileTree := NewCommitFileTree(getFiles, log, showTree)
46+
func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, common *common.Common, showTree bool) *CommitFileTreeViewModel {
47+
fileTree := NewCommitFileTree(getFiles, common, showTree)
4848
listCursor := traits.NewListCursor(fileTree.Len)
4949
return &CommitFileTreeViewModel{
5050
ICommitFileTree: fileTree,

pkg/gui/filetree/file_tree.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"fmt"
55

66
"github.com/jesseduffield/lazygit/pkg/commands/models"
7+
"github.com/jesseduffield/lazygit/pkg/common"
78
"github.com/jesseduffield/lazygit/pkg/gui/types"
89
"github.com/samber/lo"
9-
"github.com/sirupsen/logrus"
1010
)
1111

1212
type FileTreeDisplayFilter int
@@ -54,17 +54,17 @@ type FileTree struct {
5454
getFiles func() []*models.File
5555
tree *Node[models.File]
5656
showTree bool
57-
log *logrus.Entry
57+
common *common.Common
5858
filter FileTreeDisplayFilter
5959
collapsedPaths *CollapsedPaths
6060
}
6161

6262
var _ IFileTree = &FileTree{}
6363

64-
func NewFileTree(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTree {
64+
func NewFileTree(getFiles func() []*models.File, common *common.Common, showTree bool) *FileTree {
6565
return &FileTree{
6666
getFiles: getFiles,
67-
log: log,
67+
common: common,
6868
showTree: showTree,
6969
filter: DisplayAll,
7070
collapsedPaths: NewCollapsedPaths(),

pkg/gui/filetree/file_tree_view_model.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"sync"
66

77
"github.com/jesseduffield/lazygit/pkg/commands/models"
8+
"github.com/jesseduffield/lazygit/pkg/common"
89
"github.com/jesseduffield/lazygit/pkg/gui/context/traits"
910
"github.com/jesseduffield/lazygit/pkg/gui/types"
1011
"github.com/jesseduffield/lazygit/pkg/utils"
1112
"github.com/samber/lo"
12-
"github.com/sirupsen/logrus"
1313
)
1414

1515
type IFileTreeViewModel interface {
@@ -28,8 +28,8 @@ type FileTreeViewModel struct {
2828

2929
var _ IFileTreeViewModel = &FileTreeViewModel{}
3030

31-
func NewFileTreeViewModel(getFiles func() []*models.File, log *logrus.Entry, showTree bool) *FileTreeViewModel {
32-
fileTree := NewFileTree(getFiles, log, showTree)
31+
func NewFileTreeViewModel(getFiles func() []*models.File, common *common.Common, showTree bool) *FileTreeViewModel {
32+
fileTree := NewFileTree(getFiles, common, showTree)
3333
listCursor := traits.NewListCursor(fileTree.Len)
3434
return &FileTreeViewModel{
3535
IFileTree: fileTree,

pkg/gui/presentation/files_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/gookit/color"
88
"github.com/jesseduffield/lazygit/pkg/commands/models"
99
"github.com/jesseduffield/lazygit/pkg/commands/patch"
10+
"github.com/jesseduffield/lazygit/pkg/common"
1011
"github.com/jesseduffield/lazygit/pkg/config"
1112
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
1213
"github.com/jesseduffield/lazygit/pkg/utils"
@@ -87,7 +88,8 @@ func TestRenderFileTree(t *testing.T) {
8788

8889
for _, s := range scenarios {
8990
t.Run(s.name, func(t *testing.T) {
90-
viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, utils.NewDummyLog(), true)
91+
common := common.NewDummyCommon()
92+
viewModel := filetree.NewFileTree(func() []*models.File { return s.files }, common, true)
9193
viewModel.SetTree()
9294
for _, path := range s.collapsedPaths {
9395
viewModel.ToggleCollapsed(path)
@@ -151,7 +153,8 @@ func TestRenderCommitFileTree(t *testing.T) {
151153
t.Run(s.name, func(t *testing.T) {
152154
hashPool := &utils.StringPool{}
153155

154-
viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, utils.NewDummyLog(), true)
156+
common := common.NewDummyCommon()
157+
viewModel := filetree.NewCommitFileTreeViewModel(func() []*models.CommitFile { return s.files }, common, true)
155158
viewModel.SetRef(models.NewCommit(hashPool, models.NewCommitOpts{Hash: "1234"}))
156159
viewModel.SetTree()
157160
for _, path := range s.collapsedPaths {

0 commit comments

Comments
 (0)