Share sequence history construction
This commit is contained in:
@@ -413,6 +413,27 @@ func applySequenceHistory(target **document.Node, incoming *document.Node, contr
|
||||
}
|
||||
}
|
||||
|
||||
func sequenceHistoryContributionForCombination(
|
||||
destination Path,
|
||||
operation sequenceMode,
|
||||
incoming *document.Node,
|
||||
combined sequenceCombinationResult,
|
||||
) sequenceHistoryContribution {
|
||||
contribution := sequenceHistoryContribution{
|
||||
path: destination.clone(), mode: sequenceHistoryMapped,
|
||||
}
|
||||
if operation == sequenceModeReplace {
|
||||
contribution.mode = sequenceHistoryReplace
|
||||
if incoming != nil && incoming.Kind == document.Sequence {
|
||||
contribution.length = len(incoming.Sequence)
|
||||
}
|
||||
return contribution
|
||||
}
|
||||
contribution.items = append([]sequenceItemProjection(nil), combined.higherItems...)
|
||||
contribution.replacements = append([]sequenceItemReplacement(nil), combined.replacements...)
|
||||
return contribution
|
||||
}
|
||||
|
||||
func cloneSequenceHistoryContributions(values []sequenceHistoryContribution) []sequenceHistoryContribution {
|
||||
if values == nil {
|
||||
return nil
|
||||
|
||||
@@ -469,21 +469,18 @@ func TestSequenceHistoryReplaysCombinationEvidence(t *testing.T) {
|
||||
t.Fatalf("combine diagnostics = %#v", diagnostics)
|
||||
}
|
||||
|
||||
mode := sequenceHistoryMapped
|
||||
if test.operation == sequenceModeReplace {
|
||||
mode = sequenceHistoryReplace
|
||||
}
|
||||
length := 0
|
||||
if mode == sequenceHistoryReplace {
|
||||
length = len(combined.higherItems)
|
||||
}
|
||||
application := historyApplication{
|
||||
layer: LayerOverlay,
|
||||
value: higherRoot,
|
||||
sequences: []sequenceHistoryContribution{{
|
||||
path: Keys("records"), mode: mode, length: length,
|
||||
items: combined.higherItems, replacements: combined.replacements,
|
||||
}},
|
||||
sequences: []sequenceHistoryContribution{
|
||||
sequenceHistoryContributionForCombination(Keys("records"), test.operation, higher, combined),
|
||||
},
|
||||
}
|
||||
if len(combined.higherItems) != 0 {
|
||||
combined.higherItems[0].outputIndex++
|
||||
}
|
||||
if len(combined.replacements) != 0 {
|
||||
combined.replacements[0].outputIndex++
|
||||
}
|
||||
application.sequencesByPath = indexSequenceHistoryContributions(application.sequences)
|
||||
replayed := document.Clone(lowerRoot)
|
||||
|
||||
@@ -85,17 +85,9 @@ func combineInheritanceTemplate(
|
||||
result.replacements = append(result.replacements, applyInheritanceSequenceOrigins(
|
||||
mergedOrigins, child.origins, childPath, lowerValue, incoming, combined, resolution.operation,
|
||||
)...)
|
||||
history := sequenceHistoryContribution{path: childPath.clone(), mode: sequenceHistoryMapped}
|
||||
if resolution.operation == sequenceModeReplace {
|
||||
history.mode = sequenceHistoryReplace
|
||||
if incoming != nil && incoming.Kind == document.Sequence {
|
||||
history.length = len(incoming.Sequence)
|
||||
}
|
||||
} else {
|
||||
history.items = append([]sequenceItemProjection(nil), combined.higherItems...)
|
||||
history.replacements = append([]sequenceItemReplacement(nil), combined.replacements...)
|
||||
}
|
||||
sequenceContributions = append(sequenceContributions, history)
|
||||
sequenceContributions = append(sequenceContributions, sequenceHistoryContributionForCombination(
|
||||
childPath, resolution.operation, incoming, combined,
|
||||
))
|
||||
return combined.value, true
|
||||
},
|
||||
})
|
||||
|
||||
@@ -274,17 +274,9 @@ func (operation *overlayMergeOperation) merge(path Path, existing, incoming *doc
|
||||
operation.incomingOrigins, operation.incomingPolicies, operation.layer,
|
||||
)
|
||||
operation.valueDestinations[path.String()] = true
|
||||
history := sequenceHistoryContribution{path: path.clone(), mode: sequenceHistoryMapped}
|
||||
if resolution.operation == sequenceModeReplace {
|
||||
history.mode = sequenceHistoryReplace
|
||||
if incoming != nil && incoming.Kind == document.Sequence {
|
||||
history.length = len(incoming.Sequence)
|
||||
}
|
||||
} else {
|
||||
history.items = append([]sequenceItemProjection(nil), combined.higherItems...)
|
||||
history.replacements = append([]sequenceItemReplacement(nil), combined.replacements...)
|
||||
}
|
||||
operation.sequenceApplications[path.String()] = history
|
||||
operation.sequenceApplications[path.String()] = sequenceHistoryContributionForCombination(
|
||||
path, resolution.operation, incoming, combined,
|
||||
)
|
||||
return combined.value, true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user