MCPcopy Create free account
hub / github.com/cogentcore/core / diffDirsAt

Method diffDirsAt

texteditor/diffbrowser/node.go:118–183  ·  view source on GitHub ↗

diffDirsAt creates a tree of files with the same names that differ within two dirs.

(pathA, pathB string, node *Node, excludeFile func(fname string) bool)

Source from the content-addressed store, hash-verified

116// diffDirsAt creates a tree of files with the same names
117// that differ within two dirs.
118func (br *Browser) diffDirsAt(pathA, pathB string, node *Node, excludeFile func(fname string) bool) {
119 da := fsx.Dirs(pathA)
120 db := fsx.Dirs(pathB)
121
122 node.SetFileA(pathA).SetFileB(pathB)
123
124 for _, pa := range da {
125 if excludeFile != nil && excludeFile(pa) {
126 continue
127 }
128 for _, pb := range db {
129 if pa == pb {
130 nn := NewNode(node)
131 nn.SetText(pa)
132 br.diffDirsAt(filepath.Join(pathA, pa), filepath.Join(pathB, pb), nn, excludeFile)
133 }
134 }
135 }
136
137 fsa := fsx.Filenames(pathA)
138 fsb := fsx.Filenames(pathB)
139
140 for _, fa := range fsa {
141 isDir := false
142 for _, pa := range da {
143 if fa == pa {
144 isDir = true
145 break
146 }
147 }
148 if isDir {
149 continue
150 }
151 if excludeFile != nil && excludeFile(fa) {
152 continue
153 }
154 for _, fb := range fsb {
155 if fa != fb {
156 continue
157 }
158 pfa := filepath.Join(pathA, fa)
159 pfb := filepath.Join(pathB, fb)
160
161 ca, err := os.ReadFile(pfa)
162 if err != nil {
163 slog.Error(err.Error())
164 continue
165 }
166 cb, err := os.ReadFile(pfb)
167 if err != nil {
168 slog.Error(err.Error())
169 continue
170 }
171 sa := string(ca)
172 sb := string(cb)
173 if sa == sb {
174 continue
175 }

Callers 1

DiffDirsMethod · 0.95

Calls 11

SetFileAMethod · 0.95
DirsFunction · 0.92
FilenamesFunction · 0.92
ReadFileMethod · 0.80
SetTextBMethod · 0.80
SetTextAMethod · 0.80
InitFileMethod · 0.80
NewNodeFunction · 0.70
ErrorMethod · 0.65
SetFileBMethod · 0.45
SetTextMethod · 0.45

Tested by

no test coverage detected