@fluidframework/tree 2.61.0 → 2.62.0-356644
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-report/tree.alpha.api.md +3 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/rebase/index.d.ts +1 -1
- package/dist/core/rebase/index.d.ts.map +1 -1
- package/dist/core/rebase/index.js +2 -1
- package/dist/core/rebase/index.js.map +1 -1
- package/dist/core/rebase/utils.d.ts +10 -0
- package/dist/core/rebase/utils.d.ts.map +1 -1
- package/dist/core/rebase/utils.js +20 -1
- package/dist/core/rebase/utils.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/shared-tree/schematizingTreeView.js +2 -2
- package/dist/shared-tree/schematizingTreeView.js.map +1 -1
- package/dist/shared-tree/sharedTree.d.ts +12 -2
- package/dist/shared-tree/sharedTree.d.ts.map +1 -1
- package/dist/shared-tree/sharedTree.js +71 -33
- package/dist/shared-tree/sharedTree.js.map +1 -1
- package/dist/shared-tree/treeCheckout.d.ts +13 -7
- package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
- package/dist/shared-tree/treeCheckout.js +114 -84
- package/dist/shared-tree/treeCheckout.js.map +1 -1
- package/dist/shared-tree-core/branch.d.ts +3 -0
- package/dist/shared-tree-core/branch.d.ts.map +1 -1
- package/dist/shared-tree-core/branch.js.map +1 -1
- package/dist/shared-tree-core/branchIdCodec.d.ts +11 -0
- package/dist/shared-tree-core/branchIdCodec.d.ts.map +1 -0
- package/dist/shared-tree-core/branchIdCodec.js +18 -0
- package/dist/shared-tree-core/branchIdCodec.js.map +1 -0
- package/dist/shared-tree-core/editManager.d.ts +33 -63
- package/dist/shared-tree-core/editManager.d.ts.map +1 -1
- package/dist/shared-tree-core/editManager.js +437 -290
- package/dist/shared-tree-core/editManager.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.d.ts +1 -1
- package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/editManagerCodecs.js +7 -96
- package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +17 -0
- package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -0
- package/dist/shared-tree-core/editManagerCodecsCommons.js +139 -0
- package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -0
- package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts +16 -0
- package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -0
- package/dist/shared-tree-core/editManagerCodecsV1toV4.js +39 -0
- package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -0
- package/dist/shared-tree-core/editManagerCodecsV5.d.ts +16 -0
- package/dist/shared-tree-core/editManagerCodecsV5.d.ts.map +1 -0
- package/dist/shared-tree-core/editManagerCodecsV5.js +58 -0
- package/dist/shared-tree-core/editManagerCodecsV5.js.map +1 -0
- package/dist/shared-tree-core/{editManagerFormat.d.ts → editManagerFormatCommons.d.ts} +31 -7
- package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -0
- package/dist/shared-tree-core/{editManagerFormat.js → editManagerFormatCommons.js} +13 -12
- package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -0
- package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +31 -0
- package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -0
- package/dist/shared-tree-core/editManagerFormatV1toV4.js +24 -0
- package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -0
- package/dist/shared-tree-core/editManagerFormatV5.d.ts +62 -0
- package/dist/shared-tree-core/editManagerFormatV5.d.ts.map +1 -0
- package/dist/shared-tree-core/editManagerFormatV5.js +20 -0
- package/dist/shared-tree-core/editManagerFormatV5.js.map +1 -0
- package/dist/shared-tree-core/index.d.ts +3 -3
- package/dist/shared-tree-core/index.d.ts.map +1 -1
- package/dist/shared-tree-core/index.js.map +1 -1
- package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +11 -0
- package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -0
- package/dist/shared-tree-core/messageCodecV1ToV4.js +59 -0
- package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -0
- package/dist/shared-tree-core/messageCodecV5.d.ts +11 -0
- package/dist/shared-tree-core/messageCodecV5.d.ts.map +1 -0
- package/dist/shared-tree-core/messageCodecV5.js +78 -0
- package/dist/shared-tree-core/messageCodecV5.js.map +1 -0
- package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/dist/shared-tree-core/messageCodecs.js +16 -47
- package/dist/shared-tree-core/messageCodecs.js.map +1 -1
- package/dist/shared-tree-core/{messageFormat.d.ts → messageFormatV1ToV4.d.ts} +1 -1
- package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -0
- package/dist/shared-tree-core/{messageFormat.js → messageFormatV1ToV4.js} +1 -1
- package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -0
- package/dist/shared-tree-core/messageFormatV5.d.ts +42 -0
- package/dist/shared-tree-core/messageFormatV5.d.ts.map +1 -0
- package/dist/shared-tree-core/messageFormatV5.js +20 -0
- package/dist/shared-tree-core/messageFormatV5.js.map +1 -0
- package/dist/shared-tree-core/messageTypes.d.ts +12 -2
- package/dist/shared-tree-core/messageTypes.d.ts.map +1 -1
- package/dist/shared-tree-core/messageTypes.js.map +1 -1
- package/dist/shared-tree-core/sequenceIdUtils.d.ts +1 -1
- package/dist/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
- package/dist/shared-tree-core/sequenceIdUtils.js.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.d.ts +18 -5
- package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/dist/shared-tree-core/sharedTreeCore.js +175 -56
- package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/dist/simple-tree/api/tree.d.ts +10 -0
- package/dist/simple-tree/api/tree.d.ts.map +1 -1
- package/dist/simple-tree/api/tree.js.map +1 -1
- package/lib/core/index.d.ts +1 -1
- package/lib/core/index.d.ts.map +1 -1
- package/lib/core/index.js +1 -1
- package/lib/core/index.js.map +1 -1
- package/lib/core/rebase/index.d.ts +1 -1
- package/lib/core/rebase/index.d.ts.map +1 -1
- package/lib/core/rebase/index.js +1 -1
- package/lib/core/rebase/index.js.map +1 -1
- package/lib/core/rebase/utils.d.ts +10 -0
- package/lib/core/rebase/utils.d.ts.map +1 -1
- package/lib/core/rebase/utils.js +18 -0
- package/lib/core/rebase/utils.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/shared-tree/schematizingTreeView.js +2 -2
- package/lib/shared-tree/schematizingTreeView.js.map +1 -1
- package/lib/shared-tree/sharedTree.d.ts +12 -2
- package/lib/shared-tree/sharedTree.d.ts.map +1 -1
- package/lib/shared-tree/sharedTree.js +72 -34
- package/lib/shared-tree/sharedTree.js.map +1 -1
- package/lib/shared-tree/treeCheckout.d.ts +13 -7
- package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
- package/lib/shared-tree/treeCheckout.js +115 -85
- package/lib/shared-tree/treeCheckout.js.map +1 -1
- package/lib/shared-tree-core/branch.d.ts +3 -0
- package/lib/shared-tree-core/branch.d.ts.map +1 -1
- package/lib/shared-tree-core/branch.js.map +1 -1
- package/lib/shared-tree-core/branchIdCodec.d.ts +11 -0
- package/lib/shared-tree-core/branchIdCodec.d.ts.map +1 -0
- package/lib/shared-tree-core/branchIdCodec.js +13 -0
- package/lib/shared-tree-core/branchIdCodec.js.map +1 -0
- package/lib/shared-tree-core/editManager.d.ts +33 -63
- package/lib/shared-tree-core/editManager.d.ts.map +1 -1
- package/lib/shared-tree-core/editManager.js +437 -290
- package/lib/shared-tree-core/editManager.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.d.ts +1 -1
- package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/editManagerCodecs.js +4 -93
- package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
- package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +17 -0
- package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -0
- package/lib/shared-tree-core/editManagerCodecsCommons.js +134 -0
- package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -0
- package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts +16 -0
- package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -0
- package/lib/shared-tree-core/editManagerCodecsV1toV4.js +35 -0
- package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -0
- package/lib/shared-tree-core/editManagerCodecsV5.d.ts +16 -0
- package/lib/shared-tree-core/editManagerCodecsV5.d.ts.map +1 -0
- package/lib/shared-tree-core/editManagerCodecsV5.js +54 -0
- package/lib/shared-tree-core/editManagerCodecsV5.js.map +1 -0
- package/lib/shared-tree-core/{editManagerFormat.d.ts → editManagerFormatCommons.d.ts} +31 -7
- package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -0
- package/lib/shared-tree-core/{editManagerFormat.js → editManagerFormatCommons.js} +10 -11
- package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -0
- package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +31 -0
- package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -0
- package/lib/shared-tree-core/editManagerFormatV1toV4.js +20 -0
- package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -0
- package/lib/shared-tree-core/editManagerFormatV5.d.ts +62 -0
- package/lib/shared-tree-core/editManagerFormatV5.d.ts.map +1 -0
- package/lib/shared-tree-core/editManagerFormatV5.js +16 -0
- package/lib/shared-tree-core/editManagerFormatV5.js.map +1 -0
- package/lib/shared-tree-core/index.d.ts +3 -3
- package/lib/shared-tree-core/index.d.ts.map +1 -1
- package/lib/shared-tree-core/index.js.map +1 -1
- package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +11 -0
- package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -0
- package/lib/shared-tree-core/messageCodecV1ToV4.js +55 -0
- package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -0
- package/lib/shared-tree-core/messageCodecV5.d.ts +11 -0
- package/lib/shared-tree-core/messageCodecV5.d.ts.map +1 -0
- package/lib/shared-tree-core/messageCodecV5.js +74 -0
- package/lib/shared-tree-core/messageCodecV5.js.map +1 -0
- package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
- package/lib/shared-tree-core/messageCodecs.js +17 -48
- package/lib/shared-tree-core/messageCodecs.js.map +1 -1
- package/lib/shared-tree-core/{messageFormat.d.ts → messageFormatV1ToV4.d.ts} +1 -1
- package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -0
- package/lib/shared-tree-core/{messageFormat.js → messageFormatV1ToV4.js} +1 -1
- package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -0
- package/lib/shared-tree-core/messageFormatV5.d.ts +42 -0
- package/lib/shared-tree-core/messageFormatV5.d.ts.map +1 -0
- package/lib/shared-tree-core/messageFormatV5.js +16 -0
- package/lib/shared-tree-core/messageFormatV5.js.map +1 -0
- package/lib/shared-tree-core/messageTypes.d.ts +12 -2
- package/lib/shared-tree-core/messageTypes.d.ts.map +1 -1
- package/lib/shared-tree-core/messageTypes.js.map +1 -1
- package/lib/shared-tree-core/sequenceIdUtils.d.ts +1 -1
- package/lib/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
- package/lib/shared-tree-core/sequenceIdUtils.js.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.d.ts +18 -5
- package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
- package/lib/shared-tree-core/sharedTreeCore.js +176 -57
- package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
- package/lib/simple-tree/api/tree.d.ts +10 -0
- package/lib/simple-tree/api/tree.d.ts.map +1 -1
- package/lib/simple-tree/api/tree.js.map +1 -1
- package/package.json +20 -20
- package/src/core/index.ts +1 -0
- package/src/core/rebase/index.ts +1 -0
- package/src/core/rebase/utils.ts +27 -0
- package/src/packageVersion.ts +1 -1
- package/src/shared-tree/schematizingTreeView.ts +2 -2
- package/src/shared-tree/sharedTree.ts +103 -46
- package/src/shared-tree/treeCheckout.ts +147 -98
- package/src/shared-tree-core/branch.ts +7 -0
- package/src/shared-tree-core/branchIdCodec.ts +28 -0
- package/src/shared-tree-core/editManager.ts +709 -437
- package/src/shared-tree-core/editManagerCodecs.ts +4 -164
- package/src/shared-tree-core/editManagerCodecsCommons.ts +236 -0
- package/src/shared-tree-core/editManagerCodecsV1toV4.ts +108 -0
- package/src/shared-tree-core/editManagerCodecsV5.ts +150 -0
- package/src/shared-tree-core/{editManagerFormat.ts → editManagerFormatCommons.ts} +17 -13
- package/src/shared-tree-core/editManagerFormatV1toV4.ts +42 -0
- package/src/shared-tree-core/editManagerFormatV5.ts +35 -0
- package/src/shared-tree-core/index.ts +3 -1
- package/src/shared-tree-core/messageCodecV1ToV4.ts +101 -0
- package/src/shared-tree-core/messageCodecV5.ts +128 -0
- package/src/shared-tree-core/messageCodecs.ts +16 -85
- package/src/shared-tree-core/messageFormatV5.ts +50 -0
- package/src/shared-tree-core/messageTypes.ts +15 -2
- package/src/shared-tree-core/sequenceIdUtils.ts +1 -1
- package/src/shared-tree-core/sharedTreeCore.ts +270 -84
- package/src/simple-tree/api/tree.ts +15 -0
- package/dist/shared-tree-core/editManagerFormat.d.ts.map +0 -1
- package/dist/shared-tree-core/editManagerFormat.js.map +0 -1
- package/dist/shared-tree-core/messageFormat.d.ts.map +0 -1
- package/dist/shared-tree-core/messageFormat.js.map +0 -1
- package/lib/shared-tree-core/editManagerFormat.d.ts.map +0 -1
- package/lib/shared-tree-core/editManagerFormat.js.map +0 -1
- package/lib/shared-tree-core/messageFormat.d.ts.map +0 -1
- package/lib/shared-tree-core/messageFormat.js.map +0 -1
- /package/src/shared-tree-core/{messageFormat.ts → messageFormatV1ToV4.ts} +0 -0
|
@@ -7,7 +7,7 @@ import { createEmitter } from "@fluid-internal/client-utils";
|
|
|
7
7
|
import { BTree } from "@tylerbu/sorted-btree-es6";
|
|
8
8
|
import { findAncestor, findCommonAncestor, mintCommit, tagChange, } from "../core/index.js";
|
|
9
9
|
import { brand, getOrCreate, mapIterable } from "../util/index.js";
|
|
10
|
-
import { SharedTreeBranch, onForkTransitive } from "./branch.js";
|
|
10
|
+
import { SharedTreeBranch, onForkTransitive, } from "./branch.js";
|
|
11
11
|
import { getUpperBoundOfPreviousSequenceId, equalSequenceIds, maxSequenceId, minSequenceId, sequenceIdComparator, } from "./sequenceIdUtils.js";
|
|
12
12
|
import { TelemetryEventBatcher, } from "@fluidframework/telemetry-utils/internal";
|
|
13
13
|
export const minimumPossibleSequenceNumber = brand(Number.MIN_SAFE_INTEGER);
|
|
@@ -40,25 +40,11 @@ export class EditManager {
|
|
|
40
40
|
this.localSessionId = localSessionId;
|
|
41
41
|
this.mintRevisionTag = mintRevisionTag;
|
|
42
42
|
this._events = createEmitter();
|
|
43
|
+
this.sharedBranches = new Map();
|
|
43
44
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
this.trunkMetadata = new Map();
|
|
48
|
-
/**
|
|
49
|
-
* A map from a sequence id to the commit in the {@link trunk} which has that sequence id.
|
|
50
|
-
* This also includes an entry for the {@link trunkBase} which always has the lowest key in the map.
|
|
51
|
-
*/
|
|
52
|
-
this.sequenceMap = new BTree(undefined, sequenceIdComparator);
|
|
53
|
-
/**
|
|
54
|
-
* Branches are maintained to represent the local change list that the issuing client had
|
|
55
|
-
* at the time of submitting the latest known edit on the branch.
|
|
56
|
-
* This means the head commit of each branch is always in its original (non-rebased) form.
|
|
57
|
-
*/
|
|
58
|
-
this.peerLocalBranches = new Map();
|
|
59
|
-
/**
|
|
60
|
-
* Tracks where on the trunk all registered branches are based. Each key is the sequence id of a commit on
|
|
61
|
-
* the trunk, and the value is the set of all branches who have that commit as their common ancestor with the trunk.
|
|
45
|
+
* Tracks where on the trunk of the main branch all registered branches are based.
|
|
46
|
+
* Each key is the sequence id of a commit on the trunk,
|
|
47
|
+
* and the value is the set of all branches who have that commit as their common ancestor with the trunk.
|
|
62
48
|
*
|
|
63
49
|
* @remarks
|
|
64
50
|
* This does not include the local branch.
|
|
@@ -71,39 +57,28 @@ export class EditManager {
|
|
|
71
57
|
* @remarks If there are more than one commit with the same sequence number we assume this refers to the last commit in the batch.
|
|
72
58
|
*/
|
|
73
59
|
this.minimumSequenceNumber = minimumPossibleSequenceNumber;
|
|
74
|
-
/**
|
|
75
|
-
* The list of commits (from oldest to most recent) that are on the local branch but not on the trunk.
|
|
76
|
-
* When a local commit is sequenced, the first commit in this list shifted onto the tip of the trunk.
|
|
77
|
-
*/
|
|
78
|
-
this.localCommits = [];
|
|
79
60
|
this.trunkBase = {
|
|
80
61
|
revision: rootRevision,
|
|
81
62
|
change: changeFamily.rebaser.compose([]),
|
|
82
63
|
};
|
|
83
|
-
this.sequenceMap.set(minimumPossibleSequenceId, this.trunkBase);
|
|
84
64
|
if (logger !== undefined) {
|
|
85
65
|
this.telemetryEventBatcher = new TelemetryEventBatcher({
|
|
86
66
|
eventName: "rebaseProcessing",
|
|
87
67
|
category: "performance",
|
|
88
68
|
}, logger, maxRebaseStatsAggregationCount);
|
|
89
69
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this.localBranch.events.on("afterChange", (event) => {
|
|
93
|
-
if (event.type === "append") {
|
|
94
|
-
for (const commit of event.newCommits) {
|
|
95
|
-
this.localCommits.push(commit);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
this.localCommits.length = 0;
|
|
100
|
-
findCommonAncestor([this.localBranch.getHead(), this.localCommits], this.trunk.getHead());
|
|
101
|
-
}
|
|
102
|
-
});
|
|
70
|
+
const mainTrunk = new SharedTreeBranch(this.trunkBase, changeFamily, mintRevisionTag, this._events, this.telemetryEventBatcher);
|
|
71
|
+
const mainBranch = this.createSharedBranch("main", undefined, undefined, mainTrunk);
|
|
103
72
|
// Track all forks of the local branch for purposes of trunk eviction. Unlike the local branch, they have
|
|
104
73
|
// an unknown lifetime and rebase frequency, so we can not make any assumptions about which trunk commits
|
|
105
74
|
// they require and therefore we monitor them explicitly.
|
|
106
|
-
onForkTransitive(
|
|
75
|
+
onForkTransitive(mainBranch.localBranch, (fork) => this.registerBranch(fork));
|
|
76
|
+
}
|
|
77
|
+
getLocalBranch(branchId) {
|
|
78
|
+
return this.getSharedBranch(branchId).localBranch;
|
|
79
|
+
}
|
|
80
|
+
getSharedBranch(branchId) {
|
|
81
|
+
return this.sharedBranches.get(branchId) ?? fail("Branch does not exist");
|
|
107
82
|
}
|
|
108
83
|
/**
|
|
109
84
|
* Make the given branch known to the `EditManager`. The `EditManager` will ensure that all registered
|
|
@@ -125,30 +100,32 @@ export class EditManager {
|
|
|
125
100
|
const offAfterRebase = branch.events.on("afterChange", (args) => {
|
|
126
101
|
if (args.type === "rebase") {
|
|
127
102
|
this.trackBranch(branch);
|
|
128
|
-
this.
|
|
103
|
+
this.trimHistory();
|
|
129
104
|
}
|
|
130
105
|
});
|
|
131
106
|
// When the branch is disposed, update our branch set and trim the trunk
|
|
132
107
|
const offDispose = branch.events.on("dispose", () => {
|
|
133
108
|
this.untrackBranch(branch);
|
|
134
|
-
this.
|
|
109
|
+
this.trimHistory();
|
|
135
110
|
offBeforeRebase();
|
|
136
111
|
offAfterRebase();
|
|
137
112
|
offDispose();
|
|
138
113
|
});
|
|
139
114
|
}
|
|
140
115
|
trackBranch(b) {
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
116
|
+
const main = this.getSharedBranch("main");
|
|
117
|
+
const trunkCommit = findCommonAncestor(main.trunk.getHead(), b.getHead()) ??
|
|
118
|
+
fail(0xad2 /* Expected branch to be related to main */);
|
|
119
|
+
const sequenceId = main.getCommitSequenceId(trunkCommit.revision);
|
|
144
120
|
const branches = getOrCreate(this.trunkBranches, sequenceId, () => new Set());
|
|
145
121
|
assert(!branches.has(b), 0x670 /* Branch was registered more than once */);
|
|
146
122
|
branches.add(b);
|
|
147
123
|
}
|
|
148
124
|
untrackBranch(b) {
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
125
|
+
const main = this.getSharedBranch("main");
|
|
126
|
+
const trunkCommit = findCommonAncestor(main.trunk.getHead(), b.getHead()) ??
|
|
127
|
+
fail(0xad3 /* Expected branch to be related to main */);
|
|
128
|
+
const sequenceId = main.getCommitSequenceId(trunkCommit.revision);
|
|
152
129
|
const branches = this.trunkBranches.get(sequenceId) ?? fail(0xad4 /* Expected branch to be tracked */);
|
|
153
130
|
assert(branches.delete(b), 0x671 /* Expected branch to be tracked */);
|
|
154
131
|
if (branches.size === 0) {
|
|
@@ -156,54 +133,17 @@ export class EditManager {
|
|
|
156
133
|
}
|
|
157
134
|
}
|
|
158
135
|
/**
|
|
159
|
-
*
|
|
160
|
-
* @param sequenceId - The sequence id of the new trunk commit
|
|
161
|
-
* @remarks This method is a performance optimization for the scenario where this client receives its own change back after sequencing.
|
|
162
|
-
* The normal (not optimized) process in this case would be to apply the new sequenced commit to the trunk and then rebase the local branch over the trunk.
|
|
163
|
-
* The first commit will be "the same" (as in, it will have the same revision) as the commit that was just sequenced, so the rebase will be a no-op.
|
|
164
|
-
* Because the rebase is a no-op, we can skip it entirely and simply remove the commit from the local branch and append it to the trunk.
|
|
165
|
-
* Avoiding the overhead of the rebase process, even when it's a no-op, has real measured performance benefits and is worth the added complexity here.
|
|
136
|
+
* Return the sequenced number of the latest sequenced change.
|
|
166
137
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.pushGraphCommitToTrunk(sequenceId, firstLocalCommit, this.localSessionId);
|
|
174
|
-
// Next, we need to update the sequence IDs that our local branches (user's branches, not peer branches) are associated with.
|
|
175
|
-
// In particular, if a local branch is based on the previous trunk head (the branch's first ancestor in the trunk is the commit that was the head before we pushed the new commit)
|
|
176
|
-
// and also branches off of the local branch (it has an ancestor that is part of the local branch), it needs to have its sequence number advanced to be that of the new trunk head.
|
|
177
|
-
// Intuitively, this makes sense because:
|
|
178
|
-
// 1. The trunk's head just advanced forward by some (sequence) amount.
|
|
179
|
-
// 2. The local branch is always rebased to be branching off of the head of the trunk (not literally in this case, because of the optimization, but in effect).
|
|
180
|
-
// 3. Therefore, the entire local branch just advanced forward by some (sequence) amount, and any commits downstream of it which track the sequence numbers of their base commits on the trunk should also advance.
|
|
181
|
-
// This update is not necessarily required for all local branches, since some may have fallen behind the local branch and are based on older trunk commits (such branches do not need updating).
|
|
182
|
-
const currentBranches = this.trunkBranches.get(previousSequenceId);
|
|
183
|
-
if (currentBranches !== undefined) {
|
|
184
|
-
const newBranches = getOrCreate(this.trunkBranches, sequenceId, () => new Set());
|
|
185
|
-
for (const branch of currentBranches) {
|
|
186
|
-
// Check every branch associated with the old sequence ID and advance it if it is based on the local branch (specifically, on the local branch as it was before we pushed its first commit to the trunk).
|
|
187
|
-
// We validate this by checking if the branch's head is a descendant of the local commit that we just pushed.
|
|
188
|
-
if (findAncestor(branch.getHead(), (c) => c === firstLocalCommit) !== undefined) {
|
|
189
|
-
newBranches.add(branch);
|
|
190
|
-
currentBranches.delete(branch);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
// Clean up our trunk branches map by removing any empty sets.
|
|
194
|
-
if (currentBranches.size === 0) {
|
|
195
|
-
this.trunkBranches.delete(previousSequenceId);
|
|
196
|
-
}
|
|
197
|
-
if (newBranches.size === 0) {
|
|
198
|
-
this.trunkBranches.delete(sequenceId);
|
|
138
|
+
getLatestSequenceNumber() {
|
|
139
|
+
let maxSequenceNumber;
|
|
140
|
+
for (const branch of this.sharedBranches.values()) {
|
|
141
|
+
const branchMax = branch.getCommitSequenceId(branch.trunk.getHead().revision).sequenceNumber;
|
|
142
|
+
if (maxSequenceNumber === undefined || maxSequenceNumber < branchMax) {
|
|
143
|
+
maxSequenceNumber = branchMax;
|
|
199
144
|
}
|
|
200
145
|
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Return the sequence number at which the given commit was sequenced on the trunk, or undefined if the commit is not part of the trunk.
|
|
204
|
-
*/
|
|
205
|
-
getSequenceNumber(trunkCommit) {
|
|
206
|
-
return this.trunkMetadata.get(trunkCommit.revision)?.sequenceId.sequenceNumber;
|
|
146
|
+
return maxSequenceNumber;
|
|
207
147
|
}
|
|
208
148
|
/**
|
|
209
149
|
* Advances the minimum sequence number, and removes all commits from the trunk which lie outside the collaboration window,
|
|
@@ -212,21 +152,21 @@ export class EditManager {
|
|
|
212
152
|
*
|
|
213
153
|
* @remarks If there are more than one commit with the same sequence number we assume this refers to the last commit in the batch.
|
|
214
154
|
*/
|
|
215
|
-
advanceMinimumSequenceNumber(minimumSequenceNumber,
|
|
155
|
+
advanceMinimumSequenceNumber(minimumSequenceNumber, trimHistory = true) {
|
|
216
156
|
if (minimumSequenceNumber === this.minimumSequenceNumber) {
|
|
217
157
|
return;
|
|
218
158
|
}
|
|
219
159
|
assert(minimumSequenceNumber > this.minimumSequenceNumber, 0x476 /* number must be larger or equal to current minimumSequenceNumber. */);
|
|
220
160
|
this.minimumSequenceNumber = minimumSequenceNumber;
|
|
221
|
-
if (
|
|
222
|
-
this.
|
|
161
|
+
if (trimHistory) {
|
|
162
|
+
this.trimHistory();
|
|
223
163
|
}
|
|
224
164
|
}
|
|
225
165
|
/**
|
|
226
166
|
* Examines the latest known minimum sequence number and the trunk bases of any registered branches to determine
|
|
227
167
|
* if any commits on the trunk are unreferenced and unneeded for future computation; those found are evicted from the trunk.
|
|
228
168
|
*/
|
|
229
|
-
|
|
169
|
+
trimHistory() {
|
|
230
170
|
/** The sequence id of the most recent commit on the trunk that will be trimmed */
|
|
231
171
|
let trunkTailSequenceId = {
|
|
232
172
|
sequenceNumber: this.minimumSequenceNumber,
|
|
@@ -240,118 +180,72 @@ export class EditManager {
|
|
|
240
180
|
const sequenceIdBeforeMinimumBranchBase = getUpperBoundOfPreviousSequenceId(minimumBranchBaseSequenceId);
|
|
241
181
|
trunkTailSequenceId = minSequenceId(trunkTailSequenceId, sequenceIdBeforeMinimumBranchBase);
|
|
242
182
|
}
|
|
243
|
-
const
|
|
183
|
+
const mainBranch = this.getSharedBranch("main");
|
|
184
|
+
const [sequenceId, latestEvicted] = mainBranch.getClosestTrunkCommit(maxSequenceId(trunkTailSequenceId, mainBranch.sequenceIdToCommit.minKey() ?? minimumPossibleSequenceId));
|
|
244
185
|
// Don't do any work if the commit found by the search is already the tail of the trunk
|
|
245
|
-
if (latestEvicted
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
assert(commit === newTrunkBase, 0x729 /* Expected last evicted commit to be new trunk base */);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
Reflect.defineProperty(commit, "change", {
|
|
277
|
-
get: () => assert(false, 0xa5e /* Should not access 'change' property of an evicted commit */),
|
|
278
|
-
});
|
|
279
|
-
Reflect.defineProperty(commit, "revision", {
|
|
280
|
-
get: () => assert(false, 0xa5f /* Should not access 'revision' property of an evicted commit */),
|
|
281
|
-
});
|
|
282
|
-
Reflect.defineProperty(commit, "parent", {
|
|
283
|
-
get: () => assert(false, 0xa60 /* Should not access 'parent' property of an evicted commit */),
|
|
284
|
-
});
|
|
285
|
-
return { delete: true };
|
|
286
|
-
}
|
|
186
|
+
if (latestEvicted === this.trunkBase) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
// This mutation is a performance hack. If commits are truly immutable, then changing the trunk's tail requires
|
|
190
|
+
// regenerating the entire commit graph. Instead, we can simply chop off the tail like this if we're certain
|
|
191
|
+
// that there are no outstanding references to any of the commits being removed (other than the references via
|
|
192
|
+
// the trunk). The peer branches have been rebased to the head of the trunk, the local branch is already rebased
|
|
193
|
+
// to the head of the trunk, and all other branches are tracked by `trunkBranches` and known to be ahead of or at
|
|
194
|
+
// `newTrunkBase`. Therefore, no branches should have unique references to any of the commits being evicted here.
|
|
195
|
+
// We mutate the most recent of the evicted commits to become the new trunk base. That way, any other commits that
|
|
196
|
+
// have parent pointers to the latest evicted commit will stay linked, even though that it is no longer part of the trunk.
|
|
197
|
+
const newTrunkBase = latestEvicted;
|
|
198
|
+
// collect the revisions that will be trimmed to send as part of the branch trimmed event
|
|
199
|
+
const trimmedCommits = getPathFromBase(newTrunkBase, this.trunkBase);
|
|
200
|
+
const trimmedRevisions = trimmedCommits.map((c) => c.revision);
|
|
201
|
+
// The minimum sequence number informs us that all peer branches are at least caught up to the tail commit,
|
|
202
|
+
// so rebase them accordingly. This is necessary to prevent peer branches from referencing any evicted commits.
|
|
203
|
+
mainBranch.trimHistory(latestEvicted, sequenceId);
|
|
204
|
+
// Only the last trimmed commit, which is the new trunk base, should remain accessible.
|
|
205
|
+
for (const commit of trimmedCommits.slice(0, -1)) {
|
|
206
|
+
Reflect.defineProperty(commit, "change", {
|
|
207
|
+
get: () => assert(false, 0xa5e /* Should not access 'change' property of an evicted commit */),
|
|
208
|
+
});
|
|
209
|
+
Reflect.defineProperty(commit, "revision", {
|
|
210
|
+
get: () => assert(false, 0xa5f /* Should not access 'revision' property of an evicted commit */),
|
|
211
|
+
});
|
|
212
|
+
Reflect.defineProperty(commit, "parent", {
|
|
213
|
+
get: () => assert(false, 0xa60 /* Should not access 'parent' property of an evicted commit */),
|
|
287
214
|
});
|
|
288
|
-
const trunkSize = getPathFromBase(this.trunk.getHead(), this.trunkBase).length;
|
|
289
|
-
assert(this.sequenceMap.size === trunkSize + 1, 0x744 /* The size of the sequenceMap must have one element more than the trunk */);
|
|
290
|
-
assert(this.trunkMetadata.size === trunkSize, 0x745 /* The size of the trunkMetadata must be the same as the trunk */);
|
|
291
|
-
this._events.emit("ancestryTrimmed", trimmedRevisions);
|
|
292
215
|
}
|
|
216
|
+
// Dropping the parent field removes (transitively) all references to the evicted commits so they can be garbage collected.
|
|
217
|
+
delete newTrunkBase.parent;
|
|
218
|
+
this.trunkBase = newTrunkBase;
|
|
219
|
+
this._events.emit("ancestryTrimmed", trimmedRevisions);
|
|
293
220
|
}
|
|
294
221
|
isEmpty() {
|
|
295
|
-
|
|
296
|
-
this.
|
|
297
|
-
|
|
298
|
-
|
|
222
|
+
for (const branch of this.sharedBranches.values()) {
|
|
223
|
+
if (!branch.isEmpty(this.trunkBase)) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return this.minimumSequenceNumber === minimumPossibleSequenceNumber;
|
|
299
228
|
}
|
|
300
229
|
getSummaryData() {
|
|
301
|
-
// The assert below is acceptable at present because summarization only ever occurs on a client with no
|
|
302
|
-
// local/in-flight changes.
|
|
303
|
-
// In the future we may wish to relax this constraint. For that to work, the current implementation of
|
|
304
|
-
// `EditManager` would have to be amended in one of two ways:
|
|
305
|
-
// A) Changes made by the local session should be represented by a branch in `EditManager.branches`.
|
|
306
|
-
// B) The contents of such a branch should be computed on demand based on the trunk.
|
|
307
|
-
// Note that option (A) would be a simple change to `addSequencedChanges` whereas (B) would likely require
|
|
308
|
-
// rebasing trunk changes over the inverse of trunk changes.
|
|
309
|
-
assert(this.localBranch.getHead() === this.trunk.getHead(), 0x428 /* Clients with local changes cannot be used to generate summaries */);
|
|
310
230
|
// Trimming the trunk before serializing ensures that the trunk data in the summary is as minimal as possible.
|
|
311
|
-
this.
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
sequenceNumber: metadata.sequenceId.sequenceNumber,
|
|
326
|
-
sessionId: metadata.sessionId,
|
|
327
|
-
};
|
|
328
|
-
if (metadata.sequenceId.indexInBatch !== undefined) {
|
|
329
|
-
commit.indexInBatch = metadata.sequenceId.indexInBatch;
|
|
231
|
+
this.trimHistory();
|
|
232
|
+
const minSeqNumberToSummarize = {
|
|
233
|
+
sequenceNumber: brand(this.minimumSequenceNumber + 1),
|
|
234
|
+
};
|
|
235
|
+
let minBaseSeqId = minSeqNumberToSummarize;
|
|
236
|
+
const mainBranch = this.getSharedBranch("main");
|
|
237
|
+
const branches = new Map();
|
|
238
|
+
for (const [branchId, branch] of this.sharedBranches) {
|
|
239
|
+
if (branchId !== "main") {
|
|
240
|
+
const branchSummary = branch.getSummaryData(minSeqNumberToSummarize, this.trunkBase.revision);
|
|
241
|
+
branches.set(branchId, branchSummary);
|
|
242
|
+
assert(branchSummary.base !== undefined, "Branch summary must have a base");
|
|
243
|
+
const baseSequenceId = mainBranch.getCommitSequenceId(branchSummary.base);
|
|
244
|
+
minBaseSeqId = minSequenceId(minBaseSeqId, baseSequenceId);
|
|
330
245
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const branchPath = [];
|
|
335
|
-
const ancestor = findCommonAncestor([branch.getHead(), branchPath], this.trunk.getHead()) ??
|
|
336
|
-
fail(0xad6 /* Expected branch to be based on trunk */);
|
|
337
|
-
const base = ancestor === this.trunkBase ? rootRevision : ancestor.revision;
|
|
338
|
-
return [
|
|
339
|
-
sessionId,
|
|
340
|
-
{
|
|
341
|
-
base,
|
|
342
|
-
commits: branchPath.map((c) => {
|
|
343
|
-
assert(c !== this.trunkBase, 0xa62 /* Serialized branch should not include the trunk base */);
|
|
344
|
-
const commit = {
|
|
345
|
-
change: c.change,
|
|
346
|
-
revision: c.revision,
|
|
347
|
-
sessionId,
|
|
348
|
-
};
|
|
349
|
-
return commit;
|
|
350
|
-
}),
|
|
351
|
-
},
|
|
352
|
-
];
|
|
353
|
-
}));
|
|
354
|
-
return { trunk, peerLocalBranches };
|
|
246
|
+
}
|
|
247
|
+
const mainSummary = mainBranch.getSummaryData(minBaseSeqId, this.trunkBase.revision);
|
|
248
|
+
return { main: mainSummary, branches, originator: this.localSessionId };
|
|
355
249
|
}
|
|
356
250
|
loadSummaryData(data) {
|
|
357
251
|
assert(this.isEmpty(), 0x68a /* Attempted to load from summary after edit manager was already mutated */);
|
|
@@ -359,53 +253,30 @@ export class EditManager {
|
|
|
359
253
|
// when hydrating the peer branches below
|
|
360
254
|
const trunkRevisionCache = new Map();
|
|
361
255
|
trunkRevisionCache.set(this.trunkBase.revision, this.trunkBase);
|
|
362
|
-
this.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
indexInBatch: c.indexInBatch,
|
|
370
|
-
};
|
|
371
|
-
const commit = mintCommit(base, c);
|
|
372
|
-
this.sequenceMap.set(sequenceId, commit);
|
|
373
|
-
this.trunkMetadata.set(c.revision, {
|
|
374
|
-
sequenceId,
|
|
375
|
-
sessionId: c.sessionId,
|
|
376
|
-
});
|
|
377
|
-
trunkRevisionCache.set(c.revision, commit);
|
|
378
|
-
return commit;
|
|
379
|
-
}, this.trunkBase));
|
|
380
|
-
this.localBranch.setHead(this.trunk.getHead());
|
|
381
|
-
for (const [sessionId, branch] of data.peerLocalBranches) {
|
|
382
|
-
const commit = trunkRevisionCache.get(branch.base) ??
|
|
383
|
-
fail(0xad7 /* Expected summary branch to be based off of a revision in the trunk */);
|
|
384
|
-
this.peerLocalBranches.set(sessionId, new SharedTreeBranch(branch.commits.reduce(mintCommit, commit), this.changeFamily, this.mintRevisionTag));
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
getCommitSequenceId(trunkCommitOrTrunkBase) {
|
|
388
|
-
const id = this.trunkMetadata.get(trunkCommitOrTrunkBase.revision)?.sequenceId;
|
|
389
|
-
if (id === undefined) {
|
|
390
|
-
assert(trunkCommitOrTrunkBase === this.trunkBase, 0xa63 /* Commit must be either be on the trunk or be the trunk base */);
|
|
391
|
-
return minimumPossibleSequenceId;
|
|
256
|
+
const mainBranch = this.sharedBranches.get("main") ?? fail("Main branch must exist");
|
|
257
|
+
mainBranch.loadSummaryData(data.main, trunkRevisionCache);
|
|
258
|
+
if (data.branches !== undefined) {
|
|
259
|
+
for (const [branchId, branchData] of data.branches) {
|
|
260
|
+
const branch = this.createSharedBranch(branchId, branchData.session, mainBranch, mainBranch.trunk.fork());
|
|
261
|
+
branch.loadSummaryData(branchData, trunkRevisionCache);
|
|
262
|
+
}
|
|
392
263
|
}
|
|
393
|
-
return id;
|
|
394
264
|
}
|
|
395
|
-
|
|
396
|
-
return this.
|
|
265
|
+
getTrunkHead(branchId) {
|
|
266
|
+
return this.getSharedBranch(branchId).trunk.getHead();
|
|
397
267
|
}
|
|
398
|
-
|
|
399
|
-
return
|
|
268
|
+
getTrunkChanges(branchId) {
|
|
269
|
+
return this.getTrunkCommits(branchId).map((c) => c.change);
|
|
400
270
|
}
|
|
401
|
-
|
|
402
|
-
return this.
|
|
271
|
+
getTrunkCommits(branchId) {
|
|
272
|
+
return getPathFromBase(this.getTrunkHead(branchId), this.trunkBase);
|
|
403
273
|
}
|
|
404
|
-
getLocalChanges() {
|
|
405
|
-
return this.getLocalCommits().map((c) => c.change);
|
|
274
|
+
getLocalChanges(branchId) {
|
|
275
|
+
return this.getLocalCommits(branchId).map((c) => c.change);
|
|
406
276
|
}
|
|
407
|
-
getLocalCommits() {
|
|
408
|
-
|
|
277
|
+
getLocalCommits(branchId) {
|
|
278
|
+
const branch = this.getSharedBranch(branchId);
|
|
279
|
+
return branch.getLocalCommits();
|
|
409
280
|
}
|
|
410
281
|
/**
|
|
411
282
|
* Gets the length of the longest branch maintained by this `EditManager`.
|
|
@@ -417,15 +288,36 @@ export class EditManager {
|
|
|
417
288
|
*/
|
|
418
289
|
getLongestBranchLength() {
|
|
419
290
|
let max = 0;
|
|
420
|
-
const
|
|
421
|
-
|
|
422
|
-
const branchPath = getPathFromBase(branch.getHead(), trunkHead);
|
|
423
|
-
if (branchPath.length > max) {
|
|
424
|
-
max = branchPath.length;
|
|
425
|
-
}
|
|
291
|
+
for (const branch of this.sharedBranches.values()) {
|
|
292
|
+
max = Math.max(max, branch.getLongestBranchLength());
|
|
426
293
|
}
|
|
427
|
-
|
|
428
|
-
|
|
294
|
+
return max;
|
|
295
|
+
}
|
|
296
|
+
sequenceBranchCreation(sessionId, referenceSequenceNumber, branchId) {
|
|
297
|
+
if (sessionId === this.localSessionId) {
|
|
298
|
+
assert(this.sharedBranches.has(branchId), "Expected branch to already exist");
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const mainBranch = this.getSharedBranch("main");
|
|
302
|
+
const branchTrunk = mainBranch.rebasePeer(sessionId, referenceSequenceNumber).fork();
|
|
303
|
+
const sharedBranch = this.createSharedBranch(branchId, sessionId, mainBranch, branchTrunk);
|
|
304
|
+
this.registerBranch(sharedBranch.localBranch);
|
|
305
|
+
onForkTransitive(sharedBranch.localBranch, (fork) => this.registerBranch(fork));
|
|
306
|
+
}
|
|
307
|
+
addBranch(branchId) {
|
|
308
|
+
const main = this.getSharedBranch("main") ?? fail("Main branch must exist");
|
|
309
|
+
this.createSharedBranch(branchId, this.localSessionId, main, this.getLocalBranch("main").fork());
|
|
310
|
+
}
|
|
311
|
+
removeBranch(branchId) {
|
|
312
|
+
assert(branchId !== "main", "Cannot remove main branch");
|
|
313
|
+
const hadBranch = this.sharedBranches.delete(branchId);
|
|
314
|
+
assert(hadBranch, "Expected branch to exist");
|
|
315
|
+
}
|
|
316
|
+
createSharedBranch(branchId, sessionId, parent, branch) {
|
|
317
|
+
const sharedBranch = new SharedBranch(parent, branch, branchId, sessionId, minimumPossibleSequenceId, this.changeFamily, this.mintRevisionTag, this._events, this.telemetryEventBatcher);
|
|
318
|
+
assert(!this.sharedBranches.has(branchId), "A branch with this ID already exists");
|
|
319
|
+
this.sharedBranches.set(branchId, sharedBranch);
|
|
320
|
+
return sharedBranch;
|
|
429
321
|
}
|
|
430
322
|
/* eslint-disable jsdoc/check-indentation */
|
|
431
323
|
/**
|
|
@@ -438,34 +330,118 @@ export class EditManager {
|
|
|
438
330
|
* - They are not interleaved with messages from other clients.
|
|
439
331
|
*/
|
|
440
332
|
/* eslint-enable jsdoc/check-indentation */
|
|
441
|
-
addSequencedChanges(newCommits, sessionId, sequenceNumber, referenceSequenceNumber) {
|
|
333
|
+
addSequencedChanges(newCommits, sessionId, sequenceNumber, referenceSequenceNumber, branchId = "main") {
|
|
442
334
|
assert(newCommits.length > 0, 0xad8 /* Expected at least one sequenced change */);
|
|
443
335
|
assert(sequenceNumber > this.minimumSequenceNumber, 0x713 /* Expected change sequence number to exceed the last known minimum sequence number */);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
336
|
+
const branch = this.getSharedBranch(branchId);
|
|
337
|
+
const onSequenceLocalCommit = (commit, sequenceId, previousSequenceId) => {
|
|
338
|
+
// Next, we need to update the sequence IDs that our local branches (user's branches, not peer branches) are associated with.
|
|
339
|
+
// In particular, if a local branch is based on the previous trunk head (the branch's first ancestor in the trunk is the commit that was the head before we pushed the new commit)
|
|
340
|
+
// and also branches off of the local branch (it has an ancestor that is part of the local branch), it needs to have its sequence number advanced to be that of the new trunk head.
|
|
341
|
+
// Intuitively, this makes sense because:
|
|
342
|
+
// 1. The trunk's head just advanced forward by some (sequence) amount.
|
|
343
|
+
// 2. The local branch is always rebased to be branching off of the head of the trunk (not literally in this case, because of the optimization, but in effect).
|
|
344
|
+
// 3. Therefore, the entire local branch just advanced forward by some (sequence) amount, and any commits downstream of it which track the sequence numbers of their base commits on the trunk should also advance.
|
|
345
|
+
// This update is not necessarily required for all local branches, since some may have fallen behind the local branch and are based on older trunk commits (such branches do not need updating).
|
|
346
|
+
const currentBranches = this.trunkBranches.get(previousSequenceId);
|
|
347
|
+
if (currentBranches !== undefined) {
|
|
348
|
+
const newBranches = getOrCreate(this.trunkBranches, sequenceId, () => new Set());
|
|
349
|
+
for (const forkedBranch of currentBranches) {
|
|
350
|
+
// Check every branch associated with the old sequence ID and advance it if it is based on the local branch (specifically, on the local branch as it was before we pushed its first commit to the trunk).
|
|
351
|
+
// We validate this by checking if the branch's head is a descendant of the local commit that we just pushed.
|
|
352
|
+
if (findAncestor(forkedBranch.getHead(), (c) => c === commit) !== undefined) {
|
|
353
|
+
newBranches.add(forkedBranch);
|
|
354
|
+
currentBranches.delete(forkedBranch);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// Clean up our trunk branches map by removing any empty sets.
|
|
358
|
+
if (currentBranches.size === 0) {
|
|
359
|
+
this.trunkBranches.delete(previousSequenceId);
|
|
360
|
+
}
|
|
361
|
+
if (newBranches.size === 0) {
|
|
362
|
+
this.trunkBranches.delete(sequenceId);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
453
365
|
};
|
|
454
|
-
const
|
|
366
|
+
const areLocalCommits = sessionId === this.localSessionId;
|
|
367
|
+
branch.addSequencedChanges(newCommits, sessionId, sequenceNumber, areLocalCommits, referenceSequenceNumber, onSequenceLocalCommit);
|
|
368
|
+
}
|
|
369
|
+
findLocalCommit(branchId, revision) {
|
|
370
|
+
const commits = [];
|
|
371
|
+
const commit = findAncestor([this.getSharedBranch(branchId).localBranch.getHead(), commits], (c) => c.revision === revision);
|
|
372
|
+
assert(commit !== undefined, 0x599 /* Expected local branch to contain revision */);
|
|
373
|
+
return [commit, commits];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Gets the path from the base of a branch to its head.
|
|
378
|
+
*/
|
|
379
|
+
function getPathFromBase(branchHead, baseBranchHead) {
|
|
380
|
+
const path = [];
|
|
381
|
+
assert(findCommonAncestor([branchHead, path], baseBranchHead) !== undefined, 0x573 /* Expected branches to be related */);
|
|
382
|
+
return path;
|
|
383
|
+
}
|
|
384
|
+
class SharedBranch {
|
|
385
|
+
constructor(parentBranch, trunk, id, sessionId, baseCommitSequenceId, changeFamily, mintRevisionTag, branchTrimmer, telemetryEventBatcher) {
|
|
386
|
+
this.parentBranch = parentBranch;
|
|
387
|
+
this.trunk = trunk;
|
|
388
|
+
this.id = id;
|
|
389
|
+
this.sessionId = sessionId;
|
|
390
|
+
this.changeFamily = changeFamily;
|
|
391
|
+
this.mintRevisionTag = mintRevisionTag;
|
|
392
|
+
/**
|
|
393
|
+
* Branches are maintained to represent the local change list that the issuing client had
|
|
394
|
+
* at the time of submitting the latest known edit on the branch.
|
|
395
|
+
* This means the head commit of each branch is always in its original (non-rebased) form.
|
|
396
|
+
*/
|
|
397
|
+
this.peerLocalBranches = new Map();
|
|
398
|
+
/**
|
|
399
|
+
* A map from a sequence id to the commit which has that sequence id.
|
|
400
|
+
* This also includes an entry for the {@link trunkBase} which always has the lowest key in the map.
|
|
401
|
+
*/
|
|
402
|
+
this.sequenceIdToCommit = new BTree(undefined, sequenceIdComparator);
|
|
403
|
+
/**
|
|
404
|
+
* The list of commits (from oldest to most recent) that are on the local branch but not on the trunk.
|
|
405
|
+
* When a local commit is sequenced, the first commit in this list shifted onto the tip of the trunk.
|
|
406
|
+
*/
|
|
407
|
+
this.localCommits = [];
|
|
408
|
+
/**
|
|
409
|
+
* Records extra data associated with sequenced commits.
|
|
410
|
+
* This does not include an entry for the {@link trunkBase}.
|
|
411
|
+
*/
|
|
412
|
+
this.commitMetadata = new Map();
|
|
413
|
+
this.localBranch = new SharedTreeBranch(this.trunk.getHead(), changeFamily, mintRevisionTag, branchTrimmer, telemetryEventBatcher);
|
|
414
|
+
this.sequenceIdToCommit.set(baseCommitSequenceId, this.trunk.getHead());
|
|
415
|
+
this.localBranch.events.on("afterChange", (event) => {
|
|
416
|
+
if (event.type === "append") {
|
|
417
|
+
for (const commit of event.newCommits) {
|
|
418
|
+
this.localCommits.push(commit);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
else {
|
|
422
|
+
this.localCommits.length = 0;
|
|
423
|
+
findCommonAncestor([this.localBranch.getHead(), this.localCommits], this.trunk.getHead());
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
addSequencedChanges(newCommits, sessionId, sequenceNumber, areLocalCommits, referenceSequenceNumber, onSequenceLocalCommit) {
|
|
428
|
+
assert(sequenceNumber >= // This is ">=", not ">" because changes in the same batch will have the same sequence number
|
|
429
|
+
(this.sequenceIdToCommit.maxKey()?.sequenceNumber ?? minimumPossibleSequenceNumber), 0xa64 /* Attempted to sequence change with an outdated sequence number */);
|
|
430
|
+
const batchSize = this.getBatchSize(sequenceNumber);
|
|
455
431
|
// The sequence id for the next commit to be processed in the bunch.
|
|
456
|
-
let nextSequenceId =
|
|
432
|
+
let nextSequenceId = batchSize === 0
|
|
457
433
|
? {
|
|
458
434
|
sequenceNumber,
|
|
459
435
|
}
|
|
460
436
|
: {
|
|
461
437
|
sequenceNumber,
|
|
462
|
-
indexInBatch:
|
|
438
|
+
indexInBatch: batchSize,
|
|
463
439
|
};
|
|
464
440
|
// Local changes, i.e., changes from this client are applied by fast forwarding the local branch commit onto
|
|
465
441
|
// the trunk.
|
|
466
|
-
if (
|
|
442
|
+
if (areLocalCommits) {
|
|
467
443
|
for (const _ of newCommits) {
|
|
468
|
-
this.
|
|
444
|
+
this.sequenceLocalCommit(nextSequenceId, sessionId, onSequenceLocalCommit);
|
|
469
445
|
nextSequenceId = getNextSequenceId(nextSequenceId);
|
|
470
446
|
}
|
|
471
447
|
return;
|
|
@@ -475,9 +451,7 @@ export class EditManager {
|
|
|
475
451
|
// Get the revision that the remote change is based on and rebase that peer local branch over the part of the
|
|
476
452
|
// trunk up to the base revision. This will be a no-op if the sending client has not advanced since the last
|
|
477
453
|
// time we received an edit from it
|
|
478
|
-
const
|
|
479
|
-
const peerLocalBranch = getOrCreate(this.peerLocalBranches, sessionId, () => new SharedTreeBranch(baseRevisionInTrunk, this.changeFamily, this.mintRevisionTag));
|
|
480
|
-
peerLocalBranch.rebaseOnto(this.trunk, baseRevisionInTrunk);
|
|
454
|
+
const peerLocalBranch = this.rebasePeer(sessionId, referenceSequenceNumber);
|
|
481
455
|
// Step 2 - Append the changes to the peer branch and rebase the changes to the tip of the trunk.
|
|
482
456
|
if (peerLocalBranch.getHead() === this.trunk.getHead()) {
|
|
483
457
|
// If the peer local branch is fully caught up and empty (no changes relative to the trunk) after being
|
|
@@ -498,8 +472,8 @@ export class EditManager {
|
|
|
498
472
|
// If the merge resulted in any changes to the trunk, update the sequence map and trunk metadata
|
|
499
473
|
// with the rebased commits.
|
|
500
474
|
for (const sourceCommit of result.sourceCommits) {
|
|
501
|
-
this.
|
|
502
|
-
this.
|
|
475
|
+
this.sequenceIdToCommit.set(nextSequenceId, sourceCommit);
|
|
476
|
+
this.commitMetadata.set(sourceCommit.revision, {
|
|
503
477
|
sequenceId: nextSequenceId,
|
|
504
478
|
sessionId,
|
|
505
479
|
});
|
|
@@ -510,21 +484,85 @@ export class EditManager {
|
|
|
510
484
|
// Step 3 - Rebase the local branch over the updated trunk.
|
|
511
485
|
this.localBranch.rebaseOnto(this.trunk);
|
|
512
486
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return [commit, commits];
|
|
487
|
+
isEmpty(baseCommit) {
|
|
488
|
+
return (this.trunk.getHead() === baseCommit &&
|
|
489
|
+
this.peerLocalBranches.size === 0 &&
|
|
490
|
+
this.localBranch.getHead() === this.trunk.getHead());
|
|
518
491
|
}
|
|
519
|
-
|
|
520
|
-
const
|
|
521
|
-
this.
|
|
492
|
+
rebasePeer(sessionId, referenceSequenceNumber) {
|
|
493
|
+
const [, baseRevisionInTrunk] = this.getClosestTrunkCommit(referenceSequenceNumber);
|
|
494
|
+
const peerLocalBranch = getOrCreate(this.peerLocalBranches, sessionId, () => new SharedTreeBranch(baseRevisionInTrunk, this.changeFamily, this.mintRevisionTag));
|
|
495
|
+
peerLocalBranch.rebaseOnto(this.trunk, baseRevisionInTrunk);
|
|
496
|
+
return peerLocalBranch;
|
|
522
497
|
}
|
|
523
|
-
|
|
524
|
-
this.
|
|
498
|
+
getPeerBranchOrTrunk(sessionId) {
|
|
499
|
+
return this.peerLocalBranches.get(sessionId) ?? this.trunk;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Gets the length of the longest branch maintained by this `SharedBranch`.
|
|
503
|
+
* This may be the length of a peer branch or the local branch.
|
|
504
|
+
*
|
|
505
|
+
* @remarks
|
|
506
|
+
* The length is counted from the lowest common ancestor with the trunk such that a fully sequenced branch would
|
|
507
|
+
* have length zero.
|
|
508
|
+
*/
|
|
509
|
+
getLongestBranchLength() {
|
|
510
|
+
let max = 0;
|
|
525
511
|
const trunkHead = this.trunk.getHead();
|
|
526
|
-
this.
|
|
527
|
-
|
|
512
|
+
for (const branch of this.peerLocalBranches.values()) {
|
|
513
|
+
const branchPath = getPathFromBase(branch.getHead(), trunkHead);
|
|
514
|
+
if (branchPath.length > max) {
|
|
515
|
+
max = branchPath.length;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const localPath = getPathFromBase(this.localBranch.getHead(), trunkHead);
|
|
519
|
+
return Math.max(max, localPath.length);
|
|
520
|
+
}
|
|
521
|
+
trimHistory(newBase, sequenceId) {
|
|
522
|
+
this.rebasePeers(newBase);
|
|
523
|
+
this.sequenceIdToCommit.editRange(minimumPossibleSequenceId, sequenceId, true, (s, commit) => {
|
|
524
|
+
// Cleanup look-aside data for each evicted commit
|
|
525
|
+
this.commitMetadata.delete(commit.revision);
|
|
526
|
+
// Delete all evicted commits from `sequenceMap` except for the latest one, which is the new `trunkBase`
|
|
527
|
+
if (equalSequenceIds(s, sequenceId)) {
|
|
528
|
+
assert(commit === newBase, 0x729 /* Expected last evicted commit to be new trunk base */);
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
return { delete: true };
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
const trunkSize = getPathFromBase(this.trunk.getHead(), newBase).length;
|
|
535
|
+
assert(this.sequenceIdToCommit.size === trunkSize + 1, 0x744 /* The size of the sequenceMap must have one element more than the trunk */);
|
|
536
|
+
assert(this.commitMetadata.size === trunkSize, 0x745 /* The size of the trunkMetadata must be the same as the trunk */);
|
|
537
|
+
}
|
|
538
|
+
rebasePeers(commit) {
|
|
539
|
+
for (const [, branch] of this.peerLocalBranches) {
|
|
540
|
+
branch.rebaseOnto(this.trunk, commit);
|
|
541
|
+
}
|
|
542
|
+
// The metadata for new trunk base revision needs to be deleted before modifying it.
|
|
543
|
+
this.commitMetadata.delete(commit.revision);
|
|
544
|
+
}
|
|
545
|
+
getLocalCommits() {
|
|
546
|
+
return this.localCommits;
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* Promote the oldest un-sequenced commit on the local branch to the head of the trunk.
|
|
550
|
+
* @param sequenceId - The sequence id of the new trunk commit
|
|
551
|
+
* @remarks This method is a performance optimization for the scenario where this client receives its own change back after sequencing.
|
|
552
|
+
* The normal (not optimized) process in this case would be to apply the new sequenced commit to the trunk and then rebase the local branch over the trunk.
|
|
553
|
+
* The first commit will be "the same" (as in, it will have the same revision) as the commit that was just sequenced, so the rebase will be a no-op.
|
|
554
|
+
* Because the rebase is a no-op, we can skip it entirely and simply remove the commit from the local branch and append it to the trunk.
|
|
555
|
+
* Avoiding the overhead of the rebase process, even when it's a no-op, has real measured performance benefits and is worth the added complexity here.
|
|
556
|
+
*/
|
|
557
|
+
sequenceLocalCommit(sequenceId, sessionId, onSequenceLocalCommit) {
|
|
558
|
+
// First, push the local commit to the trunk.
|
|
559
|
+
// We are mutating our `localCommits` cache here,but there is no need to actually change the `localBranch` itself because it will simply catch up later if/when it next rebases.
|
|
560
|
+
const firstLocalCommit = this.localCommits.shift();
|
|
561
|
+
assert(firstLocalCommit !== undefined, 0x6b5 /* Received a sequenced change from the local session despite having no local changes */);
|
|
562
|
+
const prevSequenceId = this.getCommitSequenceId(this.trunk.getHead().revision);
|
|
563
|
+
this.pushGraphCommitToTrunk(sequenceId, firstLocalCommit, sessionId);
|
|
564
|
+
onSequenceLocalCommit(firstLocalCommit, sequenceId, prevSequenceId);
|
|
565
|
+
return firstLocalCommit;
|
|
528
566
|
}
|
|
529
567
|
getClosestTrunkCommit(searchBy) {
|
|
530
568
|
const sequenceId = typeof searchBy === "number"
|
|
@@ -536,26 +574,135 @@ export class EditManager {
|
|
|
536
574
|
indexInBatch: Number.POSITIVE_INFINITY,
|
|
537
575
|
}
|
|
538
576
|
: searchBy;
|
|
539
|
-
const commit = this.
|
|
577
|
+
const commit = this.sequenceIdToCommit.getPairOrNextLower(sequenceId);
|
|
540
578
|
assert(commit !== undefined, 0x746 /* sequence id has been evicted */);
|
|
541
579
|
return commit;
|
|
542
580
|
}
|
|
543
|
-
|
|
581
|
+
pushGraphCommitToTrunk(sequenceId, graphCommit, sessionId) {
|
|
582
|
+
this.trunk.setHead(graphCommit);
|
|
583
|
+
this.registerSequencedCommit(sequenceId, sessionId, graphCommit);
|
|
584
|
+
}
|
|
585
|
+
pushCommitToTrunk(sequenceId, commit) {
|
|
586
|
+
const mintedCommit = mintCommit(this.trunk.getHead(), commit);
|
|
587
|
+
this.pushGraphCommitToTrunk(sequenceId, mintedCommit, commit.sessionId);
|
|
588
|
+
}
|
|
589
|
+
registerSequencedCommit(sequenceId, sessionId, commit) {
|
|
590
|
+
this.sequenceIdToCommit.set(sequenceId, commit);
|
|
591
|
+
this.commitMetadata.set(commit.revision, { sequenceId, sessionId });
|
|
592
|
+
}
|
|
593
|
+
getCommitSequenceId(commitRevision) {
|
|
594
|
+
const id = this.commitMetadata.get(commitRevision)?.sequenceId;
|
|
595
|
+
if (id === undefined) {
|
|
596
|
+
return minimumPossibleSequenceId;
|
|
597
|
+
}
|
|
598
|
+
return id;
|
|
599
|
+
}
|
|
600
|
+
// TODO: Document that this is to handle receiving separate commits with the same sequence ID,
|
|
601
|
+
// as a batch of changes are not guaranteed to be processed as one bunch.
|
|
602
|
+
getBatchSize(sequenceNumber) {
|
|
544
603
|
const startSequenceId = {
|
|
545
604
|
sequenceNumber,
|
|
546
605
|
};
|
|
547
606
|
const endSequenceId = {
|
|
548
607
|
sequenceNumber: brand(sequenceNumber + 1),
|
|
549
608
|
};
|
|
550
|
-
return this.
|
|
609
|
+
return this.sequenceIdToCommit.getRange(startSequenceId, endSequenceId, false).length;
|
|
610
|
+
}
|
|
611
|
+
getSummaryData(minSeqNumberToSummarize, trunkBaseRevision) {
|
|
612
|
+
// The assert below is acceptable at present because summarization only ever occurs on a client with no
|
|
613
|
+
// local/in-flight changes.
|
|
614
|
+
// In the future we may wish to relax this constraint. For that to work, the current implementation of
|
|
615
|
+
// `EditManager` would have to be amended in one of two ways:
|
|
616
|
+
// A) Changes made by the local session should be represented by a branch in `EditManager.branches`.
|
|
617
|
+
// B) The contents of such a branch should be computed on demand based on the trunk.
|
|
618
|
+
// Note that option (A) would be a simple change to `addSequencedChanges` whereas (B) would likely require
|
|
619
|
+
// rebasing trunk changes over the inverse of trunk changes.
|
|
620
|
+
assert(this.localBranch.getHead() === this.trunk.getHead(), "Clients with local changes cannot be used to generate summaries");
|
|
621
|
+
let parentHead;
|
|
622
|
+
if (this.parentBranch === undefined) {
|
|
623
|
+
const oldestCommitInCollabWindow = this.getClosestTrunkCommit(minSeqNumberToSummarize)[1];
|
|
624
|
+
// Path construction is exclusive, so we need to use the parent of the oldest commit in the window if it exists
|
|
625
|
+
parentHead = oldestCommitInCollabWindow.parent ?? oldestCommitInCollabWindow;
|
|
626
|
+
}
|
|
627
|
+
else {
|
|
628
|
+
parentHead = this.parentBranch.trunk.getHead();
|
|
629
|
+
}
|
|
630
|
+
const childBranchTrunkCommits = [];
|
|
631
|
+
const forkPointFromMainTrunk = findCommonAncestor([this.trunk.getHead(), childBranchTrunkCommits], parentHead);
|
|
632
|
+
assert(forkPointFromMainTrunk !== undefined, "Expected child branch to be based on main branch");
|
|
633
|
+
const trunk = childBranchTrunkCommits.map((c) => {
|
|
634
|
+
const metadata = this.commitMetadata.get(c.revision) ??
|
|
635
|
+
fail(0xad5 /* Expected metadata for trunk commit */);
|
|
636
|
+
const commit = {
|
|
637
|
+
change: c.change,
|
|
638
|
+
revision: c.revision,
|
|
639
|
+
sequenceNumber: metadata.sequenceId.sequenceNumber,
|
|
640
|
+
sessionId: metadata.sessionId,
|
|
641
|
+
};
|
|
642
|
+
if (metadata.sequenceId.indexInBatch !== undefined) {
|
|
643
|
+
commit.indexInBatch = metadata.sequenceId.indexInBatch;
|
|
644
|
+
}
|
|
645
|
+
return commit;
|
|
646
|
+
});
|
|
647
|
+
const peerLocalBranches = new Map(mapIterable(this.peerLocalBranches.entries(), ([sessionId, branch]) => {
|
|
648
|
+
const branchPath = [];
|
|
649
|
+
const ancestor = findCommonAncestor([branch.getHead(), branchPath], this.trunk.getHead()) ??
|
|
650
|
+
fail(0xad6 /* Expected branch to be based on trunk */);
|
|
651
|
+
const base = ancestor.revision === trunkBaseRevision ? rootRevision : ancestor.revision;
|
|
652
|
+
return [
|
|
653
|
+
sessionId,
|
|
654
|
+
{
|
|
655
|
+
base,
|
|
656
|
+
commits: branchPath.map((c) => {
|
|
657
|
+
const commit = {
|
|
658
|
+
change: c.change,
|
|
659
|
+
revision: c.revision,
|
|
660
|
+
sessionId,
|
|
661
|
+
};
|
|
662
|
+
return commit;
|
|
663
|
+
}),
|
|
664
|
+
},
|
|
665
|
+
];
|
|
666
|
+
}));
|
|
667
|
+
const trunkBase = this.parentBranch === undefined ? undefined : forkPointFromMainTrunk.revision;
|
|
668
|
+
return { trunk, peerLocalBranches, base: trunkBase, id: this.id, session: this.sessionId };
|
|
669
|
+
}
|
|
670
|
+
loadSummaryData(data, trunkRevisionCache) {
|
|
671
|
+
assert((this.parentBranch === undefined) === (data.base === undefined), "Expected branch base to match presence of parent branch");
|
|
672
|
+
const parentTrunkBase = trunkRevisionCache.get(data.base ?? rootRevision) ??
|
|
673
|
+
fail("Expected base revision to be in trunk cache");
|
|
674
|
+
this.trunk.setHead(data.trunk.reduce((base, c) => {
|
|
675
|
+
const sequenceId = c.indexInBatch === undefined
|
|
676
|
+
? {
|
|
677
|
+
sequenceNumber: c.sequenceNumber,
|
|
678
|
+
}
|
|
679
|
+
: {
|
|
680
|
+
sequenceNumber: c.sequenceNumber,
|
|
681
|
+
indexInBatch: c.indexInBatch,
|
|
682
|
+
};
|
|
683
|
+
const commit = mintCommit(base, c);
|
|
684
|
+
this.sequenceIdToCommit.set(sequenceId, commit);
|
|
685
|
+
this.commitMetadata.set(c.revision, {
|
|
686
|
+
sequenceId,
|
|
687
|
+
sessionId: c.sessionId,
|
|
688
|
+
});
|
|
689
|
+
trunkRevisionCache.set(c.revision, commit);
|
|
690
|
+
return commit;
|
|
691
|
+
}, parentTrunkBase));
|
|
692
|
+
this.localBranch.setHead(this.trunk.getHead());
|
|
693
|
+
for (const [sessionId, branch] of data.peerLocalBranches) {
|
|
694
|
+
const commit = trunkRevisionCache.get(branch.base) ??
|
|
695
|
+
fail(0xad7 /* Expected summary branch to be based off of a revision in the trunk */);
|
|
696
|
+
this.peerLocalBranches.set(sessionId, new SharedTreeBranch(branch.commits.reduce(mintCommit, commit), this.changeFamily, this.mintRevisionTag));
|
|
697
|
+
}
|
|
551
698
|
}
|
|
552
699
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
700
|
+
// Returns the sequence id for the next commit to be processed in the bunch. Since all the commits have the
|
|
701
|
+
// same sequence number, only the index in the batch needs to be incremented.
|
|
702
|
+
function getNextSequenceId(sequenceId) {
|
|
703
|
+
return {
|
|
704
|
+
sequenceNumber: sequenceId.sequenceNumber,
|
|
705
|
+
indexInBatch: (sequenceId.indexInBatch ?? 0) + 1,
|
|
706
|
+
};
|
|
560
707
|
}
|
|
561
708
|
//# sourceMappingURL=editManager.js.map
|