Skip to content

Commit 852bf4a

Browse files
committed
Added support for reserved "patch" property
1 parent fadcdcb commit 852bf4a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

keyvalue.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"strings"
66
)
77

8+
const reservedKeyPatch = "patch"
9+
810
// A KeyValue object, that may hold multiple Values
911
type KeyValue struct {
1012
key string
@@ -128,7 +130,13 @@ func (node *KeyValue) Parent() *KeyValue {
128130
func (node *KeyValue) MergeInto(parent *KeyValue) (merged KeyValue, err error) {
129131
merged = *parent
130132
if node.Key() != merged.Key() {
131-
return merged,errors.New("cannot merge mismatched root nodes")
133+
// "patch" is a special key that can appear at the root of a keyvalue
134+
// it does what it sounds like, its ony real purpose is to patch another tree
135+
// with its own values
136+
if node.Key() != reservedKeyPatch || node.Parent() == nil || node.Parent().Key() != tokenRootNodeKey {
137+
return merged,errors.New("cannot merge mismatched root nodes")
138+
}
139+
node.key = merged.Key()
132140
}
133141

134142
err = recursiveMerge(node, &merged)

0 commit comments

Comments
 (0)