This commit is contained in:
Erik Brakkee 2025-01-07 09:29:13 +01:00
commit f52507aa8f

View File

@ -20,15 +20,19 @@ func subtract(yaml2 yaml.MapSlice, yaml1 yaml.MapSlice) yaml.MapSlice {
v2 := item.Value v2 := item.Value
v1 := yaml1.ToMap()[k] v1 := yaml1.ToMap()[k]
switch { switch {
case v2 != nil && v1 == nil:
res = append(res, item)
case reflect.DeepEqual(v1, v2): case reflect.DeepEqual(v1, v2):
// delete is implicit by not copying to the output // delete is implicit by not copying to the output
case Type(v1) == Map && Type(v2) == Map: case reflect.TypeOf(v1) == reflect.TypeOf(yaml.MapSlice{}) &&
reflect.TypeOf(v2) == reflect.TypeOf(yaml.MapSlice{}):
diff := subtract(v2.(yaml.MapSlice), v1.(yaml.MapSlice)) diff := subtract(v2.(yaml.MapSlice), v1.(yaml.MapSlice))
if len(diff) > 0 { if len(diff) > 0 {
res = append(res, item) mi := yaml.MapItem{Key: k, Value: diff}
res = append(res, mi)
} }
case Type(v1) == Slice && Type(v2) == Slice: case Type(v1) == Slice && Type(v2) == Slice:
// To be improved can be really confusing.
v2set := make(map[string]bool) v2set := make(map[string]bool)
v1set := make(map[string]bool) v1set := make(map[string]bool)
stringToValue := make(map[any]any) stringToValue := make(map[any]any)