summaryrefslogtreecommitdiffstats
path: root/pkg/gui/status_tree.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2020-11-15 10:45:55 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-03-30 21:57:00 +1100
commit45939171ea6537562270975348fe2919c9c60b95 (patch)
treeb9c4138c32b54577a3d6f17acdc0f4132c2ebc9e /pkg/gui/status_tree.go
parent049849264e561d2867d0d94940b1f66dcac77e6b (diff)
WIP
start moving to new interface WIP WIP WIP WIP WIP
Diffstat (limited to 'pkg/gui/status_tree.go')
-rw-r--r--pkg/gui/status_tree.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/gui/status_tree.go b/pkg/gui/status_tree.go
new file mode 100644
index 000000000..758f308a7
--- /dev/null
+++ b/pkg/gui/status_tree.go
@@ -0,0 +1,47 @@
+package gui
+
+import (
+ "os"
+ "sort"
+ "strings"
+
+ "github.com/jesseduffield/lazygit/pkg/commands/models"
+)
+
+func GetTreeFromStatusFiles(files []*models.File) *models.StatusLineNode {
+ root := &models.StatusLineNode{}
+
+ sort.SliceStable(files, func(i, j int) bool {
+ return files[i].Name < files[j].Name
+ })
+
+ var curr *models.StatusLineNode
+ for _, file := range files {
+ split := strings.Split(file.Name, string(os.PathSeparator))
+ curr = root
+ outer:
+ for i, dir := range split {
+ var setFile *models.File
+ if i == len(split)-1 {
+ setFile = file
+ }
+ for _, existingChild := range curr.Children {
+ if existingChild.Name == dir {
+ curr = existingChild
+ continue outer
+ }
+ }
+ newChild := &models.StatusLineNode{
+ Name: dir,
+ File: setFile,
+ }
+ curr.Children = append(curr.Children, newChild)
+
+ curr = newChild
+ }
+ }
+
+ root.SortTree()
+
+ return root
+}