Apply collection policies during sibling inheritance
This commit is contained in:
@@ -11,6 +11,7 @@ type inheritanceWalker struct {
|
||||
nodes int // logical non-directive nodes in the entire working tree
|
||||
origins map[string]Origin
|
||||
collectionPolicies collectionPolicyScope
|
||||
applicationPolicy sequencePolicy
|
||||
limits projectionLimits
|
||||
retained *retainedNodeCounter
|
||||
transfers []inheritanceTransfer
|
||||
@@ -34,10 +35,18 @@ func expandInheritanceWithBudgets(input *document.Node, inputOrigins map[string]
|
||||
}
|
||||
|
||||
func expandInheritanceWithPolicies(input *document.Node, inputOrigins map[string]Origin, policies collectionPolicyScope, limits projectionLimits) (*inheritanceScope, []Diagnostic) {
|
||||
return expandInheritanceWithPolicyBudgets(input, inputOrigins, policies, limits, historyNodeLimit)
|
||||
return expandInheritanceWithCollectionRules(input, inputOrigins, policies, sequencePolicy{}, limits)
|
||||
}
|
||||
|
||||
func expandInheritanceWithPolicyBudgets(input *document.Node, inputOrigins map[string]Origin, policies collectionPolicyScope, limits projectionLimits, historyLimit int) (*inheritanceScope, []Diagnostic) {
|
||||
return expandInheritanceWithCollectionRuleBudgets(input, inputOrigins, policies, sequencePolicy{}, limits, historyLimit)
|
||||
}
|
||||
|
||||
func expandInheritanceWithCollectionRules(input *document.Node, inputOrigins map[string]Origin, policies collectionPolicyScope, applicationPolicy sequencePolicy, limits projectionLimits) (*inheritanceScope, []Diagnostic) {
|
||||
return expandInheritanceWithCollectionRuleBudgets(input, inputOrigins, policies, applicationPolicy, limits, historyNodeLimit)
|
||||
}
|
||||
|
||||
func expandInheritanceWithCollectionRuleBudgets(input *document.Node, inputOrigins map[string]Origin, policies collectionPolicyScope, applicationPolicy sequencePolicy, limits projectionLimits, historyLimit int) (*inheritanceScope, []Diagnostic) {
|
||||
if input == nil || input.Kind != document.Mapping {
|
||||
return nil, []Diagnostic{{Code: CodeInheritanceInvalid, Severity: SeverityError,
|
||||
Message: "inheritance requires a mapping document root"}}
|
||||
@@ -54,6 +63,7 @@ func expandInheritanceWithPolicyBudgets(input *document.Node, inputOrigins map[s
|
||||
walker := inheritanceWalker{
|
||||
nodes: nodes, limits: limits, origins: origins,
|
||||
collectionPolicies: cloneCollectionPolicyScopeForInheritance(policies),
|
||||
applicationPolicy: applicationPolicy,
|
||||
retained: newRetainedNodeCounter(historyLimit),
|
||||
}
|
||||
if problem := walker.visit(&root, Path{}, true); problem != nil {
|
||||
@@ -102,11 +112,21 @@ func (w *inheritanceWalker) visit(node **document.Node, path Path, unscoped bool
|
||||
if limits.nodes >= 0 {
|
||||
limits.nodes -= w.nodes - before
|
||||
}
|
||||
resolved, diagnostics := expandSiblingDefinitionsWithPolicies(*node, path, limits, w.origins, w.collectionPolicies, w.retained)
|
||||
resolved, diagnostics := expandSiblingDefinitionsWithCollectionRules(
|
||||
*node, path, limits, w.origins, w.collectionPolicies, w.applicationPolicy, w.retained,
|
||||
)
|
||||
if len(diagnostics) != 0 {
|
||||
return &diagnostics[0]
|
||||
}
|
||||
*node = resolved.root
|
||||
for pointer, entry := range w.collectionPolicies.collections {
|
||||
if pathHasPrefix(entry.destination, path) {
|
||||
delete(w.collectionPolicies.collections, pointer)
|
||||
}
|
||||
}
|
||||
for _, entry := range resolved.collectionPolicies.collections {
|
||||
w.collectionPolicies.set(entry.destination, entry.policy)
|
||||
}
|
||||
deleteOriginSubtree(w.origins, path, original)
|
||||
for pointer, origin := range resolved.origins {
|
||||
w.origins[pointer] = origin
|
||||
|
||||
Reference in New Issue
Block a user