{"file":"worker/project/tree.ts","version":318,"total":25,"from":1,"to":25,"lines":[{"n":1,"text":"// A tree hash (#39, the merge queue; #42, Actions): one sha256 for a set of","atom":"a0","author":"init","version":0},{"n":2,"text":"// files, so a queue candidate and the version that lands from it, or a run in","atom":"a0","author":"init","version":0},{"n":3,"text":"// someone's own account, can be matched without comparing every file. It","atom":"a0","author":"init","version":0},{"n":4,"text":"// covers each file's path, mode (executable, or link target) and content (the","atom":"a0","author":"init","version":0},{"n":5,"text":"// text's sha256, or the blob's sha256 for a binary file), in path order.","atom":"a0","author":"init","version":0},{"n":6,"text":"import { createHash } from \"node:crypto\";","atom":"a0","author":"init","version":0},{"n":7,"text":"","atom":"a0","author":"init","version":0},{"n":8,"text":"export interface TreeFiles {","atom":"a0","author":"init","version":0},{"n":9,"text":"\treadonly files: Readonly<Record<string, string>>;","atom":"a0","author":"init","version":0},{"n":10,"text":"\treadonly modes?: Readonly<Record<string, { readonly exec?: boolean; readonly link?: string | null }>>;","atom":"a0","author":"init","version":0},{"n":11,"text":"\treadonly blobs?: Readonly<Record<string, string>>;","atom":"a0","author":"init","version":0},{"n":12,"text":"}","atom":"a0","author":"init","version":0},{"n":13,"text":"","atom":"a0","author":"init","version":0},{"n":14,"text":"const sha = (s: string): string => createHash(\"sha256\").update(s, \"utf8\").digest(\"hex\");","atom":"a0","author":"init","version":0},{"n":15,"text":"","atom":"a0","author":"init","version":0},{"n":16,"text":"export function treeHash(tree: TreeFiles): string {","atom":"a0","author":"init","version":0},{"n":17,"text":"\tconst paths = [...new Set([...Object.keys(tree.files), ...Object.keys(tree.blobs ?? {})])].sort();","atom":"a0","author":"init","version":0},{"n":18,"text":"\tconst lines = paths.map((p) => {","atom":"a0","author":"init","version":0},{"n":19,"text":"\t\tconst m = tree.modes?.[p];","atom":"a0","author":"init","version":0},{"n":20,"text":"\t\tconst mode = m?.link != null ? `link:${m.link}` : m?.exec ? \"exec\" : \"file\";","atom":"a0","author":"init","version":0},{"n":21,"text":"\t\tconst content = tree.blobs?.[p] ?? sha(tree.files[p] ?? \"\");","atom":"a0","author":"init","version":0},{"n":22,"text":"\t\treturn `${mode} ${content} ${p}`;","atom":"a0","author":"init","version":0},{"n":23,"text":"\t});","atom":"a0","author":"init","version":0},{"n":24,"text":"\treturn sha(lines.join(\"\\n\"));","atom":"a0","author":"init","version":0},{"n":25,"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"}}]}