{"file":"src/engine/labels.ts","version":318,"total":48,"from":1,"to":48,"lines":[{"n":1,"text":"// Labels: what git calls commits. A label is a head atom plus everything it","atom":"a0","author":"init","version":0},{"n":2,"text":"// needed, minus a base. Labels are stored on the graph (graph.setLabel).","atom":"a0","author":"init","version":0},{"n":3,"text":"","atom":"a0","author":"init","version":0},{"n":4,"text":"import type { Graph } from \"./graph.ts\";","atom":"a0","author":"init","version":0},{"n":5,"text":"import { history } from \"./sets.ts\";","atom":"a0","author":"init","version":0},{"n":6,"text":"import { type AtomId, EngineError, type Label } from \"./types.ts\";","atom":"a0","author":"init","version":0},{"n":7,"text":"","atom":"a0","author":"init","version":0},{"n":8,"text":"/** A label name or an atom id, resolved to an atom id (a label resolves to its head). */","atom":"a0","author":"init","version":0},{"n":9,"text":"export function resolveRef(graph: Graph, ref: string): AtomId {","atom":"a0","author":"init","version":0},{"n":10,"text":"\tconst label = graph.label(ref);","atom":"a0","author":"init","version":0},{"n":11,"text":"\tif (label) return label.head;","atom":"a0","author":"init","version":0},{"n":12,"text":"\tif (graph.has(ref)) return ref;","atom":"a0","author":"init","version":0},{"n":13,"text":"\tthrow new EngineError(\"unknown-ref\", `${ref} is neither a label nor an atom`);","atom":"a0","author":"init","version":0},{"n":14,"text":"}","atom":"a0","author":"init","version":0},{"n":15,"text":"","atom":"a0","author":"init","version":0},{"n":16,"text":"/** The full state a ref names: the closure of the atom (or the label's head). */","atom":"a0","author":"init","version":0},{"n":17,"text":"export function stateOf(graph: Graph, ref: string): ReadonlySet<AtomId> {","atom":"a0","author":"init","version":0},{"n":18,"text":"\treturn graph.closure(resolveRef(graph, ref));","atom":"a0","author":"init","version":0},{"n":19,"text":"}","atom":"a0","author":"init","version":0},{"n":20,"text":"","atom":"a0","author":"init","version":0},{"n":21,"text":"/**","atom":"a0","author":"init","version":0},{"n":22,"text":" * A label's contents, in history order: closure(head) minus closure(base);","atom":"a0","author":"init","version":0},{"n":23,"text":" * without a base, minus a0.","atom":"a0","author":"init","version":0},{"n":24,"text":" */","atom":"a0","author":"init","version":0},{"n":25,"text":"export function labelContents(graph: Graph, label: Pick<Label, \"head\" | \"base\">): AtomId[] {","atom":"a0","author":"init","version":0},{"n":26,"text":"\tconst include = graph.closure(label.head);","atom":"a0","author":"init","version":0},{"n":27,"text":"\tconst exclude: ReadonlySet<AtomId> = label.base !== undefined ? stateOf(graph, label.base) : new Set([\"a0\"]);","atom":"a0","author":"init","version":0},{"n":28,"text":"\treturn history(","atom":"a0","author":"init","version":0},{"n":29,"text":"\t\tgraph,","atom":"a0","author":"init","version":0},{"n":30,"text":"\t\t[...include].filter((id) => !exclude.has(id)),","atom":"a0","author":"init","version":0},{"n":31,"text":"\t).map((a) => a.id);","atom":"a0","author":"init","version":0},{"n":32,"text":"}","atom":"a0","author":"init","version":0},{"n":33,"text":"","atom":"a0","author":"init","version":0},{"n":34,"text":"/**","atom":"a0","author":"init","version":0},{"n":35,"text":" * Re-slice: any atom inside a label defines a smaller label (that atom plus","atom":"a0","author":"init","version":0},{"n":36,"text":" * its own closure, same base). Returns that smaller label's contents.","atom":"a0","author":"init","version":0},{"n":37,"text":" */","atom":"a0","author":"init","version":0},{"n":38,"text":"export function reslice(graph: Graph, label: Pick<Label, \"head\" | \"base\">, atom: AtomId): AtomId[] {","atom":"a0","author":"init","version":0},{"n":39,"text":"\tif (!labelContents(graph, label).includes(atom)) {","atom":"a0","author":"init","version":0},{"n":40,"text":"\t\tthrow new EngineError(\"not-in-set\", `${atom} is not inside the label`);","atom":"a0","author":"init","version":0},{"n":41,"text":"\t}","atom":"a0","author":"init","version":0},{"n":42,"text":"\treturn labelContents(graph, { head: atom, ...(label.base !== undefined ? { base: label.base } : {}) });","atom":"a0","author":"init","version":0},{"n":43,"text":"}","atom":"a0","author":"init","version":0},{"n":44,"text":"","atom":"a0","author":"init","version":0},{"n":45,"text":"/** Labels whose contents include the atom (for \"why\" output). */","atom":"a0","author":"init","version":0},{"n":46,"text":"export function labelsContaining(graph: Graph, atom: AtomId): Label[] {","atom":"a0","author":"init","version":0},{"n":47,"text":"\treturn graph.labels().filter((l) => labelContents(graph, l).includes(atom));","atom":"a0","author":"init","version":0},{"n":48,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}}]}