Lines 1–6 at 149 (were 1–5 at 148)
11import { createHash } from "node:crypto"; 22import type { Atom } from "../types.ts"; 3+import { ProjectionAtomDescriptor } from "./projection-atom-index.ts"; 34import type { ExperimentalMarkerProjection, MarkerState } from "./projection-marker.ts"; 45import { adoptMovesStep } from "./projection-move-adoption.ts"; Lines 82–88 at 149 (were 81–87 at 148)
8384 previous: MarkerState; 84− atom: Atom;
85+ atom: Atom | ProjectionAtomDescriptor; Lines 102–137 at 149 (were 101–108 at 148)
102103 throw Error("invalid atom adoption page bounds"); 103104 const atom = input.atom; 104− const identity = digest([input.source, input.previous, atom, input.remove]);
105− if (digest(p.graph.atom(atom.id)) !== digest(atom)) throw Error("canonical adoption atom mismatch");
105+ const indexed = atom instanceof ProjectionAtomDescriptor ? atom : undefined; 106+ const full = indexed ? undefined : (atom as Atom); 107+ const identity = digest([ 110+ indexed ? [indexed.id, indexed.seq, indexed.digest] : atom, 114+ if (p.graph.idOfSeq(indexed.seq) !== indexed.id) throw Error("canonical adoption atom mismatch"); 115+ } else if (digest(p.graph.atom(atom.id)) !== digest(full)) throw Error("canonical adoption atom mismatch"); 116+ const inserts = indexed?.count("inserts") ?? full!.inserts.length; 117+ const run = (i: number) => 119+ ? indexed.item("inserts", i) 120+ : { file: full!.inserts[i]!.file, parent: full!.inserts[i]!.parent, lines: full!.inserts[i]!.lines.length }; 121+ const deps = indexed?.count("deps") ?? full!.deps.length; 122+ const dependency = (i: number) => (indexed ? indexed.item("deps", i) : full!.deps[i]!); 123+ const deletes = indexed?.count("deletes") ?? full!.deletes.length; 124+ const deletion = (i: number) => (indexed ? indexed.item("deletes", i) : full!.deletes[i]!); 125+ const attrs = indexed?.count("attrs") ?? full!.attrs?.length ?? 0; 126+ const attribute = (i: number) => (indexed ? indexed.item("attrs", i) : full!.attrs![i]!); 127+ const moves = indexed?.count("moves") ?? full!.moves?.length ?? 0; 128+ const fullFiles = indexed ? undefined : p.graph.filesOf(atom.id); 129+ const files = indexed?.count("files") ?? fullFiles!.length; 130+ const file = (i: number) => (indexed ? indexed.item("files", i) : fullFiles![i]!); 131+ const seqOf = (id: string) => { 132+ if (!p.graph.has(id)) throw Error("missing dependency"); 133+ return Number(id.slice(1)); 106135 const collection = `atom-adoption:${this.task}`; 107136 const validate = () => { 108137 const result: unknown = input.validateSource(); Lines 150–168 at 149 (were 121–139 at 148)
122151 throw Error("invalid or changed atom adoption cursor"); 123152 p.assertContext(cursor.state); 124− if (cursor.run > atom.inserts.length || cursor.line > (atom.inserts[cursor.run]?.lines.length ?? 0))
153+ if (cursor.run > inserts || cursor.line > (cursor.run < inserts ? run(cursor.run).lines : 0)) 125154 throw Error("invalid atom adoption line position"); 126155 const limits: Record<Phase, number> = { 127− dependencies: atom.deps.length,
128− files: atom.inserts.length + 1,
130− deletes: atom.deletes.length,
131− counts: atom.deps.length,
132− attributes: atom.attrs?.length ?? 0,
133− contributions: p.graph.filesOf(atom.id).length,
162+ contributions: files, 136− cleanup: atom.attrs?.length ?? 0,
139168 if (cursor.index > limits[cursor.phase]) throw Error("invalid atom adoption phase position"); Lines 187–221 at 149 (were 158–192 at 148)
158187 cursor!.index = 0; 160189 const state = cursor.state; 161− const contributionFiles = p.graph.filesOf(atom.id);
162191 while (cursor.phase !== "done" && steps < input.maxSteps) { 164193 switch (cursor.phase) { 165194 case "dependencies": { 166− if (input.remove || cursor.index === atom.deps.length) {
195+ if (input.remove || cursor.index === deps) { 170− const id = atom.deps[cursor.index++]!;
171− if (!p.members.get(state.membership, p.graph.atom(id).seq)?.present) throw Error("missing dependency");
199+ const id = dependency(cursor.index++); 200+ if (!p.members.get(state.membership, seqOf(id))?.present) throw Error("missing dependency"); 175− if (input.remove || cursor.index > atom.inserts.length) {
204+ if (input.remove || cursor.index > inserts) { 179− p.ensureFile(state, cursor.index === 0 ? p.path : atom.inserts[cursor.index - 1]!.file);
208+ p.ensureFile(state, cursor.index === 0 ? p.path : run(cursor.index - 1).file); 184− if (cursor.run === atom.inserts.length) {
213+ if (cursor.run === inserts) { 188− const run = atom.inserts[cursor.run]!;
189− if (cursor.line === run.lines.length) {
217+ const currentRun = run(cursor.run); 218+ if (cursor.line === currentRun.lines) { Lines 231–241 at 149 (were 202–212 at 148)
205− if (cursor.index === atom.deletes.length) {
234+ if (cursor.index === deletes) { 209− const marker = p.markers.get(state.locator, p.graph.lineN(atom.deletes[cursor.index++]!) + 1);
238+ const marker = p.markers.get(state.locator, p.graph.lineN(deletion(cursor.index++)) + 1); 210239 if (!marker) throw Error("missing deleted marker"); 211240 state.sequence = p.sequence.update(state.sequence, { 212241 kind: "visibility", Lines 245–255 at 149 (were 216–226 at 148)
219− if (cursor.index === atom.deps.length) {
248+ if (cursor.index === deps) { 223− const seq = p.graph.atom(atom.deps[cursor.index++]!).seq;
252+ const seq = seqOf(dependency(cursor.index++)); 224253 const member = p.members.get(state.membership, seq); 225254 if (!member?.present || (input.remove && member.dependents < 1)) throw Error("invalid dependency count"); 226255 state.membership = p.members.set(state.membership, seq, { Lines 259–282 at 149 (were 230–254 at 148)
232261 case "attributes": { 233− const attrs = atom.attrs ?? [];
234− if (cursor.index === attrs.length) {
262+ if (cursor.index === attrs) { 238− const attr = attrs[cursor.index++]!;
266+ const attr = attribute(cursor.index++); 239267 const key = JSON.stringify([attr.file, attr.name]); 240268 if (!p.storage.read(`${collection}:attributes`, key)) { 241− p.updateAttributes(state, { ...atom, attrs: [attr] }, !input.remove);
269+ p.updateAttributes(state, { seq: atom.seq, attrs: [attr] }, !input.remove); 242270 p.storage.write(`${collection}:attributes`, key, true); 246274 case "contributions": { 247− if (cursor.index === contributionFiles.length) {
275+ if (cursor.index === files) { 251− const path = contributionFiles[cursor.index++]!;
279+ const path = file(cursor.index++); 252280 p.ensureFile(state, path); 253281 const key = p.fileKey(path)!; 254282 const marker = p.markers.get(state.locator, key); Lines 294–326 at 149 (were 266–285 at 148)
269− if (atom.moves?.length) {
270− const result = adoptMovesStep(p, state, this.task, identity);
298+ const result = adoptMovesStep( 305+ count: (id) => indexed.related(id).count("moves"), 307+ const atom = indexed.related(id); 308+ return k < atom.count("moves") ? atom.item("moves", k) : undefined; 271313 Object.assign(state, result.state); 272314 if (!result.done) break; 277− const attrs = atom.attrs ?? [];
278− if (cursor.index === attrs.length) {
319+ if (cursor.index === attrs) { 282− const attr = attrs[cursor.index++]!;
323+ const attr = attribute(cursor.index++); 283324 p.storage.remove(`${collection}:attributes`, JSON.stringify([attr.file, attr.name]));