@ibgib/vcs-gib 0.0.18 → 0.0.21
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/dist/AUTO-GENERATED-version.d.mts +1 -1
- package/dist/AUTO-GENERATED-version.mjs +1 -1
- package/dist/bootstrap/node-bootstrap.d.mts.map +1 -1
- package/dist/bootstrap/node-bootstrap.mjs +2 -2
- package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
- package/dist/cli/commands/branch-cmd.d.mts.map +1 -1
- package/dist/cli/commands/branch-cmd.mjs.map +1 -1
- package/dist/cli/commands/merge-cmd.d.mts.map +1 -1
- package/dist/cli/commands/merge-cmd.mjs +1 -1
- package/dist/cli/commands/merge-cmd.mjs.map +1 -1
- package/dist/engine/item/item-helper.d.mts +1 -0
- package/dist/engine/item/item-helper.d.mts.map +1 -1
- package/dist/engine/item/item-helper.mjs +13 -3
- package/dist/engine/item/item-helper.mjs.map +1 -1
- package/dist/engine/item/item-types.d.mts +1 -0
- package/dist/engine/item/item-types.d.mts.map +1 -1
- package/dist/engine/merge/b2tfs-3way-merge-strategy.d.mts +12 -2
- package/dist/engine/merge/b2tfs-3way-merge-strategy.d.mts.map +1 -1
- package/dist/engine/merge/b2tfs-3way-merge-strategy.mjs +384 -236
- package/dist/engine/merge/b2tfs-3way-merge-strategy.mjs.map +1 -1
- package/dist/engine/merge/b2tfs-3way-merge-types.d.mts +41 -0
- package/dist/engine/merge/b2tfs-3way-merge-types.d.mts.map +1 -0
- package/dist/engine/merge/b2tfs-3way-merge-types.mjs +2 -0
- package/dist/engine/merge/b2tfs-3way-merge-types.mjs.map +1 -0
- package/package.json +5 -5
- package/src/AUTO-GENERATED-version.mts +1 -1
- package/src/bootstrap/node-bootstrap.mts +4 -3
- package/src/cli/commands/branch-checkout-cmd.respec.log +111 -0
- package/src/cli/commands/branch-cmd.mts +2 -4
- package/src/cli/commands/merge-cmd.mts +2 -6
- package/src/engine/item/item-helper.mts +15 -9
- package/src/engine/item/item-types.mts +2 -1
- package/src/engine/merge/b2tfs-3way-merge-strategy.mts +388 -261
- package/src/engine/merge/b2tfs-3way-merge-strategy.respec.log +39 -0
- package/src/engine/merge/{b2tfs-merge-strategy.respec.mts → b2tfs-3way-merge-strategy.respec.mts} +16 -13
- package/src/engine/merge/b2tfs-3way-merge-types.mts +42 -0
- package/tsconfig.json +3 -2
- package/tsconfig.test.json +10 -0
- package/tsconfig.test.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/assumptions.respec.d.mts +0 -2
- package/dist/assumptions.respec.d.mts.map +0 -1
- package/dist/assumptions.respec.mjs +0 -41
- package/dist/assumptions.respec.mjs.map +0 -1
- package/dist/bootstrap/node-bootstrap.respec.d.mts +0 -7
- package/dist/bootstrap/node-bootstrap.respec.d.mts.map +0 -1
- package/dist/bootstrap/node-bootstrap.respec.mjs +0 -28
- package/dist/bootstrap/node-bootstrap.respec.mjs.map +0 -1
- package/dist/cli/cli-arg-parser.respec.d.mts +0 -7
- package/dist/cli/cli-arg-parser.respec.d.mts.map +0 -1
- package/dist/cli/cli-arg-parser.respec.mjs +0 -35
- package/dist/cli/cli-arg-parser.respec.mjs.map +0 -1
- package/dist/cli/cli-e2e.respec.d.mts +0 -8
- package/dist/cli/cli-e2e.respec.d.mts.map +0 -1
- package/dist/cli/cli-e2e.respec.mjs +0 -263
- package/dist/cli/cli-e2e.respec.mjs.map +0 -1
- package/dist/cli/commands/branch-checkout-cmd.respec.d.mts +0 -7
- package/dist/cli/commands/branch-checkout-cmd.respec.d.mts.map +0 -1
- package/dist/cli/commands/branch-checkout-cmd.respec.mjs +0 -452
- package/dist/cli/commands/branch-checkout-cmd.respec.mjs.map +0 -1
- package/dist/cli/commands/commit-log-cmd.respec.d.mts +0 -7
- package/dist/cli/commands/commit-log-cmd.respec.d.mts.map +0 -1
- package/dist/cli/commands/commit-log-cmd.respec.mjs +0 -251
- package/dist/cli/commands/commit-log-cmd.respec.mjs.map +0 -1
- package/dist/cli/commands/init-cmd.respec.d.mts +0 -7
- package/dist/cli/commands/init-cmd.respec.d.mts.map +0 -1
- package/dist/cli/commands/init-cmd.respec.mjs +0 -40
- package/dist/cli/commands/init-cmd.respec.mjs.map +0 -1
- package/dist/cli/commands/reset-restore-cmd.respec.d.mts +0 -7
- package/dist/cli/commands/reset-restore-cmd.respec.d.mts.map +0 -1
- package/dist/cli/commands/reset-restore-cmd.respec.mjs +0 -185
- package/dist/cli/commands/reset-restore-cmd.respec.mjs.map +0 -1
- package/dist/cli/commands/status-add-cmd.respec.d.mts +0 -7
- package/dist/cli/commands/status-add-cmd.respec.d.mts.map +0 -1
- package/dist/cli/commands/status-add-cmd.respec.mjs +0 -239
- package/dist/cli/commands/status-add-cmd.respec.mjs.map +0 -1
- package/dist/engine/branch/branch-space.respec.d.mts +0 -8
- package/dist/engine/branch/branch-space.respec.d.mts.map +0 -1
- package/dist/engine/branch/branch-space.respec.mjs +0 -143
- package/dist/engine/branch/branch-space.respec.mjs.map +0 -1
- package/dist/engine/diff/line-diff-helper.respec.d.mts +0 -7
- package/dist/engine/diff/line-diff-helper.respec.d.mts.map +0 -1
- package/dist/engine/diff/line-diff-helper.respec.mjs +0 -66
- package/dist/engine/diff/line-diff-helper.respec.mjs.map +0 -1
- package/dist/engine/filter/glob-helper.respec.d.mts +0 -7
- package/dist/engine/filter/glob-helper.respec.d.mts.map +0 -1
- package/dist/engine/filter/glob-helper.respec.mjs +0 -78
- package/dist/engine/filter/glob-helper.respec.mjs.map +0 -1
- package/dist/engine/item/item.respec.d.mts +0 -7
- package/dist/engine/item/item.respec.d.mts.map +0 -1
- package/dist/engine/item/item.respec.mjs +0 -75
- package/dist/engine/item/item.respec.mjs.map +0 -1
- package/dist/engine/merge/b2tfs-merge-strategy.respec.d.mts +0 -7
- package/dist/engine/merge/b2tfs-merge-strategy.respec.d.mts.map +0 -1
- package/dist/engine/merge/b2tfs-merge-strategy.respec.mjs +0 -335
- package/dist/engine/merge/b2tfs-merge-strategy.respec.mjs.map +0 -1
- package/dist/vcs-gib.respec.d.mts +0 -8
- package/dist/vcs-gib.respec.d.mts.map +0 -1
- package/dist/vcs-gib.respec.mjs +0 -82
- package/dist/vcs-gib.respec.mjs.map +0 -1
|
@@ -9,17 +9,17 @@ import { getGib } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
|
|
|
9
9
|
import { rel8 } from '@ibgib/ts-gib/dist/V1/transforms/rel8.mjs';
|
|
10
10
|
import { GraftMergeStrategyBase_V1 } from '@ibgib/core-gib/dist/sync/graft-info/graft-merge-strategy-base-v1.mjs';
|
|
11
11
|
import { getFromSpace, persistTransformResult, registerNewIbGib, putInSpace } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
|
|
12
|
-
import { getBinIb, getIbGibsFromCache_fallbackToSpaces
|
|
13
|
-
import { applyTransforms, getUniqueDnas } from '@ibgib/core-gib/dist/witness/space/reconciliation-space/reconciliation-space-helper.mjs';
|
|
12
|
+
import { getBinIb, getIbGibsFromCache_fallbackToSpaces } from '@ibgib/core-gib/dist/common/other/ibgib-helper.mjs';
|
|
14
13
|
import { createGraftInfo } from '@ibgib/core-gib/dist/sync/graft-info/graft-info-helpers.mjs';
|
|
15
14
|
import { GRAFT_INFO_REL8N_NAME } from '@ibgib/core-gib/dist/sync/graft-info/graft-info-constants.mjs';
|
|
16
15
|
import { SyncConflictStrategy } from '@ibgib/core-gib/dist/sync/sync-constants.mjs';
|
|
17
16
|
import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
|
|
18
17
|
import { isBinaryBuffer, decodeToLines, computeLineLcsDiff } from '../diff/line-diff-helper.mjs';
|
|
19
|
-
import { B2TFS_CHILD_ITEM_REL8N_NAME, BINARY_REL8N_NAME } from '../item/item-types.mjs';
|
|
20
|
-
import { evolveB2tFSItemIbGib } from '../item/item-helper.mjs';
|
|
18
|
+
import { B2TFS_CHILD_ITEM_REL8N_NAME, BINARY_REL8N_NAME, B2tFSType } from '../item/item-types.mjs';
|
|
19
|
+
import { evolveB2tFSItemIbGib, isB2tFSItemIbGib } from '../item/item-helper.mjs';
|
|
21
20
|
const lcFile = `[b2tfs-3way-merge-strategy]`;
|
|
22
|
-
const logalot = GLOBAL_LOG_A_LOT;
|
|
21
|
+
const logalot = GLOBAL_LOG_A_LOT || true;
|
|
22
|
+
const mergeDiag = `[MERGE DIAGNOSTIC]`;
|
|
23
23
|
/**
|
|
24
24
|
* Performs 3-way line diff merging across LCA, Base, and Orphan text lines.
|
|
25
25
|
* Inserts Git conflict markers (`<<<<<<< HEAD`, `=======`, `>>>>>>>`) when overlapping
|
|
@@ -117,33 +117,65 @@ export function perform3WayTextLineMerge({ textLCA, textBase, textOrphan, }) {
|
|
|
117
117
|
export class B2tFS3WayGraftStrategy extends GraftMergeStrategyBase_V1 {
|
|
118
118
|
strategyId = 'B2tFS3WayGraftStrategy';
|
|
119
119
|
lc = '[B2tFS3WayGraftStrategy]';
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Returns true only if the graft context has two tips that are text-based file b2tfs item ibgibs.
|
|
122
|
+
*
|
|
123
|
+
* ## notes
|
|
124
|
+
*
|
|
125
|
+
* atow (08/12/2026) implementation is guantlet style: if cannot graft, return early
|
|
126
|
+
*
|
|
127
|
+
* @param context info about the divergent timelines {@link GraftContext}
|
|
128
|
+
*
|
|
129
|
+
* @returns true if it's a text file item ibgib, else false
|
|
130
|
+
*/
|
|
129
131
|
async canGraft(context) {
|
|
130
132
|
const lc = `${this.lc}[${this.canGraft.name}]`;
|
|
131
133
|
try {
|
|
132
134
|
const { conflictStrategy, timelineAddrsA, timelineAddrsB, ibGibReadCache, space } = context;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
// todo: refactor conflict strategy to be more generic: 'graft' | 'abort' | maybe something else.
|
|
136
|
+
const hasRelevantStrategy = conflictStrategy === SyncConflictStrategy.optimisticWithLCS || conflictStrategy === 'b2tfs3WayMerge';
|
|
137
|
+
if (!hasRelevantStrategy) {
|
|
138
|
+
// immediately return false because we are not the chosen strategy.
|
|
139
|
+
// todo: after refactor, really this should be out of the hands of the implementation and we should have a discriminator as part of the strategy interface. So the graft strategy pipeline executor can just check that first, and then if multiple found, it will delegate to this `canGraft` method.
|
|
140
|
+
return false; /* <<<< returns early */
|
|
135
141
|
}
|
|
136
142
|
const tipAddrA = timelineAddrsA.at(-1);
|
|
137
143
|
const tipAddrB = timelineAddrsB.at(-1);
|
|
138
144
|
if (!tipAddrA || !tipAddrB) {
|
|
139
|
-
|
|
145
|
+
if (logalot) {
|
|
146
|
+
console.log(`${lc} we don't have two tip addrs? how was a graft decided upon? (I: b20b6de462c35e0e74360cc8d317f126)`);
|
|
147
|
+
}
|
|
148
|
+
return false; /* <<<< returns early */
|
|
140
149
|
}
|
|
141
150
|
const [tipA, tipB] = await getIbGibsFromCache_fallbackToSpaces({
|
|
142
151
|
addrs: [tipAddrA, tipAddrB],
|
|
143
152
|
readCache_graph: ibGibReadCache,
|
|
144
153
|
space,
|
|
145
154
|
});
|
|
146
|
-
|
|
155
|
+
if (!tipA) {
|
|
156
|
+
throw new Error(`(UNEXPECTED) tipA falsy? couldn't get tipA? should have been available to us in the temp space or cache.(E: 752101026888140f074614e893531826)`);
|
|
157
|
+
}
|
|
158
|
+
if (!tipB) {
|
|
159
|
+
throw new Error(`(UNEXPECTED) tipB falsy? couldn't get tipB? should have been available to us in the temp space or cache. (E: d4d4a876cad8c7869830d33832bfde26)`);
|
|
160
|
+
}
|
|
161
|
+
const bothTipsAreB2tFSNodes = isB2tFSItemIbGib(tipA) && isB2tFSItemIbGib(tipB);
|
|
162
|
+
if (!bothTipsAreB2tFSNodes) {
|
|
163
|
+
// at this point, we're returning false. But I'm being extra defensive since this algorithm is so difficult to implement. So throw if somehow only one is a b2tfs item
|
|
164
|
+
if (isB2tFSItemIbGib(tipA) || isB2tFSItemIbGib(tipB)) {
|
|
165
|
+
console.error(`${lc}${mergeDiag} (UNEXPECTED)(NOT THROWN) only tipA or tipB but not both are b2tfs items? (E: cacb38796da881268898e9d1af245826)`);
|
|
166
|
+
}
|
|
167
|
+
return false; /* <<<< returns early */
|
|
168
|
+
}
|
|
169
|
+
if (tipA.data.fsType !== tipB.data.fsType) {
|
|
170
|
+
throw new Error(`(UNEXPECTED) tipA.data.fsType (${tipA.data.fsType}) !== tipB.data.fsType (${tipB.data.fsType})? both tips are expected to be the same B2tFSType. (E: c01c1885ac738f679813117852c48426)`);
|
|
171
|
+
}
|
|
172
|
+
// only do files. folders can use the replay dna strategy.
|
|
173
|
+
const isFile = tipA.data.fsType === B2tFSType.file;
|
|
174
|
+
if (!isFile) {
|
|
175
|
+
return false; /* <<<< returns early */
|
|
176
|
+
}
|
|
177
|
+
// passed gauntlet, we have a b2tfs file item that we can merge
|
|
178
|
+
return true;
|
|
147
179
|
}
|
|
148
180
|
catch (error) {
|
|
149
181
|
console.error(`${lc} ${extractErrorMsg(error)} (E: 8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e)`);
|
|
@@ -186,128 +218,309 @@ export class B2tFS3WayGraftStrategy extends GraftMergeStrategyBase_V1 {
|
|
|
186
218
|
const baseBranchAddrs = baseBranch.map(x => getIbGibAddr({ ibGib: x }));
|
|
187
219
|
const orphanTipAddr = getIbGibAddr({ ibGib: orphanTip });
|
|
188
220
|
const orphanBranchAddrs = orphanBranch.map(x => getIbGibAddr({ ibGib: x }));
|
|
221
|
+
if (logalot) {
|
|
222
|
+
console.log(`${lc} baseBranchAddrs:\n${baseBranchAddrs.join('\n')}\n(I: 2cad420d7bc822f798b8a8785f1f8c26)`);
|
|
223
|
+
}
|
|
224
|
+
if (logalot) {
|
|
225
|
+
console.log(`${lc} orphanBranchAddrs:\n${orphanBranchAddrs.join('\n')}\n(I: cc86489d6737e2aced42b585cba13526)`);
|
|
226
|
+
}
|
|
189
227
|
// 3. Replay orphan branch transforms onto base tip
|
|
190
228
|
const [latestCommonFrameIbGib] = await getIbGibsFromCache_fallbackToSpaces({
|
|
191
229
|
addrs: [latestCommonFrameAddr],
|
|
192
230
|
space,
|
|
193
231
|
});
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
232
|
+
// It is non-trivial and not at all obvious, but the following approach is WRONG!!
|
|
233
|
+
//
|
|
234
|
+
// This is not a generic timeline, rather, this is a timeline that
|
|
235
|
+
// is restricted to a b2tfs node, which itself has two
|
|
236
|
+
// possibilities: file or folder. So we can't replay dna blindly
|
|
237
|
+
// between the two branches and then try to do some kind of text
|
|
238
|
+
// merge later. We must analyze each branch and decide how to handle
|
|
239
|
+
// each change.
|
|
240
|
+
//
|
|
241
|
+
// NOTE: I have tweaked canGraft to only return true on
|
|
242
|
+
// B2tFSType.file and not folders, to see if the dna replay is good
|
|
243
|
+
// enough for folders, so we can concentrate on just files. Keep
|
|
244
|
+
// that in mind when I discuss the following notes.
|
|
245
|
+
//
|
|
246
|
+
// what we know at this point:
|
|
247
|
+
// * graft was invoked, so the sync engine detected divergence in
|
|
248
|
+
// the two spaces, i.e., our two branches (branch-per-space)
|
|
249
|
+
// * IOW, this is NOT a FF merge. That would have already been
|
|
250
|
+
// applied and not triggered this graft.
|
|
251
|
+
// * This is either a file or a folder b2tfs item.
|
|
252
|
+
// * If it is a folder...
|
|
253
|
+
// * How does git handle two folders merging, or does it?
|
|
254
|
+
// * git is file-based, and handles folders only secondarily.
|
|
255
|
+
// * How does our current vcs-gib diffing engine even detect if a
|
|
256
|
+
// folder has moved? does it?
|
|
257
|
+
// * If it is a file...
|
|
258
|
+
// * Is there anything that can happen besides the related binary file changing?
|
|
259
|
+
// * If there are multiple changes to the binary file, should we
|
|
260
|
+
// do each of those file changes in the graft?
|
|
261
|
+
// * we need to game out multiple scenarios to answer this.
|
|
262
|
+
// * What about multiple changes to each branch? Do we squash
|
|
263
|
+
// the orphan to a single change and then merge the final?
|
|
264
|
+
// * It is possible we can even parameterize this in this
|
|
265
|
+
// strategy object, but the caller would need to configure
|
|
266
|
+
// this strategy ahead of each sync call if that is the case I
|
|
267
|
+
// think.
|
|
268
|
+
// * One thing to parameterize would be how to handle graft
|
|
269
|
+
// points, as I just realized in the context of version
|
|
270
|
+
// control systems, it is possible that we may want to
|
|
271
|
+
// configure the sync/merge to drop/do something with large
|
|
272
|
+
// binaries (or just files in general) in a specific way.
|
|
273
|
+
// const dnaAddrsAlreadyAccountedFor: IbGibAddr[] = (latestCommonFrameIbGib?.rel8ns?.dna ?? []).concat();
|
|
274
|
+
// const dnaAddrsToApply: IbGibAddr[] = [];
|
|
275
|
+
// for (const orphanFrame of orphanBranch) {
|
|
276
|
+
// if (!orphanFrame.rel8ns) { throw new Error(`(UNEXPECTED) orphanFrame.rel8ns falsy? (E: bc9a78ef8dbcd9748305d898bf1b2826)`); }
|
|
277
|
+
// // I don't know if this is expected or not, but seems like if
|
|
278
|
+
// // we're doing a merge, we are expecting the ibgib frames to
|
|
279
|
+
// // have dna
|
|
280
|
+
// if (!orphanFrame.rel8ns.dna || orphanFrame.rel8ns.dna.length === 0) {
|
|
281
|
+
// throw new Error(`(UNEXPECTED) !orphanFrame.rel8ns.dna || orphanFrame.rel8ns.dna.length === 0? How can we be grafting when the orphan slice has no dna? (E: 7e58797aa2f98dfa811e8fa88c693826)`);
|
|
282
|
+
// }
|
|
283
|
+
// const orphanDnaAddrsToApply = getUniqueDnas({
|
|
284
|
+
// base: dnaAddrsAlreadyAccountedFor,
|
|
285
|
+
// extended: orphanFrame.rel8ns.dna,
|
|
286
|
+
// throwIfExtendedDoesntContainBase: true,
|
|
287
|
+
// });
|
|
288
|
+
// orphanDnaAddrsToApply.forEach(x => dnaAddrsAlreadyAccountedFor.push(x));
|
|
289
|
+
// orphanDnaAddrsToApply.forEach(x => dnaAddrsToApply.push(x));
|
|
290
|
+
// }
|
|
291
|
+
// const dnaIbGibsToApply = await getIbGibsFromCache_fallbackToSpaces({
|
|
292
|
+
// addrs: dnaAddrsToApply,
|
|
293
|
+
// readCache_graph: ibGibReadCache,
|
|
294
|
+
// space,
|
|
295
|
+
// });
|
|
296
|
+
// if (logalot) { console.log(`${lc}${mergeDiag} dnaAddrsToApply addrs (${dnaAddrsToApply.length}): ${dnaAddrsToApply} (I: 78a8a82f540d520682664aa806f1b826)`); }
|
|
297
|
+
// const createdIbGibs_Running: IbGib_V1[] = [];
|
|
298
|
+
// const newGraftedIntermediateIbGibs_ordered: IbGib_V1[] = [];
|
|
299
|
+
// const newGraftDnaIbGibs: IbGib_V1[] = [];
|
|
300
|
+
// let currentGraftTip = await applyTransforms({
|
|
301
|
+
// src: baseTip,
|
|
302
|
+
// dnaAddrsToApplyToStoreVersion_MUTATES_IN_PLACE: dnaAddrsToApply.concat(),
|
|
303
|
+
// allLocalIbGibs: dnaIbGibsToApply,
|
|
304
|
+
// createdIbGibs_Running,
|
|
305
|
+
// });
|
|
306
|
+
// if (createdIbGibs_Running.length > 0) {
|
|
307
|
+
// await putInSpace({ space, ibGibs: createdIbGibs_Running });
|
|
308
|
+
// const { mapWithTjp_YesDna: newGraftedIbGibsMap } = splitPerTjpAndOrDna({ ibGibs: createdIbGibs_Running });
|
|
309
|
+
// const newGraftedIbGibs_orderNotGuaranteed = Object.values(newGraftedIbGibsMap);
|
|
310
|
+
// const newGraftedIbGibsByTjp = getTimelinesGroupedByTjp({ ibGibs: newGraftedIbGibs_orderNotGuaranteed });
|
|
311
|
+
// if (Object.keys(newGraftedIbGibsByTjp).length > 0) {
|
|
312
|
+
// Object.values(newGraftedIbGibsByTjp)[0].forEach(x => newGraftedIntermediateIbGibs_ordered.push(x));
|
|
313
|
+
// for (const item of newGraftedIntermediateIbGibs_ordered) {
|
|
314
|
+
// await registerNewIbGib({ ibGib: item, space });
|
|
315
|
+
// }
|
|
316
|
+
// }
|
|
317
|
+
// }
|
|
231
318
|
// 4. Perform 3-way filesystem tree merge across lcaItem, baseItem, orphanItem
|
|
232
319
|
const lcaNode = await this.fetchIbGib({ addr: latestCommonFrameAddr, space, readCache_graph: ibGibReadCache });
|
|
320
|
+
if (!lcaNode) {
|
|
321
|
+
throw new Error(`(UNEXPECTED) lcaNode falsy? (E: a8b2d80dc4f8ba1448fa280d89dfb626)`);
|
|
322
|
+
}
|
|
233
323
|
const lcaItem = await this.resolveRootItemNode({ nodeOrAddr: lcaNode, space, readCache_graph: ibGibReadCache });
|
|
324
|
+
if (!lcaItem) {
|
|
325
|
+
throw new Error(`(UNEXPECTED) lcaItem falsy? (E: 0944f88dde58cbabf82342b814955826)`);
|
|
326
|
+
}
|
|
234
327
|
const baseItem = await this.resolveRootItemNode({ nodeOrAddr: baseTip, space, readCache_graph: ibGibReadCache });
|
|
328
|
+
if (!baseItem) {
|
|
329
|
+
throw new Error(`(UNEXPECTED) baseItem falsy? (E: fac3087884cbebc7083e580514002826)`);
|
|
330
|
+
}
|
|
235
331
|
const orphanItem = await this.resolveRootItemNode({ nodeOrAddr: orphanTip, space, readCache_graph: ibGibReadCache });
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
dna: true,
|
|
260
|
-
nCounter: true,
|
|
261
|
-
});
|
|
262
|
-
const newGraftTip = await this.applyTransformAndRegister({
|
|
263
|
-
resTransform: resRel8Branch,
|
|
264
|
-
space,
|
|
265
|
-
newGraftDnaIbGibs,
|
|
266
|
-
newGraftedIntermediateIbGibs_ordered,
|
|
267
|
-
});
|
|
268
|
-
currentGraftTip = newGraftTip;
|
|
269
|
-
}
|
|
332
|
+
if (!orphanItem) {
|
|
333
|
+
throw new Error(`(UNEXPECTED) orphanItem falsy? (E: 8e7e383753a8814f283280ee82156826)`);
|
|
334
|
+
}
|
|
335
|
+
if (lcaItem.data.fsType !== baseItem.data.fsType) {
|
|
336
|
+
throw new Error(`(UNEXPECTED) lcaItem.data.fsType !== baseItem.data.fsType? (E: 794608f3e678a399ed670388629a6826)`);
|
|
337
|
+
}
|
|
338
|
+
if (lcaItem.data.fsType !== orphanItem.data.fsType) {
|
|
339
|
+
throw new Error(`(UNEXPECTED) lcaItem.data.fsType !== orphanItem.data.fsType? (E: 2813981c8c422b41f85a02fd8aa88226)`);
|
|
340
|
+
}
|
|
341
|
+
// all three fsTypes are equal
|
|
342
|
+
const fsType = lcaItem.data.fsType;
|
|
343
|
+
if (fsType === B2tFSType.folder) {
|
|
344
|
+
throw new Error(`(UNEXPECTED) fsType === B2tFSType.folder? I have tweaked the canGraft so we should only be handling files atow (08/11/2026) (E: b282b8f77b18575378edb902bd80a826)`);
|
|
345
|
+
}
|
|
346
|
+
if (fsType !== B2tFSType.file) {
|
|
347
|
+
throw new Error(`(UNEXPECTED) fsType (${fsType}) is not a file? (E: 272418fe2067ea3e16dac028e86d1a26)`);
|
|
348
|
+
}
|
|
349
|
+
const lcaPayload = await this.getFilePayloadBuffer({
|
|
350
|
+
fileItem: lcaItem, space, readCache_graph: ibGibReadCache
|
|
351
|
+
});
|
|
352
|
+
if (lcaPayload === undefined) {
|
|
353
|
+
if (logalot) {
|
|
354
|
+
console.log(`${lc}${mergeDiag} lcaPayload undefined? (I: 59b25835cce856cea883cf989ceb3826)`);
|
|
270
355
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
356
|
+
}
|
|
357
|
+
const basePayload = await this.getFilePayloadBuffer({
|
|
358
|
+
fileItem: baseItem, space, readCache_graph: ibGibReadCache
|
|
359
|
+
});
|
|
360
|
+
if (basePayload === undefined) {
|
|
361
|
+
if (logalot) {
|
|
362
|
+
console.log(`${lc}${mergeDiag} basePayload undefined? (I: 54f05406dca85eb98821b79f7325c826)`);
|
|
275
363
|
}
|
|
276
364
|
}
|
|
365
|
+
const orphanPayload = await this.getFilePayloadBuffer({
|
|
366
|
+
fileItem: orphanItem, space, readCache_graph: ibGibReadCache
|
|
367
|
+
});
|
|
368
|
+
if (orphanPayload === undefined) {
|
|
369
|
+
if (logalot) {
|
|
370
|
+
console.log(`${lc}${mergeDiag} orphanPayload undefined? (I: cd8b785875b43fc6684c65d818edd826)`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
const isBaseBin = basePayload ? isBinaryBuffer(basePayload.buffer) : false;
|
|
374
|
+
const isOrphanBin = orphanPayload ? isBinaryBuffer(orphanPayload.buffer) : false;
|
|
375
|
+
const isLcaBin = lcaPayload ? isBinaryBuffer(lcaPayload.buffer) : false;
|
|
376
|
+
if (isBaseBin || isOrphanBin || isLcaBin) {
|
|
377
|
+
if (logalot) {
|
|
378
|
+
console.log(`${lc} Non-text binary file detected (${baseItem.data?.name}). Skipping 3-way line diff. (I: 4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b)`);
|
|
379
|
+
}
|
|
380
|
+
// even though we've gotten this far into this `graft` method,
|
|
381
|
+
// we can still return `undefined` early if we decide we can't
|
|
382
|
+
// handle it and we haven't persisted/registered any ibgibs. In
|
|
383
|
+
// this particular case of 3-way text merges, we don't graft
|
|
384
|
+
// non-text binary divergences, e.g., pics, sound files, etc.
|
|
385
|
+
return undefined; /* <<<< returns early */
|
|
386
|
+
}
|
|
387
|
+
if (!lcaPayload) {
|
|
388
|
+
throw new Error(`(UNEXPECTED) lcaPayload falsy? By this point in code, we have guaranteed that we are dealing with a text payload. (E: 0b82892204482f5538a430b8915b7826)`);
|
|
389
|
+
}
|
|
390
|
+
if (!basePayload) {
|
|
391
|
+
throw new Error(`(UNEXPECTED) basePayload falsy? By this point in code, we have guaranteed that we are dealing with a text payload. (E: af1f68a020280b3a5d6ed4a812acd426)`);
|
|
392
|
+
}
|
|
393
|
+
if (!orphanPayload) {
|
|
394
|
+
throw new Error(`(UNEXPECTED) orphanPayload falsy? By this point in code, we have guaranteed that we are dealing with a text payload. (E: 6a521b684763862c3a2e0ca315d62826)`);
|
|
395
|
+
}
|
|
396
|
+
const textLCA = decodeToLines(lcaPayload.buffer).join('\n');
|
|
397
|
+
const textBase = decodeToLines(basePayload.buffer).join('\n');
|
|
398
|
+
const textOrphan = decodeToLines(orphanPayload.buffer).join('\n');
|
|
399
|
+
console.log(`${lc}${mergeDiag} file: ${baseItem.data.name}`);
|
|
400
|
+
console.log(`${lc}${mergeDiag} textLCA:\n${textLCA}`);
|
|
401
|
+
console.log(`${lc}${mergeDiag} textBase:\n${textBase}`);
|
|
402
|
+
console.log(`${lc}${mergeDiag} textOrphan:\n${textOrphan}`);
|
|
403
|
+
const { mergedText } = perform3WayTextLineMerge({ textLCA, textBase, textOrphan });
|
|
404
|
+
console.log(`${lc}${mergeDiag} mergedText:\n${mergedText}`);
|
|
405
|
+
const dataBuffer = Buffer.from(mergedText, 'utf8');
|
|
406
|
+
const fileHash = await hash({ s: mergedText });
|
|
407
|
+
if (baseItem.data.fileExt !== orphanItem.data.fileExt) {
|
|
408
|
+
console.warn(`${lc} baseItem.data.fileExt (${baseItem.data.fileExt}) !== orphanItem.data.fileExt (${orphanItem.data.fileExt})? Using baseItem.data.fileExt for merged fileExt (W: a999b54235bb231fa49224842e212326)`);
|
|
409
|
+
}
|
|
410
|
+
const fileExt = baseItem.data.fileExt;
|
|
411
|
+
const binIb = getBinIb({
|
|
412
|
+
binHash: fileHash,
|
|
413
|
+
binExt: fileExt,
|
|
414
|
+
binEncoding: 'utf8',
|
|
415
|
+
});
|
|
416
|
+
const binIbGib = {
|
|
417
|
+
ib: binIb,
|
|
418
|
+
data: dataBuffer,
|
|
419
|
+
};
|
|
420
|
+
binIbGib.gib = await getGib({ ibGib: binIbGib, hasTjp: false });
|
|
421
|
+
const binAddr = getIbGibAddr({ ibGib: binIbGib });
|
|
422
|
+
// at this point, we are committed to performing the 3-way merge.
|
|
423
|
+
await putInSpace({ ibGib: binIbGib, space });
|
|
424
|
+
await registerNewIbGib({ ibGib: binIbGib, space });
|
|
425
|
+
const fnGetN = (item) => {
|
|
426
|
+
if (item.data.n || item.data.n === 0) {
|
|
427
|
+
return item.data.n;
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
throw new Error(`(UNEXPECTED) item.data.n not a number? (E: 896ceae089c83ca67817fff826be5826)`);
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
const baseItemDataN = fnGetN(baseItem);
|
|
434
|
+
const orphanItemDataN = fnGetN(orphanItem);
|
|
435
|
+
const lowestDataN = baseItemDataN <= orphanItemDataN ?
|
|
436
|
+
baseItemDataN :
|
|
437
|
+
orphanItemDataN;
|
|
438
|
+
const evolveRes = await evolveB2tFSItemIbGib({
|
|
439
|
+
existingItem: baseItem,
|
|
440
|
+
dataToUpdate: {
|
|
441
|
+
fileHash,
|
|
442
|
+
n: lowestDataN + 1,
|
|
443
|
+
},
|
|
444
|
+
rel8nsToUpdate: {
|
|
445
|
+
[BINARY_REL8N_NAME]: [binAddr],
|
|
446
|
+
},
|
|
447
|
+
});
|
|
448
|
+
// sanity checks
|
|
449
|
+
if (!evolveRes.dnas) {
|
|
450
|
+
throw new Error(`(UNEXPECTED) evolveRes.dnas falsy? We should be using dna when working with B2tFS items. (E: e640e892cc76c77f98f3881301035826)`);
|
|
451
|
+
}
|
|
452
|
+
if (!evolveRes.newIbGib) {
|
|
453
|
+
throw new Error(`(UNEXPECTED) evolveRes.newIbGib falsy? we just did the merge, so this should be truthy. (E: 9e488d07772827b66a2aff4801905426)`);
|
|
454
|
+
}
|
|
455
|
+
const newItemWithNewBinPayload = evolveRes.newIbGib;
|
|
456
|
+
const newItemAddr = getIbGibAddr({ ibGib: newItemWithNewBinPayload });
|
|
457
|
+
if (logalot) {
|
|
458
|
+
console.log(`${lc} newItemAddr: ${newItemAddr} (I: d23eef651b88be1248ee29ca179eff26)`);
|
|
459
|
+
}
|
|
460
|
+
const newGraftDnaIbGibs = [];
|
|
461
|
+
const newGraftedIntermediateIbGibs_ordered = [];
|
|
462
|
+
newGraftDnaIbGibs.push(...evolveRes.dnas);
|
|
463
|
+
if (evolveRes.intermediateIbGibs) {
|
|
464
|
+
// todo: when we have this completed, we should know whether or not there are intermediate ibgibs in all cases, some cases, or no cases (never). we should change this from an `if` block with no else to throw an unexpected error (assertion) if it is indeed unexpected
|
|
465
|
+
evolveRes.intermediateIbGibs.forEach(x => newGraftedIntermediateIbGibs_ordered.push(x));
|
|
466
|
+
}
|
|
467
|
+
await persistTransformResult({ resTransform: evolveRes, space });
|
|
468
|
+
await registerNewIbGib({ ibGib: evolveRes.newIbGib, space });
|
|
469
|
+
const baseItemAddr = getIbGibAddr({ ibGib: baseItem });
|
|
470
|
+
const mergedRootAddr = getIbGibAddr({ ibGib: newItemWithNewBinPayload });
|
|
471
|
+
const currentRootAddr = baseItem ? getIbGibAddr({ ibGib: baseItem }) : undefined;
|
|
472
|
+
/**
|
|
473
|
+
* stupid word "details" is plural and I have this set to be an
|
|
474
|
+
* array. don't have the ability to refactor right now, so this will
|
|
475
|
+
* be mildly confusing unfortunately. Agents should not try to just
|
|
476
|
+
* refactor this on the fly.
|
|
477
|
+
*/
|
|
478
|
+
const b2tfsAddlGraftDetails = {
|
|
479
|
+
baseTextB2tFSItemAddr: baseTipAddr,
|
|
480
|
+
baseTextBinAddr: basePayload.binIbGib ? getIbGibAddr({ ibGib: basePayload.binIbGib }) : undefined,
|
|
481
|
+
orphanTextB2tFSItemAddr: orphanTipAddr,
|
|
482
|
+
orphanTextBinAddr: orphanPayload.binIbGib ? getIbGibAddr({ ibGib: orphanPayload.binIbGib }) : undefined,
|
|
483
|
+
};
|
|
277
484
|
// 6. Attach GraftInfo frame
|
|
278
485
|
const graftInfo = await createGraftInfo({
|
|
279
486
|
conflictStrategy,
|
|
280
|
-
details: `
|
|
281
|
-
addlGraftDetails:
|
|
487
|
+
details: `Merged orphan tip text with the baseTip as a starting point.`,
|
|
488
|
+
addlGraftDetails: [b2tfsAddlGraftDetails],
|
|
282
489
|
latestCommonFrameAddr,
|
|
283
490
|
baseAddrsSinceLCA: baseBranchAddrs,
|
|
284
491
|
orphanAddrsSinceLCA: orphanBranchAddrs,
|
|
285
|
-
dnaAddrsApplied:
|
|
492
|
+
dnaAddrsApplied: [],
|
|
286
493
|
});
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
494
|
+
await putInSpace({ ibGib: graftInfo, space });
|
|
495
|
+
await registerNewIbGib({ ibGib: graftInfo, space });
|
|
290
496
|
const graftInfoAddr = getIbGibAddr({ ibGib: graftInfo });
|
|
291
497
|
const resRel8GraftInfo = await rel8({
|
|
292
|
-
src:
|
|
498
|
+
src: newItemWithNewBinPayload,
|
|
293
499
|
rel8nsToAddByAddr: {
|
|
294
500
|
[GRAFT_INFO_REL8N_NAME]: [graftInfoAddr],
|
|
295
501
|
},
|
|
296
502
|
dna: true,
|
|
297
|
-
nCounter:
|
|
503
|
+
nCounter: true,
|
|
298
504
|
});
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
if (space) {
|
|
303
|
-
await persistTransformResult({ resTransform: resRel8GraftInfo, space });
|
|
304
|
-
await registerNewIbGib({ ibGib: resRel8GraftInfo.newIbGib, space });
|
|
505
|
+
if (!resRel8GraftInfo.dnas) {
|
|
506
|
+
throw new Error(`(UNEXPECTED) resRel8GraftInfo.dnas falsy? (E: f3f4a83d3a08bd8de84250c389aed826)`);
|
|
305
507
|
}
|
|
306
508
|
const finalGraftTip = resRel8GraftInfo.newIbGib;
|
|
509
|
+
const finalGraftTipAddr = getIbGibAddr({ ibGib: finalGraftTip });
|
|
510
|
+
if (logalot) {
|
|
511
|
+
console.log(`${lc} finalGraftTipAddr: ${finalGraftTipAddr} (I: 583ac81fb0a84827b85c3076ffeeaf26)`);
|
|
512
|
+
}
|
|
513
|
+
newGraftedIntermediateIbGibs_ordered.push(newItemWithNewBinPayload);
|
|
514
|
+
for (const dna of resRel8GraftInfo.dnas) {
|
|
515
|
+
newGraftDnaIbGibs.push(dna);
|
|
516
|
+
}
|
|
517
|
+
await persistTransformResult({ resTransform: resRel8GraftInfo, space });
|
|
518
|
+
await registerNewIbGib({ ibGib: finalGraftTip, space });
|
|
307
519
|
return {
|
|
308
|
-
dnasReplayed:
|
|
520
|
+
dnasReplayed: [],
|
|
309
521
|
dnasCreatedInGraft: newGraftDnaIbGibs,
|
|
310
522
|
intermediateIbGibsCreatedInGraft: newGraftedIntermediateIbGibs_ordered,
|
|
523
|
+
ancillaryIbGibsCreated: [binIbGib],
|
|
311
524
|
newGraftTip: finalGraftTip,
|
|
312
525
|
graftInfoCreated: graftInfo,
|
|
313
526
|
};
|
|
@@ -339,9 +552,6 @@ export class B2tFS3WayGraftStrategy extends GraftMergeStrategyBase_V1 {
|
|
|
339
552
|
return readCache_graph[matchingKey];
|
|
340
553
|
}
|
|
341
554
|
}
|
|
342
|
-
if (!space) {
|
|
343
|
-
return undefined;
|
|
344
|
-
}
|
|
345
555
|
try {
|
|
346
556
|
const res = await getFromSpace({ space, addrs: [addr, cleanAddr] });
|
|
347
557
|
if (res && res.success && res.ibGibs && res.ibGibs.length > 0) {
|
|
@@ -353,12 +563,14 @@ export class B2tFS3WayGraftStrategy extends GraftMergeStrategyBase_V1 {
|
|
|
353
563
|
}
|
|
354
564
|
catch {
|
|
355
565
|
// Suppress fetch error if address not found
|
|
566
|
+
// why suppress? any ibgibs available to us here should be in space
|
|
567
|
+
// (the temp space of the sync receiver)
|
|
356
568
|
}
|
|
357
569
|
return undefined;
|
|
358
570
|
}
|
|
359
571
|
async resolveRootItemNode({ nodeOrAddr, space, readCache_graph, }) {
|
|
360
572
|
if (!nodeOrAddr) {
|
|
361
|
-
|
|
573
|
+
throw new Error(`(UNEXPECTED) nodeOrAddr falsy? (E: 524108327b9caa00586207ea399f7226)`);
|
|
362
574
|
}
|
|
363
575
|
let node;
|
|
364
576
|
if (typeof nodeOrAddr === 'string') {
|
|
@@ -368,20 +580,16 @@ export class B2tFS3WayGraftStrategy extends GraftMergeStrategyBase_V1 {
|
|
|
368
580
|
node = nodeOrAddr;
|
|
369
581
|
}
|
|
370
582
|
if (!node) {
|
|
371
|
-
|
|
583
|
+
throw new Error(`(UNEXPECTED) node falsy? couldn't get node? (E: bd7d1c3b4a3881ff882746281869d826)`);
|
|
372
584
|
}
|
|
373
|
-
if (
|
|
374
|
-
|
|
375
|
-
if (rootItemAddr) {
|
|
376
|
-
const rootNode = await this.fetchIbGib({ addr: rootItemAddr, space, readCache_graph });
|
|
377
|
-
return rootNode;
|
|
378
|
-
}
|
|
379
|
-
return undefined;
|
|
380
|
-
}
|
|
381
|
-
if (node.ib?.startsWith('b2tfs_item') || node.data?.classname === 'B2tFSItemIbGib_V1') {
|
|
585
|
+
if (isB2tFSItemIbGib(node)) {
|
|
586
|
+
// it's an item ibgib
|
|
382
587
|
return node;
|
|
383
588
|
}
|
|
384
|
-
|
|
589
|
+
else {
|
|
590
|
+
// not an item ibgib
|
|
591
|
+
throw new Error(`(UNEXPECTED) node is not a B2tFSItemIbGib_V1? canGraft should have returned false then and we should never have gotten here. (E: ddabb281ccb2fb1a181109a82046b826)`);
|
|
592
|
+
}
|
|
385
593
|
}
|
|
386
594
|
async getFilePayloadBuffer({ fileItem, space, readCache_graph, }) {
|
|
387
595
|
if (!fileItem || !fileItem.rel8ns) {
|
|
@@ -393,9 +601,12 @@ export class B2tFS3WayGraftStrategy extends GraftMergeStrategyBase_V1 {
|
|
|
393
601
|
return undefined;
|
|
394
602
|
}
|
|
395
603
|
const binIbGib = await this.fetchIbGib({ addr: latestBinAddr, space, readCache_graph });
|
|
396
|
-
if (!binIbGib
|
|
397
|
-
|
|
604
|
+
if (!binIbGib) {
|
|
605
|
+
throw new Error(`(UNEXPECTED) couldn't fetch binIbGib? latestBinAddr: ${latestBinAddr}. space.ib: ${space.ib} (E: 3d1238b3a348924038a79f88264d8226)`);
|
|
398
606
|
}
|
|
607
|
+
if (binIbGib.data === undefined) {
|
|
608
|
+
return undefined;
|
|
609
|
+
} // what if it's an empty file. will data be undefined? do we handle this at the b2tfs item level for fsType === 'file'?
|
|
399
610
|
let fileData;
|
|
400
611
|
const dataObj = binIbGib.data;
|
|
401
612
|
if (dataObj && typeof dataObj === 'object' && dataObj._dataType === 'Uint8Array_Base64' && typeof dataObj.value === 'string') {
|
|
@@ -472,119 +683,56 @@ export class B2tFS3WayGraftStrategy extends GraftMergeStrategyBase_V1 {
|
|
|
472
683
|
}
|
|
473
684
|
const fsType = baseItem.data?.fsType || orphanItem.data?.fsType;
|
|
474
685
|
if (fsType === 'file') {
|
|
475
|
-
const lcaPayload = await this.getFilePayloadBuffer({ fileItem: lcaItem, space, readCache_graph });
|
|
476
|
-
const basePayload = await this.getFilePayloadBuffer({ fileItem: baseItem, space, readCache_graph });
|
|
477
|
-
const orphanPayload = await this.getFilePayloadBuffer({ fileItem: orphanItem, space, readCache_graph });
|
|
478
|
-
const isBaseBin = basePayload ? isBinaryBuffer(basePayload.buffer) : false;
|
|
479
|
-
const isOrphanBin = orphanPayload ? isBinaryBuffer(orphanPayload.buffer) : false;
|
|
480
|
-
const isLcaBin = lcaPayload ? isBinaryBuffer(lcaPayload.buffer) : false;
|
|
481
|
-
if (isBaseBin || isOrphanBin || isLcaBin) {
|
|
482
|
-
if (logalot) {
|
|
483
|
-
console.log(`${lc} Non-text binary file detected (${baseItem.data?.name}). Skipping 3-way line diff. (I: 4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b)`);
|
|
484
|
-
}
|
|
485
|
-
return baseItem;
|
|
486
|
-
}
|
|
487
|
-
const textLCA = lcaPayload ? decodeToLines(lcaPayload.buffer).join('\n') : '';
|
|
488
|
-
const textBase = basePayload ? decodeToLines(basePayload.buffer).join('\n') : '';
|
|
489
|
-
const textOrphan = orphanPayload ? decodeToLines(orphanPayload.buffer).join('\n') : '';
|
|
490
|
-
console.log(`${lc} [MERGE DIAGNOSTIC] file: ${baseItem.data?.name}`);
|
|
491
|
-
console.log(`${lc} [MERGE DIAGNOSTIC] textLCA:\n${textLCA}`);
|
|
492
|
-
console.log(`${lc} [MERGE DIAGNOSTIC] textBase:\n${textBase}`);
|
|
493
|
-
console.log(`${lc} [MERGE DIAGNOSTIC] textOrphan:\n${textOrphan}`);
|
|
494
|
-
const { mergedText } = perform3WayTextLineMerge({ textLCA, textBase, textOrphan });
|
|
495
|
-
console.log(`${lc} [MERGE DIAGNOSTIC] mergedText:\n${mergedText}`);
|
|
496
|
-
const dataBuffer = Buffer.from(mergedText, 'utf8');
|
|
497
|
-
const fileHash = await hash({ s: mergedText });
|
|
498
|
-
const fileExt = baseItem.data?.fileExt || (baseItem.data?.name?.includes('.') ? baseItem.data.name.split('.').pop() || 'txt' : 'txt');
|
|
499
|
-
const binIb = getBinIb({
|
|
500
|
-
binHash: fileHash,
|
|
501
|
-
binExt: fileExt,
|
|
502
|
-
binEncoding: 'utf8',
|
|
503
|
-
});
|
|
504
|
-
const binIbGib = {
|
|
505
|
-
ib: binIb,
|
|
506
|
-
data: dataBuffer,
|
|
507
|
-
};
|
|
508
|
-
binIbGib.gib = await getGib({ ibGib: binIbGib, hasTjp: false });
|
|
509
|
-
const binAddr = getIbGibAddr({ ibGib: binIbGib });
|
|
510
|
-
if (space) {
|
|
511
|
-
await putInSpace({ ibGib: binIbGib, space });
|
|
512
|
-
await registerNewIbGib({ ibGib: binIbGib, space });
|
|
513
|
-
}
|
|
514
|
-
const evolveRes = await evolveB2tFSItemIbGib({
|
|
515
|
-
existingItem: baseItem,
|
|
516
|
-
dataToUpdate: {
|
|
517
|
-
fileHash,
|
|
518
|
-
},
|
|
519
|
-
rel8nsToUpdate: {
|
|
520
|
-
[BINARY_REL8N_NAME]: [binAddr],
|
|
521
|
-
},
|
|
522
|
-
});
|
|
523
|
-
if (evolveRes.dnas) {
|
|
524
|
-
newGraftDnaIbGibs.push(...evolveRes.dnas);
|
|
525
|
-
}
|
|
526
|
-
if (evolveRes.newIbGib) {
|
|
527
|
-
newGraftedIntermediateIbGibs_ordered.push(evolveRes.newIbGib);
|
|
528
|
-
}
|
|
529
|
-
if (space) {
|
|
530
|
-
await persistTransformResult({ resTransform: evolveRes, space });
|
|
531
|
-
await registerNewIbGib({ ibGib: evolveRes.newIbGib, space });
|
|
532
|
-
}
|
|
533
|
-
return evolveRes.newIbGib;
|
|
534
686
|
}
|
|
535
687
|
else if (fsType === 'folder') {
|
|
536
|
-
const lcaChildrenMap = await this.getChildItemsMap({ folderItem: lcaItem, space, readCache_graph });
|
|
537
|
-
const baseChildrenMap = await this.getChildItemsMap({ folderItem: baseItem, space, readCache_graph });
|
|
538
|
-
const orphanChildrenMap = await this.getChildItemsMap({ folderItem: orphanItem, space, readCache_graph });
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
]);
|
|
544
|
-
const mergedChildAddrs = [];
|
|
545
|
-
for (const
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
}
|
|
562
|
-
const currentChildAddrs = baseItem.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
|
|
563
|
-
const addrsChanged = mergedChildAddrs.length !== currentChildAddrs.length ||
|
|
564
|
-
|
|
565
|
-
if (!addrsChanged) {
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
const evolveRes = await evolveB2tFSItemIbGib({
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
});
|
|
577
|
-
if (evolveRes.dnas) {
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
await persistTransformResult({ resTransform: evolveRes, space });
|
|
585
|
-
await registerNewIbGib({ ibGib: evolveRes.newIbGib, space });
|
|
586
|
-
}
|
|
587
|
-
return evolveRes.newIbGib;
|
|
688
|
+
// const lcaChildrenMap = await this.getChildItemsMap({ folderItem: lcaItem, space, readCache_graph });
|
|
689
|
+
// const baseChildrenMap = await this.getChildItemsMap({ folderItem: baseItem, space, readCache_graph });
|
|
690
|
+
// const orphanChildrenMap = await this.getChildItemsMap({ folderItem: orphanItem, space, readCache_graph });
|
|
691
|
+
// const allChildAddrs = new Set([
|
|
692
|
+
// ...lcaChildrenMap.keys(),
|
|
693
|
+
// ...baseChildrenMap.keys(),
|
|
694
|
+
// ...orphanChildrenMap.keys(),
|
|
695
|
+
// ]);
|
|
696
|
+
// const mergedChildAddrs: string[] = [];
|
|
697
|
+
// for (const childItemAddr of allChildAddrs) {
|
|
698
|
+
// const childLCA = lcaChildrenMap.get(childItemAddr);
|
|
699
|
+
// const childBase = baseChildrenMap.get(childItemAddr);
|
|
700
|
+
// const childOrphan = orphanChildrenMap.get(childItemAddr);
|
|
701
|
+
// const mergedChild = await this.mergeTreeNodes({
|
|
702
|
+
// lcaItem: childLCA,
|
|
703
|
+
// baseItem: childBase,
|
|
704
|
+
// orphanItem: childOrphan,
|
|
705
|
+
// space,
|
|
706
|
+
// readCache_graph,
|
|
707
|
+
// newGraftDnaIbGibs,
|
|
708
|
+
// newGraftedIntermediateIbGibs_ordered,
|
|
709
|
+
// });
|
|
710
|
+
// if (mergedChild) {
|
|
711
|
+
// mergedChildAddrs.push(getIbGibAddr({ ibGib: mergedChild }));
|
|
712
|
+
// }
|
|
713
|
+
// }
|
|
714
|
+
// const currentChildAddrs = baseItem.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
|
|
715
|
+
// const addrsChanged = mergedChildAddrs.length !== currentChildAddrs.length ||
|
|
716
|
+
// mergedChildAddrs.some((addr, idx) => addr !== currentChildAddrs[idx]);
|
|
717
|
+
// if (!addrsChanged) {
|
|
718
|
+
// return baseItem;
|
|
719
|
+
// }
|
|
720
|
+
// const evolveRes = await evolveB2tFSItemIbGib({
|
|
721
|
+
// existingItem: baseItem,
|
|
722
|
+
// rel8nsToUpdate: {
|
|
723
|
+
// [B2TFS_CHILD_ITEM_REL8N_NAME]: mergedChildAddrs,
|
|
724
|
+
// },
|
|
725
|
+
// rel8nsToRemove: {
|
|
726
|
+
// [B2TFS_CHILD_ITEM_REL8N_NAME]: baseItem.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [],
|
|
727
|
+
// },
|
|
728
|
+
// });
|
|
729
|
+
// if (evolveRes.dnas) { newGraftDnaIbGibs.push(...evolveRes.dnas); }
|
|
730
|
+
// if (evolveRes.newIbGib) { newGraftedIntermediateIbGibs_ordered.push(evolveRes.newIbGib); }
|
|
731
|
+
// if (space) {
|
|
732
|
+
// await persistTransformResult({ resTransform: evolveRes, space });
|
|
733
|
+
// await registerNewIbGib({ ibGib: evolveRes.newIbGib, space });
|
|
734
|
+
// }
|
|
735
|
+
// return evolveRes.newIbGib as B2tFSItemIbGib_V1;
|
|
588
736
|
}
|
|
589
737
|
return baseItem;
|
|
590
738
|
}
|