Skip to content

Commit

Permalink
Added support for reserved "patch" property
Browse files Browse the repository at this point in the history
  • Loading branch information
Galaco committed Dec 24, 2018
1 parent fadcdcb commit 852bf4a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion keyvalue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strings"
)

const reservedKeyPatch = "patch"

// A KeyValue object, that may hold multiple Values
type KeyValue struct {
key string
Expand Down Expand Up @@ -128,7 +130,13 @@ func (node *KeyValue) Parent() *KeyValue {
func (node *KeyValue) MergeInto(parent *KeyValue) (merged KeyValue, err error) {
merged = *parent
if node.Key() != merged.Key() {
return merged,errors.New("cannot merge mismatched root nodes")
// "patch" is a special key that can appear at the root of a keyvalue
// it does what it sounds like, its ony real purpose is to patch another tree
// with its own values
if node.Key() != reservedKeyPatch || node.Parent() == nil || node.Parent().Key() != tokenRootNodeKey {
return merged,errors.New("cannot merge mismatched root nodes")
}
node.key = merged.Key()
}

err = recursiveMerge(node, &merged)
Expand Down

0 comments on commit 852bf4a

Please sign in to comment.