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

Function doDiff

diff/diff.go:257–316  ·  view source on GitHub ↗
(report *Report, key string, oldContent *manifest.MappingResult, newContent *manifest.MappingResult, options *Options)

Source from the content-addressed store, hash-verified

255}
256
257func doDiff(report *Report, key string, oldContent *manifest.MappingResult, newContent *manifest.MappingResult, options *Options) {
258 if oldContent != nil && newContent != nil && oldContent.Content == newContent.Content {
259 return
260 }
261 switch {
262 case options.ShowSecretsDecoded:
263 decodeSecrets(oldContent, newContent)
264 case !options.ShowSecrets:
265 redactSecrets(oldContent, newContent)
266 }
267
268 var changeType string
269 var subjectKind string
270 var diffs []difflib.DiffRecord
271 switch {
272 case oldContent == nil:
273 changeType = "ADD"
274 if newContent != nil {
275 subjectKind = newContent.Kind
276 }
277 if !options.StructuredOutput() && newContent != nil {
278 emptyMapping := &manifest.MappingResult{}
279 diffs = diffMappingResults(emptyMapping, newContent, options.StripTrailingCR)
280 }
281 case newContent == nil:
282 changeType = "REMOVE"
283 subjectKind = oldContent.Kind
284 if !options.StructuredOutput() {
285 emptyMapping := &manifest.MappingResult{}
286 diffs = diffMappingResults(oldContent, emptyMapping, options.StripTrailingCR)
287 }
288 default:
289 changeType = "MODIFY"
290 subjectKind = oldContent.Kind
291 if !options.StructuredOutput() {
292 diffs = diffMappingResults(oldContent, newContent, options.StripTrailingCR)
293 if actualChanges(diffs) == 0 {
294 return
295 }
296 }
297 }
298
299 var structured *StructuredEntry
300 if options.StructuredOutput() {
301 entry, err := buildStructuredEntry(key, changeType, subjectKind, options.SuppressedKinds, oldContent, newContent)
302 if err != nil {
303 // Log warning and omit field-level changes for this entry
304 // printStructuredReport() will still output a basic entry with name and changeType
305 fmt.Fprintf(os.Stderr, "Warning: failed to build structured entry for %s (kind: %s, changeType: %s): %v\n",
306 key, subjectKind, changeType, err)
307 } else {
308 if changeType == "MODIFY" && !entry.ChangesSuppressed && len(entry.Changes) == 0 {
309 return
310 }
311 structured = entry
312 }
313 }
314

Callers 2

generateReportFunction · 0.85
contentSearchFunction · 0.85

Calls 7

decodeSecretsFunction · 0.85
redactSecretsFunction · 0.85
diffMappingResultsFunction · 0.85
actualChangesFunction · 0.85
buildStructuredEntryFunction · 0.85
StructuredOutputMethod · 0.80
addEntryMethod · 0.80

Tested by

no test coverage detected