Preserve sibling inheritance in configuration history and explanations
This commit is contained in:
60
internal/engine/inheritance_explain.go
Normal file
60
internal/engine/inheritance_explain.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package engine
|
||||
|
||||
import "gitea.maximumdirect.net/eric/ConfigKit/internal/document"
|
||||
|
||||
func appendInheritanceExplanation(explanation *Explanation, working **document.Node, query Path, operations []inheritanceOperation, secrets map[string]bool) {
|
||||
for _, operation := range operations {
|
||||
changes := projectedInheritanceChanges(query, operation)
|
||||
if operation.control != nil {
|
||||
if !pathsIntersect(operation.control.path, query) {
|
||||
continue
|
||||
}
|
||||
before := valueSnapshot(*working, query, secrets)
|
||||
replaceHistoryPath(working, operation.control.path, nil)
|
||||
after := valueSnapshot(*working, query, secrets)
|
||||
if len(changes) != 0 {
|
||||
explanation.History = append(explanation.History, ValueChange{
|
||||
Before: before, After: after, Origin: cloneOrigin(changes[0].Origin),
|
||||
Dependencies: clonePaths(changes[0].Dependencies),
|
||||
})
|
||||
}
|
||||
continue
|
||||
}
|
||||
if operation.transfer == nil {
|
||||
continue
|
||||
}
|
||||
before := valueSnapshot(*working, query, secrets)
|
||||
replaceHistoryPath(working, operation.transfer.to, operation.parent)
|
||||
afterParent := valueSnapshot(*working, query, secrets)
|
||||
parent, parentPresent := transferredOperationOrigin(operation, operationPathForQuery(operation.transfer.to, query))
|
||||
if pathsIntersect(operation.transfer.to, query) && parentPresent {
|
||||
parent.Operation = ChangeInheritance
|
||||
parent.Inheritance = projectInheritanceSteps(parent)
|
||||
explanation.History = append(explanation.History, ValueChange{
|
||||
Before: before, After: afterParent, Origin: parent,
|
||||
Dependencies: []Path{operation.transfer.from.clone(), operation.transfer.reference.clone()},
|
||||
})
|
||||
}
|
||||
replaceHistoryPath(working, operation.transfer.to, operation.effective)
|
||||
if !pathsIntersect(operation.transfer.to, query) {
|
||||
continue
|
||||
}
|
||||
afterChild := valueSnapshot(*working, query, secrets)
|
||||
if len(changes) != 0 {
|
||||
last := changes[len(changes)-1]
|
||||
if !parentPresent || len(changes) > 1 {
|
||||
explanation.History = append(explanation.History, ValueChange{
|
||||
Before: afterParent, After: afterChild, Origin: cloneOrigin(last.Origin),
|
||||
Dependencies: clonePaths(last.Dependencies),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func operationPathForQuery(root, query Path) Path {
|
||||
if pathContains(query, root) {
|
||||
return root
|
||||
}
|
||||
return query
|
||||
}
|
||||
Reference in New Issue
Block a user