MCPcopy
hub / github.com/databus23/helm-diff / contentSearch

Function contentSearch

diff/diff.go:193–255  ·  view source on GitHub ↗
(report *Report, possiblyRemoved []string, oldIndex map[string]*manifest.MappingResult, possiblyAdded []string, newIndex map[string]*manifest.MappingResult, options *Options)

Source from the content-addressed store, hash-verified

191)
192
193func contentSearch(report *Report, possiblyRemoved []string, oldIndex map[string]*manifest.MappingResult, possiblyAdded []string, newIndex map[string]*manifest.MappingResult, options *Options) ([]string, []string) {
194 if options.FindRenames <= 0 {
195 return possiblyRemoved, possiblyAdded
196 }
197
198 var removed []string
199
200 for _, removedKey := range possiblyRemoved {
201 oldContent := oldIndex[removedKey]
202 var smallestKey string
203 var smallestFraction float32 = math.MaxFloat32
204 for _, addedKey := range possiblyAdded {
205 newContent := newIndex[addedKey]
206 if oldContent.Kind != newContent.Kind {
207 continue
208 }
209
210 oldLen := len(oldContent.Content)
211 newLen := len(newContent.Content)
212 if oldLen == 0 || newLen == 0 {
213 continue
214 }
215 // Skip the length-ratio filter for Secrets: their raw content length can
216 // differ greatly from the post-processed (redacted/decoded) length, so the
217 // ratio would be an unreliable predictor of content similarity.
218 if oldContent.Kind != kindSecret {
219 ratio := float32(oldLen) / float32(newLen)
220 if ratio < renameDetectionMinLengthRatio || ratio > renameDetectionMaxLengthRatio {
221 continue
222 }
223 }
224
225 switch {
226 case options.ShowSecretsDecoded:
227 decodeSecrets(oldContent, newContent)
228 case !options.ShowSecrets:
229 redactSecrets(oldContent, newContent)
230 }
231
232 diff := diffMappingResults(oldContent, newContent, options.StripTrailingCR)
233 delta := actualChanges(diff)
234 if delta == 0 || len(diff) == 0 {
235 continue
236 }
237 fraction := float32(delta) / float32(len(diff))
238 if fraction > 0 && fraction < smallestFraction {
239 smallestKey = addedKey
240 smallestFraction = fraction
241 }
242 }
243
244 if smallestFraction < options.FindRenames {
245 index := sort.SearchStrings(possiblyAdded, smallestKey)
246 possiblyAdded = append(possiblyAdded[:index], possiblyAdded[index+1:]...)
247 newContent := newIndex[smallestKey]
248 doDiff(report, removedKey, oldContent, newContent, options)
249 } else {
250 removed = append(removed, removedKey)

Callers 1

generateReportFunction · 0.85

Calls 5

decodeSecretsFunction · 0.85
redactSecretsFunction · 0.85
diffMappingResultsFunction · 0.85
actualChangesFunction · 0.85
doDiffFunction · 0.85

Tested by

no test coverage detected