diff --git a/go.mod b/go.mod index de082e990..e2348a3c8 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/cppforlife/cobrautil v0.0.0-20221130162803-acdfead391ef github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835 github.com/cppforlife/go-cli-ui v0.0.0-20220425131040-94f26b16bc14 - github.com/cppforlife/go-patch v0.0.0-20240118020416-2147782e467b + github.com/cppforlife/go-patch v0.2.0 github.com/google/go-cmp v0.6.0 github.com/hashicorp/go-version v1.6.0 github.com/k14s/difflib v0.0.0-20240118055029-596a7a5585c3 diff --git a/go.sum b/go.sum index 2c1972cdf..b4f220163 100644 --- a/go.sum +++ b/go.sum @@ -42,8 +42,8 @@ github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835/go.mod h1:dYeVs github.com/cppforlife/go-cli-ui v0.0.0-20200505234325-512793797f05/go.mod h1:I0qrzCmuPWYI6kAOvkllYjaW2aovclWbJ96+v+YyHb0= github.com/cppforlife/go-cli-ui v0.0.0-20220425131040-94f26b16bc14 h1:MjRdR01xh0sfkeS3OOBv+MYkYsrbHuTDc4rfBnVdFaI= github.com/cppforlife/go-cli-ui v0.0.0-20220425131040-94f26b16bc14/go.mod h1:AlgTssDlstr4mf92TR4DPITLfl5+7wEY4cKStCmeeto= -github.com/cppforlife/go-patch v0.0.0-20240118020416-2147782e467b h1:+8LQctLhaj+63L/37l8IK/5Q3odN6RzWlglonUwrKok= -github.com/cppforlife/go-patch v0.0.0-20240118020416-2147782e467b/go.mod h1:67a7aIi94FHDZdoeGSJRRFDp66l9MhaAG1yGxpUoFD8= +github.com/cppforlife/go-patch v0.2.0 h1:Y14MnCQjDlbw7WXT4k+u6DPAA9XnygN4BfrSpI/19RU= +github.com/cppforlife/go-patch v0.2.0/go.mod h1:67a7aIi94FHDZdoeGSJRRFDp66l9MhaAG1yGxpUoFD8= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= diff --git a/vendor/github.com/cppforlife/go-patch/patch/diff.go b/vendor/github.com/cppforlife/go-patch/patch/diff.go index 3526b574c..bedb01a42 100644 --- a/vendor/github.com/cppforlife/go-patch/patch/diff.go +++ b/vendor/github.com/cppforlife/go-patch/patch/diff.go @@ -31,50 +31,6 @@ func (d Diff) Calculate() Ops { func (d Diff) calculate(left, right interface{}, tokens []Token) []Op { switch typedLeft := left.(type) { - case map[string]interface{}: - if typedRight, ok := right.(map[string]interface{}); ok { - ops := []Op{} - var allKeys []string - for k := range typedLeft { - allKeys = append(allKeys, k) - } - for k := range typedRight { - if _, found := typedLeft[k]; !found { - allKeys = append(allKeys, k) - } - } - sort.SliceStable(allKeys, func(i, j int) bool { - return allKeys[i] < allKeys[j] - }) - for _, k := range allKeys { - newTokens := append([]Token{}, tokens...) - if leftVal, found := typedLeft[k]; found { - newTokens = append(newTokens, KeyToken{Key: k}) - if rightVal, found := typedRight[k]; found { - ops = append(ops, d.calculate(leftVal, rightVal, newTokens)...) - } else { // remove existing - ops = append(ops, - TestOp{Path: NewPointer(newTokens), Value: leftVal}, - RemoveOp{Path: NewPointer(newTokens)}, - ) - } - } else { // add new - testOpTokens := append([]Token{}, newTokens...) - testOpTokens = append(testOpTokens, KeyToken{Key: k}) - newTokens = append(newTokens, KeyToken{Key: k, Optional: true}) - ops = append(ops, - TestOp{Path: NewPointer(testOpTokens), Absent: true}, - ReplaceOp{Path: NewPointer(newTokens), Value: typedRight[k]}, - ) - } - } - return ops - } - return []Op{ - TestOp{Path: NewPointer(tokens), Value: left}, - ReplaceOp{Path: NewPointer(tokens), Value: right}, - } - case map[interface{}]interface{}: if typedRight, ok := right.(map[interface{}]interface{}); ok { ops := []Op{} @@ -158,7 +114,7 @@ func (d Diff) calculate(left, right interface{}, tokens []Token) []Op { } default: - if !reflect.DeepEqual(jsonToYAMLValue(left), jsonToYAMLValue(right)) { + if !reflect.DeepEqual(left, right) { return []Op{ TestOp{Path: NewPointer(tokens), Value: left}, ReplaceOp{Path: NewPointer(tokens), Value: right}, @@ -169,32 +125,6 @@ func (d Diff) calculate(left, right interface{}, tokens []Token) []Op { return []Op{} } -// The Go JSON library doesn't try to pick the right number type (int, float, -// etc.) when unmarshalling to interface{}, it just picks float64 -// universally -func jsonToYAMLValue(j interface{}) interface{} { - switch j := j.(type) { - case float64: - // replicate the logic in https://github.com/go-yaml/yaml/blob/51d6538a90f86fe93ac480b35f37b2be17fef232/resolve.go#L151 - if i64 := int64(j); j == float64(i64) { - if i := int(i64); i64 == int64(i) { - return i - } - return i64 - } - if ui64 := uint64(j); j == float64(ui64) { - return ui64 - } - return j - case int64: - if i := int(j); j == int64(i) { - return i - } - return j - } - return j -} - func max(a, b int) int { if a > b { return a diff --git a/vendor/modules.txt b/vendor/modules.txt index a39e9d251..c184f7d9b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,7 +10,7 @@ github.com/cppforlife/go-cli-ui/errors github.com/cppforlife/go-cli-ui/ui github.com/cppforlife/go-cli-ui/ui/table github.com/cppforlife/go-cli-ui/ui/test -# github.com/cppforlife/go-patch v0.0.0-20240118020416-2147782e467b +# github.com/cppforlife/go-patch v0.2.0 ## explicit github.com/cppforlife/go-patch/patch # github.com/davecgh/go-spew v1.1.1