@@ -22,58 +22,67 @@ import (
22
22
func Manifests (oldIndex , newIndex map [string ]* manifest.MappingResult , suppressedKinds []string , showSecrets bool , context int , output string , stripTrailingCR bool , to io.Writer ) bool {
23
23
report := Report {}
24
24
report .setupReportFormat (output )
25
- seenAnyChanges := false
26
- emptyMapping := & manifest.MappingResult {}
27
25
for _ , key := range sortedKeys (oldIndex ) {
28
26
oldContent := oldIndex [key ]
29
27
30
28
if newContent , ok := newIndex [key ]; ok {
31
- if oldContent .Content != newContent .Content {
32
- // modified
33
- if ! showSecrets {
34
- redactSecrets (oldContent , newContent )
35
- }
36
-
37
- diffs := diffMappingResults (oldContent , newContent , stripTrailingCR )
38
- if len (diffs ) > 0 {
39
- seenAnyChanges = true
40
- }
41
- report .addEntry (key , suppressedKinds , oldContent .Kind , context , diffs , "MODIFY" )
42
- }
29
+ // modified?
30
+ doDiff (key , oldContent , newContent , suppressedKinds , showSecrets , stripTrailingCR , context )
43
31
} else {
44
32
// removed
45
- if ! showSecrets {
46
- redactSecrets (oldContent , nil )
47
-
48
- }
49
- diffs := diffMappingResults (oldContent , emptyMapping , stripTrailingCR )
50
- if len (diffs ) > 0 {
51
- seenAnyChanges = true
52
- }
53
- report .addEntry (key , suppressedKinds , oldContent .Kind , context , diffs , "REMOVE" )
33
+ doDiff (key , oldContent , nil , suppressedKinds , showSecrets , stripTrailingCR , context )
54
34
}
55
35
}
56
36
57
37
for _ , key := range sortedKeys (newIndex ) {
58
38
newContent := newIndex [key ]
59
39
60
40
if _ , ok := oldIndex [key ]; ! ok {
61
- // added
62
- if ! showSecrets {
63
- redactSecrets (nil , newContent )
64
- }
65
- diffs := diffMappingResults (emptyMapping , newContent , stripTrailingCR )
66
- if len (diffs ) > 0 {
67
- seenAnyChanges = true
68
- }
69
- report .addEntry (key , suppressedKinds , newContent .Kind , context , diffs , "ADD" )
41
+ doDiff (key , nil , newContent , suppressedKinds , showSecrets , stripTrailingCR , context )
70
42
}
71
43
}
44
+
45
+ seenAnyChanges := len (report .entries ) > 0
72
46
report .print (to )
73
47
report .clean ()
74
48
return seenAnyChanges
75
49
}
76
50
51
+ func actualChanges (diff []difflib.DiffRecord ) int {
52
+ changes := 0
53
+ for _ , record := range diff {
54
+ if record .Delta != difflib .Common {
55
+ changes ++
56
+ }
57
+ }
58
+ return changes
59
+ }
60
+
61
+ func doDiff (key string , oldContent * manifest.MappingResult , newContent * manifest.MappingResult , suppressedKinds []string , showSecrets bool , stripTrailingCR bool , context int ) {
62
+ if oldContent != nil && newContent != nil && oldContent .Content == newContent .Content {
63
+ return
64
+ }
65
+
66
+ if ! showSecrets {
67
+ redactSecrets (oldContent , newContent )
68
+ }
69
+
70
+ if oldContent == nil {
71
+ emptyMapping := & manifest.MappingResult {}
72
+ diffs := diffMappingResults (emptyMapping , newContent , stripTrailingCR )
73
+ report .addEntry (key , suppressedKinds , newContent .Kind , context , diffs , "ADD" )
74
+ } else if newContent == nil {
75
+ emptyMapping := & manifest.MappingResult {}
76
+ diffs := diffMappingResults (oldContent , emptyMapping , stripTrailingCR )
77
+ report .addEntry (key , suppressedKinds , oldContent .Kind , context , diffs , "REMOVE" )
78
+ } else {
79
+ diffs := diffMappingResults (oldContent , newContent , stripTrailingCR )
80
+ if actualChanges (diffs ) > 0 {
81
+ report .addEntry (key , suppressedKinds , oldContent .Kind , context , diffs , "MODIFY" )
82
+ }
83
+ }
84
+ }
85
+
77
86
func redactSecrets (old , new * manifest.MappingResult ) {
78
87
if (old != nil && old .Kind != "Secret" ) || (new != nil && new .Kind != "Secret" ) {
79
88
return
0 commit comments