From e52cec9cdf17ffb27fc3521f9abd977603d31753 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 21 Mar 2021 15:25:29 +1100 Subject: [PATCH] small refactor --- pkg/gui/{status_tree.go => filetree/build_tree.go} | 8 ++++---- pkg/gui/{ => filetree}/file_change_manager.go | 6 +++--- pkg/gui/{ => filetree}/file_change_manager_test.go | 2 +- pkg/gui/gui.go | 5 +++-- 4 files changed, 11 insertions(+), 10 deletions(-) rename pkg/gui/{status_tree.go => filetree/build_tree.go} (85%) rename pkg/gui/{ => filetree}/file_change_manager.go (97%) rename pkg/gui/{ => filetree}/file_change_manager_test.go (99%) diff --git a/pkg/gui/status_tree.go b/pkg/gui/filetree/build_tree.go similarity index 85% rename from pkg/gui/status_tree.go rename to pkg/gui/filetree/build_tree.go index 3e201b7d4..e8da844e0 100644 --- a/pkg/gui/status_tree.go +++ b/pkg/gui/filetree/build_tree.go @@ -1,4 +1,4 @@ -package gui +package filetree import ( "os" @@ -9,7 +9,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/models" ) -func GetTreeFromFiles(files []*models.File) *models.FileChangeNode { +func BuildTreeFromFiles(files []*models.File) *models.FileChangeNode { root := &models.FileChangeNode{} var curr *models.FileChangeNode @@ -49,8 +49,8 @@ func GetTreeFromFiles(files []*models.File) *models.FileChangeNode { return root } -func GetFlatTreeFromFiles(files []*models.File) *models.FileChangeNode { - rootAux := GetTreeFromFiles(files) +func BuildFlatTreeFromFiles(files []*models.File) *models.FileChangeNode { + rootAux := BuildTreeFromFiles(files) sortedFiles := rootAux.GetLeaves() // Move merge conflicts to top. This is the one way in which sorting diff --git a/pkg/gui/file_change_manager.go b/pkg/gui/filetree/file_change_manager.go similarity index 97% rename from pkg/gui/file_change_manager.go rename to pkg/gui/filetree/file_change_manager.go index 1af1fb748..925398827 100644 --- a/pkg/gui/file_change_manager.go +++ b/pkg/gui/filetree/file_change_manager.go @@ -1,4 +1,4 @@ -package gui +package filetree import ( "fmt" @@ -63,9 +63,9 @@ func (m *FileChangeManager) SetFiles(files []*models.File) { func (m *FileChangeManager) SetTree() { if m.ShowTree { - m.Tree = GetTreeFromFiles(m.Files) + m.Tree = BuildTreeFromFiles(m.Files) } else { - m.Tree = GetFlatTreeFromFiles(m.Files) + m.Tree = BuildFlatTreeFromFiles(m.Files) } } diff --git a/pkg/gui/file_change_manager_test.go b/pkg/gui/filetree/file_change_manager_test.go similarity index 99% rename from pkg/gui/file_change_manager_test.go rename to pkg/gui/filetree/file_change_manager_test.go index f339aae0f..8e8ba00cd 100644 --- a/pkg/gui/file_change_manager_test.go +++ b/pkg/gui/filetree/file_change_manager_test.go @@ -1,4 +1,4 @@ -package gui +package filetree import ( "testing" diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index b36ab14db..fbb2ab223 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -21,6 +21,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/patch" "github.com/jesseduffield/lazygit/pkg/config" + "github.com/jesseduffield/lazygit/pkg/gui/filetree" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/i18n" "github.com/jesseduffield/lazygit/pkg/tasks" @@ -303,7 +304,7 @@ type guiStateMutexes struct { } type guiState struct { - FileChangeManager *FileChangeManager + FileChangeManager *filetree.FileChangeManager Submodules []*models.SubmoduleConfig Branches []*models.Branch Commits []*models.Commit @@ -380,7 +381,7 @@ func (gui *Gui) resetState() { showTree := gui.Config.GetUserConfig().Gui.ShowFileTree gui.State = &guiState{ - FileChangeManager: NewFileChangeManager(make([]*models.File, 0), gui.Log, showTree), + FileChangeManager: filetree.NewFileChangeManager(make([]*models.File, 0), gui.Log, showTree), Commits: make([]*models.Commit, 0), FilteredReflogCommits: make([]*models.Commit, 0), ReflogCommits: make([]*models.Commit, 0),