Apply explicit CLI configuration overrides
This commit is contained in:
51
overlay.go
51
overlay.go
@@ -10,6 +10,8 @@ import (
|
||||
type overlayRecord struct {
|
||||
change Change
|
||||
displaced []displacedDefinition
|
||||
before *document.Node
|
||||
after *document.Node
|
||||
}
|
||||
|
||||
type displacedDefinition struct {
|
||||
@@ -32,12 +34,12 @@ func overlayDocuments(base *composedDocument, overlay *document.Node) (*composed
|
||||
inputBytes: base.inputBytes,
|
||||
inputNodes: base.inputNodes,
|
||||
}
|
||||
mergeOverlayOrigin(result.origins, Path{}, overlay.Location)
|
||||
mergeOverlayMappings(result, result.root, overlay, Path{})
|
||||
mergeOverlayOrigin(result.origins, Path{}, overlay.Location, LayerProfile)
|
||||
mergeOverlayMappings(result, result.root, overlay, Path{}, LayerProfile, true)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func mergeOverlayMappings(result *composedDocument, target, overlay *document.Node, current Path) {
|
||||
func mergeOverlayMappings(result *composedDocument, target, overlay *document.Node, current Path, layer Layer, recordReplacements bool) {
|
||||
for _, incoming := range overlay.Mapping {
|
||||
path := current.Key(incoming.Key)
|
||||
index := documentEntryIndex(target.Mapping, incoming.Key)
|
||||
@@ -45,14 +47,14 @@ func mergeOverlayMappings(result *composedDocument, target, overlay *document.No
|
||||
cloned := incoming
|
||||
cloned.Value = document.Clone(incoming.Value)
|
||||
target.Mapping = append(target.Mapping, cloned)
|
||||
collectOverlayOrigins(result.origins, incoming.Value, path)
|
||||
collectOverlayOrigins(result.origins, incoming.Value, path, layer)
|
||||
continue
|
||||
}
|
||||
|
||||
existing := target.Mapping[index].Value
|
||||
if existing.Kind == document.Mapping && incoming.Value.Kind == document.Mapping {
|
||||
mergeOverlayOrigin(result.origins, path, incoming.Value.Location)
|
||||
mergeOverlayMappings(result, existing, incoming.Value, path)
|
||||
mergeOverlayOrigin(result.origins, path, incoming.Value.Location, layer)
|
||||
mergeOverlayMappings(result, existing, incoming.Value, path, layer, recordReplacements)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -61,41 +63,44 @@ func mergeOverlayMappings(result *composedDocument, target, overlay *document.No
|
||||
deleteOriginSubtree(result.origins, path)
|
||||
target.Mapping[index] = incoming
|
||||
target.Mapping[index].Value = document.Clone(incoming.Value)
|
||||
collectOverlayOrigins(result.origins, incoming.Value, path)
|
||||
result.overlays = append(result.overlays, overlayRecord{
|
||||
change: Change{
|
||||
Path: path.clone(), Origin: profileOrigin(incoming.Value.Location),
|
||||
Previous: previousOrigins(previous),
|
||||
},
|
||||
displaced: displaced,
|
||||
})
|
||||
collectOverlayOrigins(result.origins, incoming.Value, path, layer)
|
||||
if recordReplacements {
|
||||
result.overlays = append(result.overlays, overlayRecord{
|
||||
change: Change{
|
||||
Path: path.clone(), Origin: overlayOrigin(layer, incoming.Value.Location),
|
||||
Previous: previousOrigins(previous),
|
||||
},
|
||||
displaced: displaced,
|
||||
before: document.Clone(existing), after: document.Clone(incoming.Value),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func collectOverlayOrigins(origins map[string]Origin, node *document.Node, path Path) {
|
||||
origins[path.String()] = profileOrigin(node.Location)
|
||||
func collectOverlayOrigins(origins map[string]Origin, node *document.Node, path Path, layer Layer) {
|
||||
origins[path.String()] = overlayOrigin(layer, node.Location)
|
||||
switch node.Kind {
|
||||
case document.Mapping:
|
||||
for _, entry := range node.Mapping {
|
||||
collectOverlayOrigins(origins, entry.Value, path.Key(entry.Key))
|
||||
collectOverlayOrigins(origins, entry.Value, path.Key(entry.Key), layer)
|
||||
}
|
||||
case document.Sequence:
|
||||
for index, child := range node.Sequence {
|
||||
collectOverlayOrigins(origins, child, path.Index(index))
|
||||
collectOverlayOrigins(origins, child, path.Index(index), layer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mergeOverlayOrigin(origins map[string]Origin, path Path, location document.Location) {
|
||||
func mergeOverlayOrigin(origins map[string]Origin, path Path, location document.Location, layer Layer) {
|
||||
pointer := path.String()
|
||||
origin := cloneOrigin(origins[pointer])
|
||||
origin.Layer = LayerProfile
|
||||
origin.Layer = layer
|
||||
origin.Locations = append(origin.Locations, publicLocation(location))
|
||||
origins[pointer] = origin
|
||||
}
|
||||
|
||||
func profileOrigin(location document.Location) Origin {
|
||||
return Origin{Layer: LayerProfile, Locations: []Location{publicLocation(location)}}
|
||||
func overlayOrigin(layer Layer, location document.Location) Origin {
|
||||
return Origin{Layer: layer, Locations: []Location{publicLocation(location)}}
|
||||
}
|
||||
|
||||
func previousOrigins(origin Origin) []Origin {
|
||||
@@ -154,6 +159,8 @@ func cloneOverlayRecords(records []overlayRecord) []overlayRecord {
|
||||
cloned := make([]overlayRecord, len(records))
|
||||
for index, record := range records {
|
||||
cloned[index].change = cloneChange(record.change)
|
||||
cloned[index].before = document.Clone(record.before)
|
||||
cloned[index].after = document.Clone(record.after)
|
||||
cloned[index].displaced = make([]displacedDefinition, len(record.displaced))
|
||||
for displacedIndex, displaced := range record.displaced {
|
||||
cloned[index].displaced[displacedIndex] = displacedDefinition{
|
||||
|
||||
Reference in New Issue
Block a user