|
|
@@ -82,6 +82,12 @@ export function newCorrespondence({deltaRegistry, generateUUID, versionRegistry}
|
|
|
}
|
|
|
}));
|
|
|
|
|
|
+ // Helper
|
|
|
+ const filterCorrParents = (corrParentVersions: Version[]) => {
|
|
|
+ // when parsing/rendering, if one CORR-parent is a parent of another CORR-parent, then drop this one.
|
|
|
+ return corrParentVersions.filter(parent => !corrParentVersions.some(child => child !== parent && parent.findDescendant(child) !== undefined));
|
|
|
+ }
|
|
|
+
|
|
|
// Reducer
|
|
|
|
|
|
const parseExistingVersion = (csVersion: Version) => {
|
|
|
@@ -97,18 +103,18 @@ export function newCorrespondence({deltaRegistry, generateUUID, versionRegistry}
|
|
|
const corrParentVersions = csParentVersion.getReverseEmbeddings("cs").filter(isPartOfThisCorrespondence);
|
|
|
if (corrParentVersions.length === 0) {
|
|
|
throw new Error("Assertion failed: CS has a parent, but this parent is not yet part of a CORR version.");
|
|
|
- // console.log("Cannot parse CS version, because its parent is not parsed yet...");
|
|
|
- // continue;
|
|
|
- }
|
|
|
- if (corrParentVersions.length > 1) {
|
|
|
- throw new Error("Assertion failed: CS is part of multiple CORR versions (should be impossible, because parsing is deterministic)");
|
|
|
}
|
|
|
- const [corrParentVersion] = corrParentVersions;
|
|
|
+
|
|
|
+ // Even though parsing is deterministic, it is still possible that the same CS version is part of multiple CORR versions.
|
|
|
+ // For instance, when merging at the level of CS, and then rendering the change (with a conflict between the CORR-parents), results in a single CS version embedded in multiple CORR versions.
|
|
|
+
|
|
|
+ const filteredCorrParentVersions = filterCorrParents(corrParentVersions);
|
|
|
+ // And if then, there are still multiple CORR versions to choose from, we just pick one:
|
|
|
+ // (it would be better to ask the user which one, but whatever)
|
|
|
+ const [corrParentVersion] = filteredCorrParentVersions;
|
|
|
const asParentVersion = corrParentVersion.getEmbedding("as").version;
|
|
|
if (asParentVersion === undefined) {
|
|
|
throw new Error("Assertion failed: CS's parent is part of a CORR version, but that CORR version does not embed an AS version.");
|
|
|
- // console.log("Cannot parse - no parent AS version");
|
|
|
- // continue;
|
|
|
}
|
|
|
|
|
|
const [csGS, corrGS, asGS] = [csParentVersion, corrParentVersion, asParentVersion].map(v => getGraphState(v));
|
|
|
@@ -138,18 +144,13 @@ export function newCorrespondence({deltaRegistry, generateUUID, versionRegistry}
|
|
|
const corrParentVersions = asParentVersion.getReverseEmbeddings("as").filter(isPartOfThisCorrespondence);
|
|
|
if (corrParentVersions.length === 0) {
|
|
|
throw new Error("Assertion failed: AS has a parent, but this parent is not yet part of a CORR version.");
|
|
|
- // console.log("Cannot parse - no parent CORR version");
|
|
|
- // return;
|
|
|
}
|
|
|
// AS version may be embedded into multiple CORR versions
|
|
|
// If one CORR version is a child of another (parent), then we only render based on the child:
|
|
|
- const filteredCorrParentVersions = corrParentVersions.filter(parent => {
|
|
|
- // if there exists a child version, remove the parent from resulting array:
|
|
|
- return !corrParentVersions.some(child => child !== parent && parent.findDescendant(child) !== undefined);
|
|
|
- });
|
|
|
+ const filteredCorrParentVersions = filterCorrParents(corrParentVersions);
|
|
|
// And if then, there are still multiple CORR versions to choose from, we just pick one:
|
|
|
// (it would be better to ask the user which one, but whatever)
|
|
|
- const corrParentVersion = filteredCorrParentVersions[0]
|
|
|
+ const [corrParentVersion] = filteredCorrParentVersions;
|
|
|
console.log({corrParentVersion, filteredCorrParentVersions, corrParentVersions});
|
|
|
const csParentVersion = corrParentVersion.getEmbedding("cs").version;
|
|
|
if (csParentVersion === undefined) {
|
|
|
@@ -198,7 +199,7 @@ export function newCorrespondence({deltaRegistry, generateUUID, versionRegistry}
|
|
|
const csToAs = new Map();
|
|
|
const asToCs = new Map();
|
|
|
|
|
|
- for (const corrNode of corrGS.nodes.values()) {
|
|
|
+ for (const corrNode of corrGS.nodes.values()) {
|
|
|
const csNode = corrNode.getOutgoingEdges().get("cs");
|
|
|
if (csNode?.type !== "node") {
|
|
|
continue; // corrNode is not a correspondence node
|
|
|
@@ -236,8 +237,7 @@ export function newCorrespondence({deltaRegistry, generateUUID, versionRegistry}
|
|
|
}
|
|
|
|
|
|
if (asParentVersion.getReverseEmbeddings("as").filter(isPartOfThisCorrespondence).length === 0) {
|
|
|
- return renderExistingVersion(asParentVersion, setManualRendererState)
|
|
|
- .then(render);
|
|
|
+ return renderExistingVersion(asParentVersion, setManualRendererState).then(render);
|
|
|
}
|
|
|
else {
|
|
|
return render();
|