MCPcopy Index your code
hub / github.com/jesseduffield/lazygit / BuildTreeFromCommitFiles

Function BuildTreeFromCommitFiles

pkg/gui/filetree/build_tree.go:81–128  ·  view source on GitHub ↗
(
	files []*models.CommitFile,
	showRootItem bool,
	cmp func(a, b *Node[models.CommitFile]) int,
)

Source from the content-addressed store, hash-verified

79}
80
81func BuildTreeFromCommitFiles(
82 files []*models.CommitFile,
83 showRootItem bool,
84 cmp func(a, b *Node[models.CommitFile]) int,
85) *Node[models.CommitFile] {
86 root := &Node[models.CommitFile]{}
87
88 var curr *Node[models.CommitFile]
89 for _, file := range files {
90 splitPath := SplitFileTreePath(file.Path, showRootItem)
91 curr = root
92 outer:
93 for i := range splitPath {
94 var setFile *models.CommitFile
95 isFile := i == len(splitPath)-1
96 if isFile {
97 setFile = file
98 }
99
100 path := join(splitPath[:i+1])
101
102 for _, existingChild := range curr.Children {
103 if existingChild.path == path {
104 curr = existingChild
105 continue outer
106 }
107 }
108
109 if i == 0 && len(files) == 1 && len(splitPath) == 2 {
110 // skip the root item when there's only one file at top level; we don't need it in that case
111 continue outer
112 }
113
114 newChild := &Node[models.CommitFile]{
115 path: path,
116 File: setFile,
117 }
118 curr.Children = append(curr.Children, newChild)
119
120 curr = newChild
121 }
122 }
123
124 root.Sort(cmp)
125 root.Compress()
126
127 return root
128}
129
130func BuildFlatTreeFromFiles(
131 files []*models.File,

Callers 3

SetTreeMethod · 0.85

Calls 4

SplitFileTreePathFunction · 0.85
SortMethod · 0.80
CompressMethod · 0.80
joinFunction · 0.70

Tested by 1