{"draft":null,"from":49,"to":318,"files":[{"path":"server/scripts/capacity-patch-git-sideband.mjs","added":58,"removed":0,"diff":"--- /dev/null\n+++ b/server/scripts/capacity-patch-git-sideband.mjs\n@@ -0,0 +1,58 @@\n+import { createHash } from \"node:crypto\";\n+import { readFileSync, writeFileSync } from \"node:fs\";\n+import { join } from \"node:path\";\n+\n+const root = \"capacity-git-dependency-sandbox/node_modules/isomorphic-git\";\n+const inputs = {\n+\t\"index.js\": \"eebe6911fa660d4b95857768ea2308be74435dd5f9a796bb7b2491a31bdd109d\",\n+\t\"index.cjs\": \"33364e3ed7f3a1a6cf17a1ecabbfc5d6de6a8494f31a524d8ac293402ad4e447\",\n+};\n+const hash = (value) => createHash(\"sha256\").update(value).digest(\"hex\");\n+const queue = readFileSync(\"capacity-git-bounded-fifo.mjs\", \"utf8\").replace(\"export class\", \"class\");\n+function once(source, before, after) {\n+\tif (source.split(before).length !== 2) throw Error(`Sideband anchor mismatch: ${before}`);\n+\treturn source.replace(before, after);\n+}\n+const outputs = [];\n+for (const [file, expected] of Object.entries(inputs)) {\n+\tlet source = readFileSync(join(root, file), \"utf8\");\n+\tif (hash(source) !== expected) throw Error(`Unrecognized input: ${file}`);\n+\tsource = once(source, \"class GitSideBand {\", `${queue}\\nclass GitSideBand {`);\n+\tsource = once(source, \"  static demux(input) {\", \"  static demux(input, bounded = false) {\");\n+\tsource = once(\n+\t\tsource,\n+\t\t\"    const packfile = new FIFO();\",\n+\t\t\"    const packfile = bounded ? new BoundedPackFIFO(async () => { await getIterator(input).return?.(); }) : new FIFO();\",\n+\t);\n+\tsource = once(source, \"          packfile.write(line.slice(1));\", \"          await packfile.write(line.slice(1));\");\n+\tsource = once(\n+\t\tsource,\n+\t\t\"      nextBit();\\n    };\\n    nextBit();\",\n+\t\t`      return nextBit();\n+    };\n+    nextBit().catch(error => { packetlines.destroy(error); progress.destroy(error); packfile.destroy(error); });`,\n+\t);\n+\tsource = once(\n+\t\tsource,\n+\t\t\"async function parseUploadPackResponse(stream) {\\n  const { packetlines, packfile, progress } = GitSideBand.demux(stream);\",\n+\t\t\"async function parseUploadPackResponse(stream, bounded = false) {\\n  const { packetlines, packfile, progress } = GitSideBand.demux(stream, bounded);\",\n+\t);\n+\tsource = once(\n+\t\tsource,\n+\t\t\"  const response = await parseUploadPackResponse(raw.body);\",\n+\t\t\"  const response = await parseUploadPackResponse(raw.body, Boolean(cache && cache[Symbol.for('abso.git.disk-pack')]));\",\n+\t);\n+\toutputs.push({ file, source, sha256: hash(source) });\n+}\n+if (!process.argv.includes(\"--check\")) {\n+\tfor (const { file, source } of outputs) writeFileSync(join(root, file), source);\n+\twriteFileSync(\n+\t\t\"capacity-git-sideband-patch-manifest.json\",\n+\t\tJSON.stringify(\n+\t\t\toutputs.map(({ file, sha256 }) => ({ file, sha256 })),\n+\t\t\tnull,\n+\t\t\t2,\n+\t\t),\n+\t);\n+}\n+console.log(JSON.stringify(outputs.map(({ file, sha256 }) => ({ file, sha256 }))));"}],"unmatched":[]}