Lines 2–18 at 318 (were 2–13 at 175)
22// project's Artifacts repo, read back for project.ingest. Every commit the 33// Worker pushes ends "abso-version: N" ("avcs-version: N" before the rename); the commits above the newest such 44// commit that haven't been taken in yet are the person's, and N is their base. 5−import git from "isomorphic-git";
6−import http from "isomorphic-git/http/web";
5+import git, { type HttpClient } from "isomorphic-git"; 76import type { FileModes } from "../../worker/project/project-api.ts"; 7+import type { SqliteStorage } from "./engine-project.ts"; 8+import { gitBlobText, InvalidGitUtf8 } from "./git-blob-text.ts"; 9+import { GitDiskIntake } from "./git-disk-intake.ts"; 10+import { gitHttp } from "./git-http.ts"; 811import { MemoryFS } from "./memory-fs.ts"; 912import { repoName } from "./push.ts"; 14+const http = gitHttp(); 1116const EXEC = 0o100755; 1217const LINK = 0o120000; Lines 45–54 at 318 (were 40–46 at 175)
4045async function readAccess( 4146 artifacts: Artifacts, 43−): Promise<{ url: string; onAuth: () => { username: string; password: string } } | null> {
50+ onAuth: () => { username: string; password: string }; 4452 let repo: Awaited<ReturnType<Artifacts["get"]>>; 4654 repo = await artifacts.get(repoName(project)); Lines 65–76 at 318 (were 57–63 at 175)
5765export async function remoteHead(artifacts: Artifacts, project: string): Promise<string | null> { 5866 const access = await readAccess(artifacts, project); 5967 if (!access) return null; 60− const refs = await git.listServerRefs({ http, url: access.url, onAuth: access.onAuth, prefix: "refs/heads/main" });
68+ const refs = await git.listServerRefs({ 71+ onAuth: access.onAuth, 72+ prefix: "refs/heads/main", 6174 return refs.find((r) => r.ref === "refs/heads/main")?.oid ?? null; Lines 80–91 at 318 (were 67–72 at 175)
6881/** Stores a binary file's bytes and answers their SHA-256, or null when they're over the limit. */ 6982export type StoreBlob = (bytes: Uint8Array) => Promise<string | null>; 83+export type RetainFileChunks = ( 84+ files: Record<string, string>, 86+ chunks: Iterable<string>, 7291 * `oldBlob` gives shared's blob for a path: a binary file over the limit Lines 97–132 at 318 (were 78–91 at 175)
7897 seen: string | undefined, 7998 storeBlob?: StoreBlob, 8099 oldBlob: (path: string) => string | undefined = () => undefined, 100+ retainFile: (files: Record<string, string>, path: string, body: string, oid?: string) => void = ( 108+ storage: SqliteStorage; 109+ maxPackBytes: number; 110+ maxObjectBytes: number; 111+ maxDecodedBytes?: number; 112+ maxBinaryBytes?: number; 114+ retainFileChunks?: RetainFileChunks; 81116): Promise<PushedCommits | null> { 82117 const access = await readAccess(artifacts, project); 83118 if (!access) return null; 84119 const fs = new MemoryFS(); 85120 const dir = "/repo"; 122+ ? new GitDiskIntake(disk.storage, disk.maxPackBytes, disk.maxObjectBytes, disk.maxDecodedBytes) 124+ const cache = disk ? {} : undefined; 125+ if (intake && cache) intake.attach(cache); 88− http,
129+ http: disk?.http ?? http, 91132 onAuth: access.onAuth, Lines 135–142 at 318 (were 94–100 at 175)
97− const log = await git.log({ fs, dir, ref: "main", depth: DEPTH });
138+ intake?.assertReady(); 139+ const log = await git.log({ fs, dir, cache, ref: "main", depth: DEPTH }); 98140 if (log.length === 0) return null; 99141 const head = log[0]!.oid; 100142 const fresh: typeof log = []; Lines 155–181 at 318 (were 113–121 at 175)
115157 message: c.commit.message.trim(), 116− ...(await treeText(fs, dir, c.oid, storeBlob, tooBig, oldBlob)),
168+ disk?.retainFileChunks, 169+ disk?.maxBinaryBytes, 118− return { head, author: fresh.at(-1)?.commit.author.name ?? "git", base, commits, tooBig: [...tooBig] };
174+ author: fresh.at(-1)?.commit.author.name ?? "git", 177+ tooBig: [...tooBig], Lines 183–248 at 318 (were 123–146 at 175)
123183 * a link (120000) is "" with its target in modes. Files that aren't UTF-8 126−async function treeText(
186+export async function treeText( 130190 storeBlob: StoreBlob | undefined, 131191 tooBig: Set<string>, 132192 oldBlob: (path: string) => string | undefined, 133−): Promise<{ files: Record<string, string>; modes: FileModes; blobs: Record<string, string> }> {
193+ retainFile: (files: Record<string, string>, path: string, body: string, oid?: string) => void, 195+ intake?: GitDiskIntake, 196+ retainFileChunks?: RetainFileChunks, 197+ maxBinaryBytes?: number, 199+ files: Record<string, string>; 201+ blobs: Record<string, string>; 134203 const files: Record<string, string> = {}; 135204 const modes: FileModes = {}; 136205 const blobs: Record<string, string> = {}; 140210 trees: [git.TREE({ ref: oid })], 211+ iterate: async (walk, children) => { 212+ for (const child of children) await walk(child); 215+ reduce: async () => undefined, 141216 map: async (path, [entry]) => { 142217 if (!entry || path === ".") return true; 143218 if ((await entry.type()) !== "blob") return true; 219+ const mode = await entry.mode(); 220+ const blobOid = await entry.oid(); 221+ if (intake && retainFileChunks && mode !== LINK) { 222+ const stored = intake.bytes(blobOid); 223+ if (stored?.type !== "blob") throw Error("Git intake blob is missing"); 226+ // Validate before retaining: a late invalid byte must take the binary path. 227+ for (const _ of gitBlobText(stored)) { 228+ /* Retain no decoded text. */ 231+ if (!(error instanceof InvalidGitUtf8)) throw error; 235+ retainFileChunks(files, path, gitBlobText(stored), blobOid); 236+ modes[path] = { exec: mode === EXEC, link: null }; 239+ if (storeBlob && maxBinaryBytes !== undefined && stored.byteLength > maxBinaryBytes) { 241+ const kept = oldBlob(path); 242+ if (kept) blobs[path] = kept; 144246 const bytes = await entry.content(); 145247 if (!bytes) return true; Lines 253–259 at 318 (were 151–157 at 175)
151253 const sha = storeBlob ? await storeBlob(bytes) : null; 153255 blobs[path] = sha; 154− modes[path] = { exec: (await entry.mode()) === EXEC, link: null };
256+ modes[path] = { exec: mode === EXEC, link: null }; 155257 } else if (storeBlob) { 157259 const kept = oldBlob(path); Lines 261–271 at 318 (were 159–170 at 175)
162− const mode = await entry.mode();
163264 if (mode === LINK) { 164− files[path] = "";
265+ retainFile(files, path, ""); 165266 modes[path] = { exec: false, link: body }; 167− files[path] = body;
268+ retainFile(files, path, body, blobOid); 168269 modes[path] = { exec: mode === EXEC, link: null };