{"file":"server/src/push.ts","version":154,"total":256,"from":1,"to":256,"lines":[{"n":1,"text":"// Out to Artifacts (#8): shared's files as one git commit on main of the","atom":"a1447","author":"speed","version":150},{"n":2,"text":"// project's repo, with the publish message and the agent as author. The repo","atom":"a1447","author":"speed","version":150},{"n":3,"text":"// is created on first use. isomorphic-git works in an in-memory filesystem:","atom":"a1447","author":"speed","version":150},{"n":4,"text":"// a depth-1 clone of main with nothing checked out, then a new tree from","atom":"a1447","author":"speed","version":150},{"n":5,"text":"// shared's files that compresses and writes only what changed (abso issue 293).","atom":"a1447","author":"speed","version":150},{"n":6,"text":"import git from \"isomorphic-git\";","atom":"a1447","author":"speed","version":150},{"n":7,"text":"import http from \"isomorphic-git/http/web\";","atom":"a1447","author":"speed","version":150},{"n":8,"text":"import type { FileModes } from \"../../worker/project/project-api.ts\";","atom":"a1447","author":"speed","version":150},{"n":9,"text":"import { MemoryFS } from \"./memory-fs.ts\";","atom":"a1447","author":"speed","version":150},{"n":10,"text":"","atom":"a1447","author":"speed","version":150},{"n":11,"text":"export interface PushResult {","atom":"a1447","author":"speed","version":150},{"n":12,"text":"\trepo: string;","atom":"a1447","author":"speed","version":150},{"n":13,"text":"\tremote: string;","atom":"a1447","author":"speed","version":150},{"n":14,"text":"\tcommit: string;","atom":"a1447","author":"speed","version":150},{"n":15,"text":"\tversion: number;","atom":"a1447","author":"speed","version":150},{"n":16,"text":"\tms: number;","atom":"a1447","author":"speed","version":150},{"n":17,"text":"}","atom":"a1447","author":"speed","version":150},{"n":18,"text":"","atom":"a1447","author":"speed","version":150},{"n":19,"text":"/** New blob bytes per push before the push out splits into parts: Artifacts refuses a push much over 20 MB. */","atom":"a1447","author":"speed","version":150},{"n":20,"text":"const PUSH_BATCH = 16 * 1024 * 1024;","atom":"a1447","author":"speed","version":150},{"n":21,"text":"","atom":"a1447","author":"speed","version":150},{"n":22,"text":"/** A file as a tree entry holds it: its blob and its mode (\"100644\", \"100755\", \"120000\"). */","atom":"a1447","author":"speed","version":150},{"n":23,"text":"export interface TreeFile {","atom":"a1447","author":"speed","version":150},{"n":24,"text":"\toid: string;","atom":"a1447","author":"speed","version":150},{"n":25,"text":"\tmode: string;","atom":"a1447","author":"speed","version":150},{"n":26,"text":"}","atom":"a1447","author":"speed","version":150},{"n":27,"text":"","atom":"a1447","author":"speed","version":150},{"n":28,"text":"/** Every file in a tree, and every folder's tree oid (\"\" is the root), read from tree objects only. */","atom":"a1447","author":"speed","version":150},{"n":29,"text":"export async function readTreeFiles(","atom":"a1447","author":"speed","version":150},{"n":30,"text":"\tfs: MemoryFS,","atom":"a1447","author":"speed","version":150},{"n":31,"text":"\tdir: string,","atom":"a1447","author":"speed","version":150},{"n":32,"text":"\toid: string,","atom":"a1447","author":"speed","version":150},{"n":33,"text":"\tprefix = \"\",","atom":"a1447","author":"speed","version":150},{"n":34,"text":"\tfiles = new Map<string, TreeFile>(),","atom":"a1447","author":"speed","version":150},{"n":35,"text":"\ttrees = new Map<string, string>(),","atom":"a1447","author":"speed","version":150},{"n":36,"text":"): Promise<{ files: Map<string, TreeFile>; trees: Map<string, string> }> {","atom":"a1447","author":"speed","version":150},{"n":37,"text":"\ttrees.set(prefix, oid);","atom":"a1447","author":"speed","version":150},{"n":38,"text":"\tconst { tree } = await git.readTree({ fs, dir, oid });","atom":"a1447","author":"speed","version":150},{"n":39,"text":"\tfor (const e of tree) {","atom":"a1447","author":"speed","version":150},{"n":40,"text":"\t\tconst path = prefix === \"\" ? e.path : `${prefix}/${e.path}`;","atom":"a1447","author":"speed","version":150},{"n":41,"text":"\t\tif (e.type === \"tree\") await readTreeFiles(fs, dir, e.oid, path, files, trees);","atom":"a1447","author":"speed","version":150},{"n":42,"text":"\t\telse if (e.type === \"blob\") files.set(path, { oid: e.oid, mode: e.mode });","atom":"a1447","author":"speed","version":150},{"n":43,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":44,"text":"\treturn { files, trees };","atom":"a1447","author":"speed","version":150},{"n":45,"text":"}","atom":"a1447","author":"speed","version":150},{"n":46,"text":"","atom":"a1447","author":"speed","version":150},{"n":47,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":48,"text":" * A blob's git oid, with the platform's SHA-1 (abso issue 293): native and awaited, so hashing every file of a big","atom":"a1447","author":"speed","version":150},{"n":49,"text":" * project neither burns the object's CPU in JavaScript nor holds its other requests back for long.","atom":"a1447","author":"speed","version":150},{"n":50,"text":" */","atom":"a1447","author":"speed","version":150},{"n":51,"text":"export async function blobOid(bytes: Uint8Array): Promise<string> {","atom":"a1447","author":"speed","version":150},{"n":52,"text":"\tconst head = new TextEncoder().encode(`blob ${bytes.byteLength}\\0`);","atom":"a1447","author":"speed","version":150},{"n":53,"text":"\tconst all = new Uint8Array(head.byteLength + bytes.byteLength);","atom":"a1447","author":"speed","version":150},{"n":54,"text":"\tall.set(head);","atom":"a1447","author":"speed","version":150},{"n":55,"text":"\tall.set(bytes, head.byteLength);","atom":"a1447","author":"speed","version":150},{"n":56,"text":"\tconst d = new Uint8Array(await crypto.subtle.digest(\"SHA-1\", all));","atom":"a1447","author":"speed","version":150},{"n":57,"text":"\treturn [...d].map((b) => b.toString(16).padStart(2, \"0\")).join(\"\");","atom":"a1447","author":"speed","version":150},{"n":58,"text":"}","atom":"a1447","author":"speed","version":150},{"n":59,"text":"","atom":"a1447","author":"speed","version":150},{"n":60,"text":"const parentOf = (path: string) => {","atom":"a1447","author":"speed","version":150},{"n":61,"text":"\tconst cut = path.lastIndexOf(\"/\");","atom":"a1447","author":"speed","version":150},{"n":62,"text":"\treturn cut < 0 ? \"\" : path.slice(0, cut);","atom":"a1447","author":"speed","version":150},{"n":63,"text":"};","atom":"a1447","author":"speed","version":150},{"n":64,"text":"","atom":"a1447","author":"speed","version":150},{"n":65,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":66,"text":" * The tree for `files`, written bottom up. A folder with nothing changed under it keeps its old tree oid (`before`),","atom":"a1447","author":"speed","version":150},{"n":67,"text":" * so only the folders on a changed path are written again.","atom":"a1447","author":"speed","version":150},{"n":68,"text":" */","atom":"a1447","author":"speed","version":150},{"n":69,"text":"export async function writeTrees(","atom":"a1447","author":"speed","version":150},{"n":70,"text":"\tfs: MemoryFS,","atom":"a1447","author":"speed","version":150},{"n":71,"text":"\tdir: string,","atom":"a1447","author":"speed","version":150},{"n":72,"text":"\tfiles: Map<string, TreeFile>,","atom":"a1447","author":"speed","version":150},{"n":73,"text":"\tbefore: Map<string, string>,","atom":"a1447","author":"speed","version":150},{"n":74,"text":"\tchanged: Set<string>,","atom":"a1447","author":"speed","version":150},{"n":75,"text":"): Promise<string> {","atom":"a1447","author":"speed","version":150},{"n":76,"text":"\tconst dirty = new Set<string>([\"\"]);","atom":"a1447","author":"speed","version":150},{"n":77,"text":"\tfor (const path of changed) for (let d = parentOf(path); d !== \"\"; d = parentOf(d)) dirty.add(d);","atom":"a1447","author":"speed","version":150},{"n":78,"text":"\ttype Entry = { mode: string; oid: string; type: \"blob\" | \"tree\" };","atom":"a1447","author":"speed","version":150},{"n":79,"text":"\tconst kids = new Map<string, Map<string, Entry>>([[\"\", new Map()]]);","atom":"a1447","author":"speed","version":150},{"n":80,"text":"\tconst folder = (d: string) => {","atom":"a1447","author":"speed","version":150},{"n":81,"text":"\t\tlet k = kids.get(d);","atom":"a1447","author":"speed","version":150},{"n":82,"text":"\t\tif (!k) {","atom":"a1447","author":"speed","version":150},{"n":83,"text":"\t\t\tkids.set(d, (k = new Map()));","atom":"a1447","author":"speed","version":150},{"n":84,"text":"\t\t\tif (d !== \"\") folder(parentOf(d));","atom":"a1447","author":"speed","version":150},{"n":85,"text":"\t\t}","atom":"a1447","author":"speed","version":150},{"n":86,"text":"\t\treturn k;","atom":"a1447","author":"speed","version":150},{"n":87,"text":"\t};","atom":"a1447","author":"speed","version":150},{"n":88,"text":"\tfor (const [path, f] of files)","atom":"a1447","author":"speed","version":150},{"n":89,"text":"\t\tfolder(parentOf(path)).set(path.slice(path.lastIndexOf(\"/\") + 1), { ...f, type: \"blob\" });","atom":"a1447","author":"speed","version":150},{"n":90,"text":"\t// Deepest first, so a folder's subfolders have their oids before it is written.","atom":"a1447","author":"speed","version":150},{"n":91,"text":"\tconst depth = (d: string) => (d === \"\" ? 0 : d.split(\"/\").length);","atom":"a1447","author":"speed","version":150},{"n":92,"text":"\tconst order = [...kids.keys()].sort((a, b) => depth(b) - depth(a));","atom":"a1447","author":"speed","version":150},{"n":93,"text":"\tlet root = \"\";","atom":"a1447","author":"speed","version":150},{"n":94,"text":"\tfor (const d of order) {","atom":"a1447","author":"speed","version":150},{"n":95,"text":"\t\tconst old = before.get(d);","atom":"a1447","author":"speed","version":150},{"n":96,"text":"\t\tconst oid =","atom":"a1447","author":"speed","version":150},{"n":97,"text":"\t\t\told !== undefined && !dirty.has(d)","atom":"a1447","author":"speed","version":150},{"n":98,"text":"\t\t\t\t? old","atom":"a1447","author":"speed","version":150},{"n":99,"text":"\t\t\t\t: await git.writeTree({ fs, dir, tree: [...kids.get(d)!].map(([path, e]) => ({ path, ...e })) });","atom":"a1447","author":"speed","version":150},{"n":100,"text":"\t\tif (d === \"\") root = oid;","atom":"a1447","author":"speed","version":150},{"n":101,"text":"\t\telse folder(parentOf(d)).set(d.slice(d.lastIndexOf(\"/\") + 1), { mode: \"040000\", oid, type: \"tree\" });","atom":"a1447","author":"speed","version":150},{"n":102,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":103,"text":"\treturn root;","atom":"a1447","author":"speed","version":150},{"n":104,"text":"}","atom":"a1447","author":"speed","version":150},{"n":105,"text":"","atom":"a1447","author":"speed","version":150},{"n":106,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":107,"text":" * A project's Artifacts repo: abso-<project>. Project names are letters, digits, \".\", \"_\" and \"-\" (validName), which","atom":"a1447","author":"speed","version":150},{"n":108,"text":" * repo names take as they are.","atom":"a1447","author":"speed","version":150},{"n":109,"text":" */","atom":"a1447","author":"speed","version":150},{"n":110,"text":"export function repoName(project: string): string {","atom":"a1447","author":"speed","version":150},{"n":111,"text":"\treturn `abso-${project}`;","atom":"a1447","author":"speed","version":150},{"n":112,"text":"}","atom":"a1447","author":"speed","version":150},{"n":113,"text":"","atom":"a1447","author":"speed","version":150},{"n":114,"text":"/** The project one of our repos holds, or null for a repo that isn't ours. */","atom":"a1447","author":"speed","version":150},{"n":115,"text":"export function projectOfRepo(repo: string): string | null {","atom":"a1447","author":"speed","version":150},{"n":116,"text":"\treturn repo.startsWith(\"abso-\") && repo.length > \"abso-\".length ? repo.slice(\"abso-\".length) : null;","atom":"a1447","author":"speed","version":150},{"n":117,"text":"}","atom":"a1447","author":"speed","version":150},{"n":118,"text":"","atom":"a1447","author":"speed","version":150},{"n":119,"text":"/** The repo's remote and a write token good for `seconds`, creating the repo if it's new. */","atom":"a1447","author":"speed","version":150},{"n":120,"text":"export async function writeAccess(","atom":"a1447","author":"speed","version":150},{"n":121,"text":"\tartifacts: Artifacts,","atom":"a1447","author":"speed","version":150},{"n":122,"text":"\tname: string,","atom":"a1447","author":"speed","version":150},{"n":123,"text":"\tseconds = 600,","atom":"a1447","author":"speed","version":150},{"n":124,"text":"): Promise<{ remote: string; secret: string }> {","atom":"a1447","author":"speed","version":150},{"n":125,"text":"\ttry {","atom":"a1447","author":"speed","version":150},{"n":126,"text":"\t\tusing repo = await artifacts.get(name);","atom":"a1447","author":"speed","version":150},{"n":127,"text":"\t\tconst [info, token] = await Promise.all([repo.info(), repo.createToken(\"write\", seconds)]);","atom":"a1447","author":"speed","version":150},{"n":128,"text":"\t\treturn { remote: info!.remote, secret: token.plaintext.split(\"?expires=\")[0]! };","atom":"a1447","author":"speed","version":150},{"n":129,"text":"\t} catch {","atom":"a1447","author":"speed","version":150},{"n":130,"text":"\t\tconst created = await artifacts.create(name, { description: `abso project ${name}`, setDefaultBranch: \"main\" });","atom":"a1447","author":"speed","version":150},{"n":131,"text":"\t\treturn { remote: created.remote, secret: created.token.split(\"?expires=\")[0]! };","atom":"a1447","author":"speed","version":150},{"n":132,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":133,"text":"}","atom":"a1447","author":"speed","version":150},{"n":134,"text":"","atom":"a1447","author":"speed","version":150},{"n":135,"text":"export interface SharedFiles {","atom":"a1447","author":"speed","version":150},{"n":136,"text":"\tversion: number;","atom":"a1447","author":"speed","version":150},{"n":137,"text":"\tfiles: Record<string, string>;","atom":"a1447","author":"speed","version":150},{"n":138,"text":"\tmodes?: FileModes;","atom":"a1447","author":"speed","version":150},{"n":139,"text":"\tblobs?: Record<string, string>;","atom":"a1447","author":"speed","version":150},{"n":140,"text":"\tlast?: { agent: string; message: string };","atom":"a1447","author":"speed","version":150},{"n":141,"text":"}","atom":"a1447","author":"speed","version":150},{"n":142,"text":"","atom":"a1447","author":"speed","version":150},{"n":143,"text":"/**","atom":"a1447","author":"speed","version":150},{"n":144,"text":" * Shared's files as commits on top of `head` (null: a repo with no main yet), in the repo at `dir`. `part` is called","atom":"a1447","author":"speed","version":150},{"n":145,"text":" * with each earlier part's commit when the new blobs are too big for one push. Answers the last commit and how many","atom":"a1447","author":"speed","version":150},{"n":146,"text":" * paths changed.","atom":"a1447","author":"speed","version":150},{"n":147,"text":" */","atom":"a1447","author":"speed","version":150},{"n":148,"text":"export async function commitShared(","atom":"a1447","author":"speed","version":150},{"n":149,"text":"\tfs: MemoryFS,","atom":"a1447","author":"speed","version":150},{"n":150,"text":"\tdir: string,","atom":"a1447","author":"speed","version":150},{"n":151,"text":"\thead: string | null,","atom":"a1447","author":"speed","version":150},{"n":152,"text":"\tshared: SharedFiles,","atom":"a1447","author":"speed","version":150},{"n":153,"text":"\treadBlob: (sha256: string) => Uint8Array | null,","atom":"a1447","author":"speed","version":150},{"n":154,"text":"\tpart: (commit: string) => Promise<void> = async () => {},","atom":"a1447","author":"speed","version":150},{"n":155,"text":"): Promise<{ commit: string; changed: number }> {","atom":"a1447","author":"speed","version":150},{"n":156,"text":"\tconst old = head","atom":"a1447","author":"speed","version":150},{"n":157,"text":"\t\t? await readTreeFiles(fs, dir, (await git.readCommit({ fs, dir, oid: head })).commit.tree)","atom":"a1447","author":"speed","version":150},{"n":158,"text":"\t\t: { files: new Map<string, TreeFile>(), trees: new Map<string, string>() };","atom":"a1447","author":"speed","version":150},{"n":159,"text":"\tconst blobs = shared.blobs ?? {};","atom":"a1447","author":"speed","version":150},{"n":160,"text":"\tconst now = new Map<string, TreeFile>();","atom":"a1447","author":"speed","version":150},{"n":161,"text":"\tconst changed = new Set<string>();","atom":"a1447","author":"speed","version":150},{"n":162,"text":"\tfor (const path of old.files.keys()) if (!(path in shared.files) && !(path in blobs)) changed.add(path);","atom":"a1447","author":"speed","version":150},{"n":163,"text":"\t// A file whose blob and mode match the last push keeps its entry; only a new blob is compressed and written.","atom":"a1447","author":"speed","version":150},{"n":164,"text":"\tconst put = async (path: string, bytes: Uint8Array, mode: string, oid: string) => {","atom":"a1447","author":"speed","version":150},{"n":165,"text":"\t\tconst was = old.files.get(path);","atom":"a1447","author":"speed","version":150},{"n":166,"text":"\t\tif (was?.oid !== oid) await git.writeBlob({ fs, dir, blob: bytes });","atom":"a1447","author":"speed","version":150},{"n":167,"text":"\t\tif (was?.oid !== oid || was.mode !== mode) changed.add(path);","atom":"a1447","author":"speed","version":150},{"n":168,"text":"\t\tnow.set(path, { oid, mode });","atom":"a1447","author":"speed","version":150},{"n":169,"text":"\t};","atom":"a1447","author":"speed","version":150},{"n":170,"text":"\t// Each file goes into the tree as a blob with its mode (#27): 100755 for exec, 120000 for a link, whose blob is","atom":"a1447","author":"speed","version":150},{"n":171,"text":"\t// its target.","atom":"a1447","author":"speed","version":150},{"n":172,"text":"\tconst enc = new TextEncoder();","atom":"a1447","author":"speed","version":150},{"n":173,"text":"\tfor (const [path, text] of Object.entries(shared.files)) {","atom":"a1447","author":"speed","version":150},{"n":174,"text":"\t\tconst mode = shared.modes?.[path];","atom":"a1447","author":"speed","version":150},{"n":175,"text":"\t\tconst link = typeof mode?.link === \"string\" ? mode.link : null;","atom":"a1447","author":"speed","version":150},{"n":176,"text":"\t\tconst bytes = enc.encode(link ?? text);","atom":"a1447","author":"speed","version":150},{"n":177,"text":"\t\tawait put(path, bytes, link !== null ? \"120000\" : mode?.exec ? \"100755\" : \"100644\", await blobOid(bytes));","atom":"a1447","author":"speed","version":150},{"n":178,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":179,"text":"\tconst agent = shared.last?.agent ?? \"abso\";","atom":"a1447","author":"speed","version":150},{"n":180,"text":"\tconst author = { name: agent, email: `${agent}@abso.invalid` };","atom":"a1447","author":"speed","version":150},{"n":181,"text":"\tconst committer = { name: \"abso\", email: \"abso@abso.invalid\" };","atom":"a1447","author":"speed","version":150},{"n":182,"text":"\tconst say = (p: string) => `${shared.last?.message ?? \"Start the project\"}${p}\\n\\nabso-version: ${shared.version}\\n`;","atom":"a1447","author":"speed","version":150},{"n":183,"text":"\tlet parent = head;","atom":"a1447","author":"speed","version":150},{"n":184,"text":"\t// A part holds what's written so far, and the last push's entries for the binary files not reached yet.","atom":"a1447","author":"speed","version":150},{"n":185,"text":"\tconst commitNow = async (message: string) => {","atom":"a1447","author":"speed","version":150},{"n":186,"text":"\t\tconst files = new Map(now);","atom":"a1447","author":"speed","version":150},{"n":187,"text":"\t\tfor (const [path, f] of old.files) if (!files.has(path) && path in blobs) files.set(path, f);","atom":"a1447","author":"speed","version":150},{"n":188,"text":"\t\tconst tree = await writeTrees(fs, dir, files, old.trees, changed);","atom":"a1447","author":"speed","version":150},{"n":189,"text":"\t\tparent = await git.commit({","atom":"a1447","author":"speed","version":150},{"n":190,"text":"\t\t\tfs,","atom":"a1447","author":"speed","version":150},{"n":191,"text":"\t\t\tdir,","atom":"a1447","author":"speed","version":150},{"n":192,"text":"\t\t\tmessage,","atom":"a1447","author":"speed","version":150},{"n":193,"text":"\t\t\tauthor,","atom":"a1447","author":"speed","version":150},{"n":194,"text":"\t\t\tcommitter,","atom":"a1447","author":"speed","version":150},{"n":195,"text":"\t\t\ttree,","atom":"a1447","author":"speed","version":150},{"n":196,"text":"\t\t\tparent: parent ? [parent] : [],","atom":"a1447","author":"speed","version":150},{"n":197,"text":"\t\t\tref: \"main\",","atom":"a1447","author":"speed","version":150},{"n":198,"text":"\t\t});","atom":"a1447","author":"speed","version":150},{"n":199,"text":"\t\treturn parent;","atom":"a1447","author":"speed","version":150},{"n":200,"text":"\t};","atom":"a1447","author":"speed","version":150},{"n":201,"text":"\t// Binary files (#27) aren't in files: their bytes come from the blob store.","atom":"a1447","author":"speed","version":150},{"n":202,"text":"\t// Artifacts refuses a push much over 20 MB, so when the new blobs add up","atom":"a1447","author":"speed","version":150},{"n":203,"text":"\t// to more than PUSH_BATCH, the earlier ones go in commits of their own","atom":"a1447","author":"speed","version":150},{"n":204,"text":"\t// first. Every part carries abso-version, so intake never takes them in.","atom":"a1447","author":"speed","version":150},{"n":205,"text":"\tlet pending = 0;","atom":"a1447","author":"speed","version":150},{"n":206,"text":"\tlet parts = 0;","atom":"a1447","author":"speed","version":150},{"n":207,"text":"\tfor (const [path, sha] of Object.entries(blobs)) {","atom":"a1447","author":"speed","version":150},{"n":208,"text":"\t\tconst bytes = readBlob(sha);","atom":"a1447","author":"speed","version":150},{"n":209,"text":"\t\tif (!bytes) throw new Error(`${path}: blob ${sha} is missing from the project's store`);","atom":"a1447","author":"speed","version":150},{"n":210,"text":"\t\tconst oid = await blobOid(bytes);","atom":"a1447","author":"speed","version":150},{"n":211,"text":"\t\tconst fresh = old.files.get(path)?.oid !== oid;","atom":"a1447","author":"speed","version":150},{"n":212,"text":"\t\tif (fresh && pending > 0 && pending + bytes.byteLength > PUSH_BATCH) {","atom":"a1447","author":"speed","version":150},{"n":213,"text":"\t\t\tawait part(await commitNow(say(` (part ${++parts})`)));","atom":"a1447","author":"speed","version":150},{"n":214,"text":"\t\t\tpending = 0;","atom":"a1447","author":"speed","version":150},{"n":215,"text":"\t\t}","atom":"a1447","author":"speed","version":150},{"n":216,"text":"\t\tif (fresh) pending += bytes.byteLength;","atom":"a1447","author":"speed","version":150},{"n":217,"text":"\t\tawait put(path, bytes, shared.modes?.[path]?.exec ? \"100755\" : \"100644\", oid);","atom":"a1447","author":"speed","version":150},{"n":218,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":219,"text":"\tconst commit = await commitNow(say(parts > 0 ? ` (part ${parts + 1}, last)` : \"\"));","atom":"a1447","author":"speed","version":150},{"n":220,"text":"\treturn { commit, changed: changed.size };","atom":"a1447","author":"speed","version":150},{"n":221,"text":"}","atom":"a1447","author":"speed","version":150},{"n":222,"text":"","atom":"a1447","author":"speed","version":150},{"n":223,"text":"export async function pushShared(","atom":"a1447","author":"speed","version":150},{"n":224,"text":"\tartifacts: Artifacts,","atom":"a1447","author":"speed","version":150},{"n":225,"text":"\tproject: string,","atom":"a1447","author":"speed","version":150},{"n":226,"text":"\tshared: SharedFiles,","atom":"a1447","author":"speed","version":150},{"n":227,"text":"\t/** A binary file's bytes by SHA-256 (#27), from the project's blob store. */","atom":"a1447","author":"speed","version":150},{"n":228,"text":"\treadBlob: (sha256: string) => Uint8Array | null = () => null,","atom":"a1447","author":"speed","version":150},{"n":229,"text":"): Promise<PushResult> {","atom":"a1447","author":"speed","version":150},{"n":230,"text":"\tconst t0 = Date.now();","atom":"a1447","author":"speed","version":150},{"n":231,"text":"\tconst name = repoName(project);","atom":"a1447","author":"speed","version":150},{"n":232,"text":"\tconst { remote, secret } = await writeAccess(artifacts, name);","atom":"a1447","author":"speed","version":150},{"n":233,"text":"\tconst onAuth = () => ({ username: \"x\", password: secret });","atom":"a1447","author":"speed","version":150},{"n":234,"text":"\tlet fs = new MemoryFS();","atom":"a1447","author":"speed","version":150},{"n":235,"text":"\tconst dir = \"/repo\";","atom":"a1447","author":"speed","version":150},{"n":236,"text":"\t// A new repo has no main yet. isomorphic-git \"clones\" an empty repo without","atom":"a1447","author":"speed","version":150},{"n":237,"text":"\t// an error but leaves HEAD on master, so check for main and start clean.","atom":"a1447","author":"speed","version":150},{"n":238,"text":"\t// Nothing is checked out: the new tree is built from tree objects (293).","atom":"a1447","author":"speed","version":150},{"n":239,"text":"\tconst head = await git","atom":"a1447","author":"speed","version":150},{"n":240,"text":"\t\t.clone({ fs, http, dir, url: remote, ref: \"main\", singleBranch: true, depth: 1, noCheckout: true, onAuth })","atom":"a1447","author":"speed","version":150},{"n":241,"text":"\t\t.then(() => git.resolveRef({ fs, dir, ref: \"main\" }))","atom":"a1447","author":"speed","version":150},{"n":242,"text":"\t\t.catch(() => null);","atom":"a1447","author":"speed","version":150},{"n":243,"text":"\tif (head === null) {","atom":"a1447","author":"speed","version":150},{"n":244,"text":"\t\tfs = new MemoryFS();","atom":"a1447","author":"speed","version":150},{"n":245,"text":"\t\tawait git.init({ fs, dir, defaultBranch: \"main\" });","atom":"a1447","author":"speed","version":150},{"n":246,"text":"\t}","atom":"a1447","author":"speed","version":150},{"n":247,"text":"\tconst t1 = Date.now();","atom":"a1447","author":"speed","version":150},{"n":248,"text":"\tconst push = () => git.push({ fs, http, dir, url: remote, ref: \"main\", remoteRef: \"main\", onAuth });","atom":"a1447","author":"speed","version":150},{"n":249,"text":"\tconst { commit, changed } = await commitShared(fs, dir, head, shared, readBlob, async () => void (await push()));","atom":"a1447","author":"speed","version":150},{"n":250,"text":"\tconst t2 = Date.now();","atom":"a1447","author":"speed","version":150},{"n":251,"text":"\tawait push();","atom":"a1447","author":"speed","version":150},{"n":252,"text":"\tconsole.log(","atom":"a1447","author":"speed","version":150},{"n":253,"text":"\t\t`push ${project} v${shared.version}: clone ${t1 - t0} ms, files ${t2 - t1} ms (${changed} changed), push ${Date.now() - t2} ms`,","atom":"a1447","author":"speed","version":150},{"n":254,"text":"\t);","atom":"a1447","author":"speed","version":150},{"n":255,"text":"\treturn { repo: name, remote, commit, version: shared.version, ms: Date.now() - t0 };","atom":"a1447","author":"speed","version":150},{"n":256,"text":"}","atom":"a1447","author":"speed","version":150}],"atoms":[{"atom":"a1447","author":"speed","message":"","time":1791906675188,"timeIso":"2026-10-13T15:51:15.188Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}}]}