git-fs-s3 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/{chunk-XNSZTA4Y.js → chunk-HBOJR5D3.js} +108 -5
- package/dist/chunk-HBOJR5D3.js.map +1 -0
- package/dist/{chunk-FIFWOMPM.js → chunk-PASVUPKR.js} +64 -2
- package/dist/chunk-PASVUPKR.js.map +1 -0
- package/dist/chunk-ZB6GNJ2J.js +59 -0
- package/dist/chunk-ZB6GNJ2J.js.map +1 -0
- package/dist/http.js +294 -189
- package/dist/http.js.map +1 -1
- package/dist/index.js +79 -76
- package/dist/index.js.map +1 -1
- package/dist/ops.js +157 -22
- package/dist/ops.js.map +1 -1
- package/dist/types/edge-utils.d.ts +2 -0
- package/dist/types/http/reachability.d.ts +12 -0
- package/dist/types/http/receive-pack.d.ts +28 -9
- package/dist/types/http/upload-pack.d.ts +19 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/ops/commit.d.ts +9 -1
- package/dist/types/ops/index.d.ts +1 -0
- package/dist/types/ops/packed-writes.d.ts +9 -0
- package/dist/types/ops/tree.d.ts +9 -1
- package/dist/types/pack-write.d.ts +26 -0
- package/dist/types/refs.d.ts +9 -0
- package/package.json +2 -2
- package/dist/chunk-FIFWOMPM.js.map +0 -1
- package/dist/chunk-RMAOPWHJ.js +0 -38
- package/dist/chunk-RMAOPWHJ.js.map +0 -1
- package/dist/chunk-XNSZTA4Y.js.map +0 -1
package/README.md
CHANGED
|
@@ -218,14 +218,18 @@ export async function uploadPack(repo: Repo, request: Request) {
|
|
|
218
218
|
// POST .../git-receive-pack (push)
|
|
219
219
|
export async function receivePack(repo: Repo, request: Request) {
|
|
220
220
|
const body = new Uint8Array(await request.arrayBuffer());
|
|
221
|
-
const
|
|
221
|
+
const parsed = parseReceivePackBody(body);
|
|
222
|
+
const { results, stalePackPaths, unpackError } = await applyReceivePack(
|
|
222
223
|
repo,
|
|
223
|
-
|
|
224
|
+
parsed,
|
|
224
225
|
{ repack: { threshold: 4 } }, // or false to never auto-consolidate
|
|
225
226
|
);
|
|
226
227
|
// stalePackPaths were removed locally by the repack — delete them from any
|
|
227
228
|
// secondary storage this repo also lives in, same as you'd invalidate a cache.
|
|
228
|
-
const { status, headers, body: respBody } = receivePackResponse(results
|
|
229
|
+
const { status, headers, body: respBody } = receivePackResponse(results, {
|
|
230
|
+
capabilities: parsed.capabilities,
|
|
231
|
+
unpackError,
|
|
232
|
+
});
|
|
229
233
|
return new Response(respBody, { status, headers });
|
|
230
234
|
}
|
|
231
235
|
```
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
+
GitConflictError,
|
|
2
3
|
GitInvalidRequestError,
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
concat,
|
|
5
|
+
deflate,
|
|
6
|
+
encodeUtf8,
|
|
7
|
+
fromHex,
|
|
8
|
+
isSafeBranchName,
|
|
9
|
+
packFileName,
|
|
10
|
+
sha1,
|
|
11
|
+
toHex
|
|
12
|
+
} from "./chunk-PASVUPKR.js";
|
|
5
13
|
|
|
6
14
|
// src/ops/branch.ts
|
|
7
15
|
import git from "isomorphic-git";
|
|
@@ -106,10 +114,23 @@ async function createBranchFrom(repo, name, startPoint) {
|
|
|
106
114
|
assertSafeBranchName(name);
|
|
107
115
|
assertSafeBranchName(startPoint);
|
|
108
116
|
const object = await resolveLooseRefFast(repo, `refs/heads/${startPoint}`);
|
|
109
|
-
|
|
117
|
+
try {
|
|
118
|
+
await git.branch({ ...repo, ref: name, checkout: false, object });
|
|
119
|
+
} catch (err) {
|
|
120
|
+
if (err.code === "AlreadyExistsError") {
|
|
121
|
+
throw new GitConflictError(`Branch ${name} already exists`);
|
|
122
|
+
}
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
110
125
|
}
|
|
111
126
|
async function deleteBranchByName(repo, name) {
|
|
112
127
|
assertSafeBranchName(name);
|
|
128
|
+
const current = await getCurrentLooseBranch(repo) ?? await git.currentBranch({ ...repo, fullname: false }).catch(() => null);
|
|
129
|
+
if (current === name) {
|
|
130
|
+
throw new GitInvalidRequestError(
|
|
131
|
+
`Cannot delete ${name}: it is the default branch`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
113
134
|
await git.deleteBranch({ ...repo, ref: name });
|
|
114
135
|
}
|
|
115
136
|
async function assertBranchExists(repo, name) {
|
|
@@ -117,6 +138,82 @@ async function assertBranchExists(repo, name) {
|
|
|
117
138
|
await resolveLooseRefFast(repo, `refs/heads/${name}`);
|
|
118
139
|
}
|
|
119
140
|
|
|
141
|
+
// src/http/types.ts
|
|
142
|
+
var runStep = (hooks, label, fn) => hooks?.step ? hooks.step(label, fn) : fn();
|
|
143
|
+
function rawFs(repo) {
|
|
144
|
+
const fs = repo.fs;
|
|
145
|
+
if (!fs?.promises) {
|
|
146
|
+
throw new TypeError(
|
|
147
|
+
"This operation needs a promise fs (`fs.promises`) \u2014 node:fs and createGitFs both provide one"
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
return fs.promises;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/pack-write.ts
|
|
154
|
+
import git2 from "isomorphic-git";
|
|
155
|
+
var PACK_OBJECT_TYPE_BITS = {
|
|
156
|
+
commit: 16,
|
|
157
|
+
tree: 32,
|
|
158
|
+
blob: 48,
|
|
159
|
+
tag: 64
|
|
160
|
+
};
|
|
161
|
+
function encodePackObjectHeader(type, length) {
|
|
162
|
+
const bytes = [];
|
|
163
|
+
let more = length > 15;
|
|
164
|
+
bytes.push(
|
|
165
|
+
(more ? 128 : 0) | PACK_OBJECT_TYPE_BITS[type] | length & 15
|
|
166
|
+
);
|
|
167
|
+
let rest = Math.floor(length / 16);
|
|
168
|
+
while (more) {
|
|
169
|
+
more = rest > 127;
|
|
170
|
+
bytes.push((more ? 128 : 0) | rest & 127);
|
|
171
|
+
rest = Math.floor(rest / 128);
|
|
172
|
+
}
|
|
173
|
+
return new Uint8Array(bytes);
|
|
174
|
+
}
|
|
175
|
+
function hashGitObject(type, content) {
|
|
176
|
+
return sha1(concat(encodeUtf8(`${type} ${content.length}\0`), content));
|
|
177
|
+
}
|
|
178
|
+
async function encodePack(objects) {
|
|
179
|
+
const header = new Uint8Array(12);
|
|
180
|
+
const view = new DataView(header.buffer);
|
|
181
|
+
header.set(encodeUtf8("PACK"), 0);
|
|
182
|
+
view.setUint32(4, 2, false);
|
|
183
|
+
view.setUint32(8, objects.length, false);
|
|
184
|
+
const chunks = [header];
|
|
185
|
+
const BATCH_SIZE = 100;
|
|
186
|
+
for (let i = 0; i < objects.length; i += BATCH_SIZE) {
|
|
187
|
+
const encoded = await Promise.all(
|
|
188
|
+
objects.slice(i, i + BATCH_SIZE).map(
|
|
189
|
+
async (object) => concat(
|
|
190
|
+
encodePackObjectHeader(object.type, object.content.length),
|
|
191
|
+
await deflate(object.content)
|
|
192
|
+
)
|
|
193
|
+
)
|
|
194
|
+
);
|
|
195
|
+
chunks.push(...encoded);
|
|
196
|
+
}
|
|
197
|
+
const body = concat(...chunks);
|
|
198
|
+
return concat(body, fromHex(await sha1(body)));
|
|
199
|
+
}
|
|
200
|
+
function packBaseName(pack) {
|
|
201
|
+
return `pack-${toHex(pack.subarray(pack.length - 20))}`;
|
|
202
|
+
}
|
|
203
|
+
async function storePack(repo, pack) {
|
|
204
|
+
const fsp = rawFs(repo);
|
|
205
|
+
const packDir = `${repo.gitdir}/objects/pack`;
|
|
206
|
+
const base = packBaseName(pack);
|
|
207
|
+
await fsp.mkdir(packDir, { recursive: true });
|
|
208
|
+
await fsp.writeFile(`${packDir}/${packFileName(base, "pack")}`, pack);
|
|
209
|
+
const { oids } = await git2.indexPack({
|
|
210
|
+
...repo,
|
|
211
|
+
dir: packDir,
|
|
212
|
+
filepath: packFileName(base, "pack")
|
|
213
|
+
});
|
|
214
|
+
return { base, oids };
|
|
215
|
+
}
|
|
216
|
+
|
|
120
217
|
export {
|
|
121
218
|
assertSafeBranchName,
|
|
122
219
|
listLooseRefNames,
|
|
@@ -124,6 +221,12 @@ export {
|
|
|
124
221
|
listBranches,
|
|
125
222
|
createBranchFrom,
|
|
126
223
|
deleteBranchByName,
|
|
127
|
-
assertBranchExists
|
|
224
|
+
assertBranchExists,
|
|
225
|
+
runStep,
|
|
226
|
+
rawFs,
|
|
227
|
+
hashGitObject,
|
|
228
|
+
encodePack,
|
|
229
|
+
packBaseName,
|
|
230
|
+
storePack
|
|
128
231
|
};
|
|
129
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-HBOJR5D3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ops/branch.ts","../src/http/types.ts","../src/pack-write.ts"],"sourcesContent":["import git from \"isomorphic-git\";\nimport { GitConflictError, GitInvalidRequestError } from \"../git-errors.js\";\nimport { isSafeBranchName } from \"../refs.js\";\nimport type { Repo } from \"./types.js\";\n\nexport interface Branch {\n\tname: string;\n\tcommit: string;\n\tisDefault: boolean;\n}\n\n/**\n * Defense in depth for every branch-name argument below: `git.deleteBranch`\n * and raw resolveRef/writeRef reads don't validate ref names internally the\n * way `git.branch` does (see refs.ts) — guard at the point the primitives are\n * actually called, not just at an API boundary far above.\n */\nexport function assertSafeBranchName(name: string): void {\n\tif (!isSafeBranchName(name)) {\n\t\tthrow new GitInvalidRequestError(`Invalid branch name: ${name}`);\n\t}\n}\n\nconst FULL_SHA_RE = /^[0-9a-f]{40}$/i;\n\ntype RecursiveFileLister = {\n\tlistFilesRecursively(dirpath: string): Promise<string[]>;\n};\n\nfunction hasRecursiveFileLister(\n\tfs: Repo[\"fs\"],\n): fs is Repo[\"fs\"] & RecursiveFileLister {\n\treturn (\n\t\ttypeof fs === \"object\" &&\n\t\tfs !== null &&\n\t\t\"listFilesRecursively\" in fs &&\n\t\ttypeof (fs as Partial<RecursiveFileLister>).listFilesRecursively ===\n\t\t\t\"function\"\n\t);\n}\n\ntype PromisesFs = {\n\treadFile(path: string, encoding: \"utf8\"): Promise<string | Uint8Array>;\n};\n\n// Repo.fs is typed as isomorphic-git's own fs union (promise- or\n// callback-based) since that's what git.readTree's signature allows, but\n// every fs this package actually constructs (git-fs.ts) is promise-based —\n// this just keeps the callback-style branch honest instead of crashing on\n// it. Shared by every loose-ref fast path below instead of each repeating\n// the same cast + presence check.\nfunction getPromisesFs(fs: Repo[\"fs\"]): PromisesFs | null {\n\tconst promises = (fs as { promises?: PromisesFs }).promises;\n\treturn promises ?? null;\n}\n\nfunction decodeFileContent(content: string | Uint8Array): string {\n\treturn typeof content === \"string\"\n\t\t? content\n\t\t: new TextDecoder().decode(content);\n}\n\n/**\n * Lists loose branch names without isomorphic-git's recursive readdir/stat\n * traversal. Object stores already return only leaf keys in a recursive LIST,\n * so this is one request regardless of branch-name nesting. Ordinary\n * filesystems retain isomorphic-git's implementation and packed refs remain\n * supported there.\n */\nasync function listLooseBranches(repo: Repo): Promise<string[] | null> {\n\treturn listLooseRefNames(repo, \"refs/heads\");\n}\n\n/**\n * Loose ref names under `dir` (e.g. `refs/tags`) in one recursive listing,\n * or `null` when the fs can't list recursively (use isomorphic-git's walk).\n */\nexport async function listLooseRefNames(\n\trepo: Repo,\n\tdir: \"refs/heads\" | \"refs/tags\",\n): Promise<string[] | null> {\n\tif (!hasRecursiveFileLister(repo.fs)) return null;\n\tconst names = await repo.fs.listFilesRecursively(`${repo.gitdir}/${dir}`);\n\treturn names.filter(isSafeBranchName);\n}\n\n/** Read packed branch refs so the object-store fast path preserves Git semantics. */\nasync function readPackedBranches(repo: Repo): Promise<Map<string, string>> {\n\tif (!hasRecursiveFileLister(repo.fs)) return new Map();\n\tconst promisesFs = getPromisesFs(repo.fs);\n\tif (!promisesFs) return new Map();\n\ttry {\n\t\tconst content = await promisesFs.readFile(\n\t\t\t`${repo.gitdir}/packed-refs`,\n\t\t\t\"utf8\",\n\t\t);\n\t\tconst refs = new Map<string, string>();\n\t\tfor (const line of decodeFileContent(content).split(\"\\n\")) {\n\t\t\tconst match = /^([0-9a-f]{40}) refs\\/heads\\/(.+)$/i.exec(line);\n\t\t\tif (match?.[1] && match[2] && isSafeBranchName(match[2])) {\n\t\t\t\trefs.set(match[2], match[1]);\n\t\t\t}\n\t\t}\n\t\treturn refs;\n\t} catch {\n\t\treturn new Map();\n\t}\n}\n\n/** Read the symbolic HEAD directly when the object-store fs is available. */\nasync function getCurrentLooseBranch(repo: Repo): Promise<string | null> {\n\tif (!hasRecursiveFileLister(repo.fs)) return null;\n\tconst promisesFs = getPromisesFs(repo.fs);\n\tif (!promisesFs) return null;\n\ttry {\n\t\tconst content = await promisesFs.readFile(`${repo.gitdir}/HEAD`, \"utf8\");\n\t\tconst head = decodeFileContent(content).trim();\n\t\tconst match = /^ref: refs\\/heads\\/(.+)$/.exec(head);\n\t\treturn match?.[1] && isSafeBranchName(match[1]) ? match[1] : null;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Resolve a fully-qualified ref's oid with one read instead of isomorphic-\n * git's own `resolveRef`, which does a stat *then* a read for a loose ref\n * (two round trips against object storage) — wasteful specifically here,\n * where the caller already knows the ref exists (it came from a directory\n * listing moments earlier). Reads the loose file directly and falls back to\n * `git.resolveRef` only when that doesn't pan out (packed-refs, or anything\n * else the plain-loose-file assumption doesn't cover), so correctness for\n * those cases is unchanged — this only removes the redundant round trip on\n * the common path.\n */\nexport async function resolveLooseRefFast(\n\trepo: Repo,\n\tref: string,\n): Promise<string> {\n\tconst promisesFs = getPromisesFs(repo.fs);\n\tif (promisesFs) {\n\t\ttry {\n\t\t\tconst content = await promisesFs.readFile(\n\t\t\t\t`${repo.gitdir}/${ref}`,\n\t\t\t\t\"utf8\",\n\t\t\t);\n\t\t\tconst oid = decodeFileContent(content).trim();\n\t\t\tif (FULL_SHA_RE.test(oid)) return oid;\n\t\t} catch {\n\t\t\t// Not a loose file (packed-refs, or genuinely absent) — fall through.\n\t\t}\n\t}\n\treturn git.resolveRef({ ...repo, ref });\n}\n\n/** All branches with their tip commits; [] for an empty repository. */\nexport async function listBranches(repo: Repo): Promise<Branch[]> {\n\ttry {\n\t\tconst [looseBranches, looseCurrentBranch, packedBranches] =\n\t\t\tawait Promise.all([\n\t\t\t\tlistLooseBranches(repo),\n\t\t\t\tgetCurrentLooseBranch(repo),\n\t\t\t\treadPackedBranches(repo),\n\t\t\t]);\n\t\tconst branches =\n\t\t\tlooseBranches === null\n\t\t\t\t? await git.listBranches(repo)\n\t\t\t\t: [...new Set([...looseBranches, ...packedBranches.keys()])].sort();\n\t\tconst currentBranch =\n\t\t\tlooseBranches === null\n\t\t\t\t? await git\n\t\t\t\t\t\t.currentBranch({ ...repo, fullname: false })\n\t\t\t\t\t\t.catch(() => null)\n\t\t\t\t: looseCurrentBranch;\n\n\t\treturn Promise.all(\n\t\t\tbranches.map(async (branch) => {\n\t\t\t\tconst packedCommit = packedBranches.get(branch);\n\t\t\t\treturn {\n\t\t\t\t\tname: branch,\n\t\t\t\t\tcommit:\n\t\t\t\t\t\tpackedCommit && !looseBranches?.includes(branch)\n\t\t\t\t\t\t\t? packedCommit\n\t\t\t\t\t\t\t: await resolveLooseRefFast(repo, `refs/heads/${branch}`),\n\t\t\t\t\tisDefault: branch === currentBranch,\n\t\t\t\t};\n\t\t\t}),\n\t\t);\n\t} catch (err: unknown) {\n\t\tif ((err as { code?: string }).code === \"NotFoundError\") return [];\n\t\tthrow err;\n\t}\n}\n\n/** Create `name` pointing at the tip of `startPoint` (no checkout). */\nexport async function createBranchFrom(\n\trepo: Repo,\n\tname: string,\n\tstartPoint: string,\n): Promise<void> {\n\tassertSafeBranchName(name);\n\tassertSafeBranchName(startPoint);\n\tconst object = await resolveLooseRefFast(repo, `refs/heads/${startPoint}`);\n\ttry {\n\t\tawait git.branch({ ...repo, ref: name, checkout: false, object });\n\t} catch (err) {\n\t\tif ((err as { code?: string }).code === \"AlreadyExistsError\") {\n\t\t\tthrow new GitConflictError(`Branch ${name} already exists`);\n\t\t}\n\t\tthrow err;\n\t}\n}\n\n/** Delete a branch ref (validated — deleteBranch has no internal ref check). */\nexport async function deleteBranchByName(\n\trepo: Repo,\n\tname: string,\n): Promise<void> {\n\tassertSafeBranchName(name);\n\t// Same rule as receive-pack: deleting the branch HEAD names leaves every\n\t// clone without a default branch.\n\tconst current =\n\t\t(await getCurrentLooseBranch(repo)) ??\n\t\t(await git.currentBranch({ ...repo, fullname: false }).catch(() => null));\n\tif (current === name) {\n\t\tthrow new GitInvalidRequestError(\n\t\t\t`Cannot delete ${name}: it is the default branch`,\n\t\t);\n\t}\n\tawait git.deleteBranch({ ...repo, ref: name });\n}\n\n/** Throws (NotFoundError) unless the branch resolves. */\nexport async function assertBranchExists(\n\trepo: Repo,\n\tname: string,\n): Promise<void> {\n\tassertSafeBranchName(name);\n\tawait resolveLooseRefFast(repo, `refs/heads/${name}`);\n}\n","import type { Repo } from \"../ops/types.js\";\n\n/**\n * Transport-agnostic HTTP response the handlers produce.\n *\n * `body` is pinned to `Uint8Array<ArrayBuffer>` (not the bare `Uint8Array`,\n * whose default type argument isn't consistent across TypeScript versions)\n * so it's always assignable to Fetch API `BodyInit` regardless of which\n * TypeScript/lib version a consumer compiles against — every producer here\n * (`concat`, `pktLine`, `TextEncoder.encode`) is ArrayBuffer-backed already.\n */\nexport interface GitHttpResult {\n\tstatus: number;\n\theaders: Record<string, string>;\n\tbody: Uint8Array<ArrayBuffer>;\n}\n\n/** Optional instrumentation hooks shared by the /http handlers. */\nexport interface HttpHooks {\n\t/** Wrap a timed sub-step. Default: run directly. */\n\tstep?: <T>(label: string, fn: () => Promise<T>) => Promise<T>;\n\t/** Non-fatal problem sink (missing objects, failed repacks). */\n\tonWarn?: (message: string, error?: unknown) => void;\n}\n\nexport const runStep = <T>(\n\thooks: HttpHooks | undefined,\n\tlabel: string,\n\tfn: () => Promise<T>,\n): Promise<T> => (hooks?.step ? hooks.step(label, fn) : fn());\n\n/**\n * The raw promise-fs surface some /http paths need beyond isomorphic-git's\n * plumbing (writing an incoming pack file, listing/deleting pack files).\n * Both `node:fs` and this package's `GitFs` satisfy it via `.promises`.\n */\nexport interface RawFsPromises {\n\treadFile(path: string): Promise<Uint8Array | string>;\n\twriteFile(path: string, data: Uint8Array | string): Promise<void>;\n\tunlink(path: string): Promise<void>;\n\treaddir(path: string): Promise<string[]>;\n\tmkdir(path: string, options?: { recursive?: boolean }): Promise<unknown>;\n\tstat(path: string): Promise<unknown>;\n}\n\n/** Duck-type the `.promises` surface off a repo's fs. */\nexport function rawFs(repo: Repo): RawFsPromises {\n\tconst fs = repo.fs as { promises?: RawFsPromises };\n\tif (!fs?.promises) {\n\t\tthrow new TypeError(\n\t\t\t\"This operation needs a promise fs (`fs.promises`) — node:fs and createGitFs both provide one\",\n\t\t);\n\t}\n\treturn fs.promises;\n}\n","/**\n * Writing packfiles: serialize whole (never deltified) objects into a pack,\n * and store a pack plus its index in a repository. Shared by repack (the\n * loose-object fallback) and packed writes (ops/packed-writes.ts).\n *\n * Edge-compatible: Web Crypto SHA-1, CompressionStream, Uint8Array only.\n */\nimport git from \"isomorphic-git\";\nimport {\n\tconcat,\n\tdeflate,\n\tencodeUtf8,\n\tfromHex,\n\tsha1,\n\ttoHex,\n} from \"./edge-utils.js\";\nimport { rawFs } from \"./http/types.js\";\nimport type { Repo } from \"./ops/types.js\";\nimport { packFileName } from \"./pack-files.js\";\n\nexport type PackObjectType = \"commit\" | \"tree\" | \"blob\" | \"tag\";\n\n// Git pack object type bits (bits 6-4 of the header's first byte).\nconst PACK_OBJECT_TYPE_BITS: Record<PackObjectType, number> = {\n\tcommit: 0b0010000,\n\ttree: 0b0100000,\n\tblob: 0b0110000,\n\ttag: 0b1000000,\n};\n\n// First byte: continuation bit | 3-bit type | low 4 bits of length; the rest\n// of the length follows 7 bits at a time, little-endian.\nfunction encodePackObjectHeader(\n\ttype: PackObjectType,\n\tlength: number,\n): Uint8Array {\n\tconst bytes: number[] = [];\n\tlet more = length > 0b1111;\n\tbytes.push(\n\t\t(more ? 0b10000000 : 0) | PACK_OBJECT_TYPE_BITS[type] | (length & 0b1111),\n\t);\n\tlet rest = Math.floor(length / 16);\n\twhile (more) {\n\t\tmore = rest > 0b01111111;\n\t\tbytes.push((more ? 0b10000000 : 0) | (rest & 0b01111111));\n\t\trest = Math.floor(rest / 128);\n\t}\n\treturn new Uint8Array(bytes);\n}\n\n/** Git's object id: sha1(\"<type> <byte length>\\0<content>\"). */\nexport function hashGitObject(\n\ttype: string,\n\tcontent: Uint8Array,\n): Promise<string> {\n\treturn sha1(concat(encodeUtf8(`${type} ${content.length}\\0`), content));\n}\n\nexport interface PackObject {\n\ttype: PackObjectType;\n\tcontent: Uint8Array<ArrayBuffer>;\n}\n\n/** A version-2 pack holding `objects` as full entries, in order. */\nexport async function encodePack(\n\tobjects: readonly PackObject[],\n): Promise<Uint8Array<ArrayBuffer>> {\n\tconst header = new Uint8Array(12);\n\tconst view = new DataView(header.buffer);\n\theader.set(encodeUtf8(\"PACK\"), 0);\n\tview.setUint32(4, 2, false);\n\tview.setUint32(8, objects.length, false);\n\n\tconst chunks: Uint8Array[] = [header];\n\tconst BATCH_SIZE = 100;\n\tfor (let i = 0; i < objects.length; i += BATCH_SIZE) {\n\t\tconst encoded = await Promise.all(\n\t\t\tobjects\n\t\t\t\t.slice(i, i + BATCH_SIZE)\n\t\t\t\t.map(async (object) =>\n\t\t\t\t\tconcat(\n\t\t\t\t\t\tencodePackObjectHeader(object.type, object.content.length),\n\t\t\t\t\t\tawait deflate(object.content),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t);\n\t\tchunks.push(...encoded);\n\t}\n\t// The trailer is the SHA-1 of every preceding byte.\n\tconst body = concat(...chunks);\n\treturn concat(body, fromHex(await sha1(body)));\n}\n\n/**\n * A pack's conventional base name, `pack-<checksum>`: the trailer SHA-1 is a\n * function of the content, so two writers can never pick the same name for\n * different packs, and rewriting the same pack is idempotent.\n */\nexport function packBaseName(pack: Uint8Array): string {\n\treturn `pack-${toHex(pack.subarray(pack.length - 20))}`;\n}\n\n/**\n * Store `pack` in `repo` and index it (isomorphic-git's `indexPack`, which\n * re-hashes every object). The `.idx` is written last: a pack only becomes\n * visible to readers once its index exists. Returns the base name and the\n * oids the index lists.\n */\nexport async function storePack(\n\trepo: Repo,\n\tpack: Uint8Array,\n): Promise<{ base: string; oids: string[] }> {\n\tconst fsp = rawFs(repo);\n\tconst packDir = `${repo.gitdir}/objects/pack`;\n\tconst base = packBaseName(pack);\n\tawait fsp.mkdir(packDir, { recursive: true });\n\tawait fsp.writeFile(`${packDir}/${packFileName(base, \"pack\")}`, pack);\n\tconst { oids } = await git.indexPack({\n\t\t...repo,\n\t\tdir: packDir,\n\t\tfilepath: packFileName(base, \"pack\"),\n\t});\n\treturn { base, oids };\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,OAAO,SAAS;AAiBT,SAAS,qBAAqB,MAAoB;AACxD,MAAI,CAAC,iBAAiB,IAAI,GAAG;AAC5B,UAAM,IAAI,uBAAuB,wBAAwB,IAAI,EAAE;AAAA,EAChE;AACD;AAEA,IAAM,cAAc;AAMpB,SAAS,uBACR,IACyC;AACzC,SACC,OAAO,OAAO,YACd,OAAO,QACP,0BAA0B,MAC1B,OAAQ,GAAoC,yBAC3C;AAEH;AAYA,SAAS,cAAc,IAAmC;AACzD,QAAM,WAAY,GAAiC;AACnD,SAAO,YAAY;AACpB;AAEA,SAAS,kBAAkB,SAAsC;AAChE,SAAO,OAAO,YAAY,WACvB,UACA,IAAI,YAAY,EAAE,OAAO,OAAO;AACpC;AASA,eAAe,kBAAkB,MAAsC;AACtE,SAAO,kBAAkB,MAAM,YAAY;AAC5C;AAMA,eAAsB,kBACrB,MACA,KAC2B;AAC3B,MAAI,CAAC,uBAAuB,KAAK,EAAE,EAAG,QAAO;AAC7C,QAAM,QAAQ,MAAM,KAAK,GAAG,qBAAqB,GAAG,KAAK,MAAM,IAAI,GAAG,EAAE;AACxE,SAAO,MAAM,OAAO,gBAAgB;AACrC;AAGA,eAAe,mBAAm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IAAI,UAAU,GAAG,OAAO,IAAI,aAAa,MAAM,MAAM,CAAC,IAAI,IAAI;AACpE,QAAM,EAAE,KAAK,IAAI,MAAMC,KAAI,UAAU;AAAA,IACpC,GAAG;AAAA,IACH,KAAK;AAAA,IACL,UAAU,aAAa,MAAM,MAAM;AAAA,EACpC,CAAC;AACD,SAAO,EAAE,MAAM,KAAK;AACrB;","names":["git","git"]}
|
|
@@ -49,7 +49,15 @@ async function sha1(data) {
|
|
|
49
49
|
return toHex(new Uint8Array(hash));
|
|
50
50
|
}
|
|
51
51
|
async function deflate(data) {
|
|
52
|
-
const stream = new
|
|
52
|
+
const stream = new Response(data).body.pipeThrough(
|
|
53
|
+
new CompressionStream("deflate")
|
|
54
|
+
);
|
|
55
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
56
|
+
}
|
|
57
|
+
async function inflate(data) {
|
|
58
|
+
const stream = new Response(data).body.pipeThrough(
|
|
59
|
+
new DecompressionStream("deflate")
|
|
60
|
+
);
|
|
53
61
|
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
54
62
|
}
|
|
55
63
|
function hasNullByte(data) {
|
|
@@ -147,6 +155,17 @@ function formatErrorResponse(error) {
|
|
|
147
155
|
headers: error.statusCode === 401 ? { "WWW-Authenticate": 'Basic realm="Git Repository"' } : void 0
|
|
148
156
|
};
|
|
149
157
|
}
|
|
158
|
+
if (error?.code === "EUNAVAILABLE") {
|
|
159
|
+
return {
|
|
160
|
+
status: 503,
|
|
161
|
+
body: {
|
|
162
|
+
error: "ServiceUnavailable",
|
|
163
|
+
message: "Storage is temporarily unavailable",
|
|
164
|
+
retryable: true
|
|
165
|
+
},
|
|
166
|
+
headers: { "Retry-After": "30" }
|
|
167
|
+
};
|
|
168
|
+
}
|
|
150
169
|
if (error instanceof Error) {
|
|
151
170
|
return {
|
|
152
171
|
status: 500,
|
|
@@ -167,6 +186,36 @@ function formatErrorResponse(error) {
|
|
|
167
186
|
};
|
|
168
187
|
}
|
|
169
188
|
|
|
189
|
+
// src/pack-files.ts
|
|
190
|
+
var PACK_FILE_KINDS = [
|
|
191
|
+
"pack",
|
|
192
|
+
"idx",
|
|
193
|
+
"keep",
|
|
194
|
+
"bitmap",
|
|
195
|
+
"rev"
|
|
196
|
+
];
|
|
197
|
+
var READABLE_PACK_FILE_KINDS = /* @__PURE__ */ new Set([
|
|
198
|
+
"pack",
|
|
199
|
+
"idx"
|
|
200
|
+
]);
|
|
201
|
+
var KNOWN_KINDS = new Set(PACK_FILE_KINDS);
|
|
202
|
+
function isPackFileKind(value) {
|
|
203
|
+
return KNOWN_KINDS.has(value);
|
|
204
|
+
}
|
|
205
|
+
function parsePackFileName(name) {
|
|
206
|
+
const dot = name.lastIndexOf(".");
|
|
207
|
+
if (dot <= 0) return null;
|
|
208
|
+
const kind = name.slice(dot + 1);
|
|
209
|
+
if (!isPackFileKind(kind)) return null;
|
|
210
|
+
return { base: name.slice(0, dot), kind, name };
|
|
211
|
+
}
|
|
212
|
+
function packFileName(base, kind) {
|
|
213
|
+
return `${base}.${kind}`;
|
|
214
|
+
}
|
|
215
|
+
function parsePackDirectory(entries) {
|
|
216
|
+
return entries.map(parsePackFileName).filter((file) => file !== null);
|
|
217
|
+
}
|
|
218
|
+
|
|
170
219
|
// src/refs.ts
|
|
171
220
|
var BAD_REF_COMPONENT = (
|
|
172
221
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: control chars are exactly what git's own ref-name rules reject — this needs to match the same range.
|
|
@@ -197,6 +246,12 @@ function isSafeRepoPath(p) {
|
|
|
197
246
|
if (p.includes("\0")) return false;
|
|
198
247
|
return true;
|
|
199
248
|
}
|
|
249
|
+
function isSafeTreePath(p) {
|
|
250
|
+
if (!isSafeRepoPath(p) || p.length === 0) return false;
|
|
251
|
+
return p.split("/").every(
|
|
252
|
+
(segment) => segment.length > 0 && segment !== "." && segment !== ".." && segment.toLowerCase() !== ".git"
|
|
253
|
+
);
|
|
254
|
+
}
|
|
200
255
|
function qualifyBranchRef(ref) {
|
|
201
256
|
if (ref.startsWith("refs/") || ref === "HEAD" || FULL_SHA_RE.test(ref)) {
|
|
202
257
|
return ref;
|
|
@@ -214,6 +269,7 @@ export {
|
|
|
214
269
|
fromHex,
|
|
215
270
|
sha1,
|
|
216
271
|
deflate,
|
|
272
|
+
inflate,
|
|
217
273
|
hasNullByte,
|
|
218
274
|
readBlobContent,
|
|
219
275
|
GitError,
|
|
@@ -228,11 +284,17 @@ export {
|
|
|
228
284
|
GitInvalidRequestError,
|
|
229
285
|
GitProtocolError,
|
|
230
286
|
formatErrorResponse,
|
|
287
|
+
PACK_FILE_KINDS,
|
|
288
|
+
READABLE_PACK_FILE_KINDS,
|
|
289
|
+
parsePackFileName,
|
|
290
|
+
packFileName,
|
|
291
|
+
parsePackDirectory,
|
|
231
292
|
isSafeFullRefName,
|
|
232
293
|
isSafeBranchName,
|
|
233
294
|
isFullSha,
|
|
234
295
|
isSafeRefName,
|
|
235
296
|
isSafeRepoPath,
|
|
297
|
+
isSafeTreePath,
|
|
236
298
|
qualifyBranchRef
|
|
237
299
|
};
|
|
238
|
-
//# sourceMappingURL=chunk-
|
|
300
|
+
//# sourceMappingURL=chunk-PASVUPKR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/edge-utils.ts","../src/git-errors.ts","../src/pack-files.ts","../src/refs.ts"],"sourcesContent":["/**\n * Edge-compatible utilities replacing node:crypto, node:zlib, and Buffer.\n *\n * Every function here uses only Web APIs (SubtleCrypto, CompressionStream,\n * TextEncoder/TextDecoder) — no Node built-ins. They work on Cloudflare\n * Workers, Vercel Edge, Deno Deploy, and Node >= 18.\n */\n\nconst textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder();\n\n// ---------------------------------------------------------------------------\n// Text\n// ---------------------------------------------------------------------------\n\n/**\n * Encode a UTF-8 string to bytes.\n *\n * Return type pinned to `Uint8Array<ArrayBuffer>` (not the bare `Uint8Array`,\n * whose default type argument differs across TypeScript versions) so it's\n * always assignable to Fetch API `BodyInit` regardless of a consumer's own\n * TypeScript/lib version.\n */\nexport function encodeUtf8(data: string): Uint8Array<ArrayBuffer> {\n\treturn textEncoder.encode(data);\n}\n\n/** Decode bytes as UTF-8. */\nexport function decodeUtf8(data: Uint8Array): string {\n\treturn textDecoder.decode(data);\n}\n\n/** Decode bytes as ASCII. */\nexport function decodeAscii(data: Uint8Array): string {\n\tlet s = \"\";\n\tfor (let i = 0; i < data.length; i++)\n\t\ts += String.fromCharCode(data[i] as number);\n\treturn s;\n}\n\n// ---------------------------------------------------------------------------\n// Array manipulation\n// ---------------------------------------------------------------------------\n\n/** Concatenate any number of Uint8Arrays into one. */\nexport function concat(...parts: Uint8Array[]): Uint8Array<ArrayBuffer> {\n\tlet total = 0;\n\tfor (const p of parts) total += p.length;\n\tconst out = new Uint8Array(total);\n\tlet offset = 0;\n\tfor (const p of parts) {\n\t\tout.set(p, offset);\n\t\toffset += p.length;\n\t}\n\treturn out;\n}\n\n// ---------------------------------------------------------------------------\n// Encoding\n// ---------------------------------------------------------------------------\n\n/** Uint8Array → lowercase hex string. */\nexport function toHex(data: Uint8Array): string {\n\tlet hex = \"\";\n\tfor (let i = 0; i < data.length; i++)\n\t\thex += (data[i] as number).toString(16).padStart(2, \"0\");\n\treturn hex;\n}\n\n/** Uint8Array → base64 string. */\nexport function toBase64(data: Uint8Array): string {\n\tlet binary = \"\";\n\tfor (let i = 0; i < data.length; i++)\n\t\tbinary += String.fromCharCode(data[i] as number);\n\treturn btoa(binary);\n}\n\n/** Hex string → Uint8Array. */\nexport function fromHex(hex: string): Uint8Array<ArrayBuffer> {\n\tconst bytes = new Uint8Array(hex.length / 2);\n\tfor (let i = 0; i < bytes.length; i++) {\n\t\tbytes[i] = Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n\t}\n\treturn bytes;\n}\n\n// ---------------------------------------------------------------------------\n// Crypto\n// ---------------------------------------------------------------------------\n\n/** SHA-1 hash via Web Crypto API. Returns a hex string. */\nexport async function sha1(\n\tdata: Uint8Array<ArrayBuffer> | string,\n): Promise<string> {\n\tconst bytes = typeof data === \"string\" ? encodeUtf8(data) : data;\n\tconst hash = await globalThis.crypto.subtle.digest(\"SHA-1\", bytes);\n\treturn toHex(new Uint8Array(hash));\n}\n\n// ---------------------------------------------------------------------------\n// Compression\n// ---------------------------------------------------------------------------\n\n/** Deflate (zlib) via the CompressionStream Web API. */\nexport async function deflate(\n\tdata: Uint8Array<ArrayBuffer>,\n): Promise<Uint8Array<ArrayBuffer>> {\n\t// Response, not Blob.stream(): some Blob implementations (jsdom's) have\n\t// no stream().\n\tconst stream = (new Response(data).body as ReadableStream).pipeThrough(\n\t\tnew CompressionStream(\"deflate\"),\n\t);\n\treturn new Uint8Array(await new Response(stream).arrayBuffer());\n}\n\n/** Inflate (zlib) via the DecompressionStream Web API. */\nexport async function inflate(\n\tdata: Uint8Array<ArrayBuffer>,\n): Promise<Uint8Array<ArrayBuffer>> {\n\tconst stream = (new Response(data).body as ReadableStream).pipeThrough(\n\t\tnew DecompressionStream(\"deflate\"),\n\t);\n\treturn new Uint8Array(await new Response(stream).arrayBuffer());\n}\n\n// ---------------------------------------------------------------------------\n// Binary detection (replaces Buffer.includes(0) pattern)\n// ---------------------------------------------------------------------------\n\n/** Check if a Uint8Array contains a null byte. */\nexport function hasNullByte(data: Uint8Array): boolean {\n\treturn data.includes(0);\n}\n\n/**\n * Read a blob as text or binary metadata — the edge-compatible replacement\n * for the `Buffer.from(blob)` pattern used throughout diff.ts and history.ts.\n */\nexport function readBlobContent(blob: Uint8Array): {\n\tisBinary: boolean;\n\ttext: string;\n\tbytes: Uint8Array;\n} {\n\tconst isBinary = hasNullByte(blob);\n\treturn {\n\t\tisBinary,\n\t\ttext: isBinary ? \"\" : decodeUtf8(blob),\n\t\tbytes: blob,\n\t};\n}\n","/**\n * Git-server error types carrying an HTTP status and a retryability flag, so\n * transport layers can map internal failures to responses without inspecting\n * messages. Extend {@link GitError} for app-specific cases (storage backends,\n * quota, …) and {@link formatErrorResponse} keeps working for them.\n */\nexport class GitError extends Error {\n\tstatusCode: number;\n\tretryable: boolean;\n\n\tconstructor(message: string, statusCode = 500, retryable = false) {\n\t\tsuper(message);\n\t\tthis.name = this.constructor.name;\n\t\tthis.statusCode = statusCode;\n\t\tthis.retryable = retryable;\n\t\tError.captureStackTrace?.(this, this.constructor);\n\t}\n\n\ttoJSON(): Record<string, unknown> {\n\t\treturn {\n\t\t\terror: this.name,\n\t\t\tmessage: this.message,\n\t\t\tstatusCode: this.statusCode,\n\t\t\tretryable: this.retryable,\n\t\t};\n\t}\n}\n\n/** A file/directory path not found within a tree (404). */\nexport class GitPathNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\n/** A git object not found (404). */\nexport class GitObjectNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\n/** A ref (branch/tag) not found (404). */\nexport class GitRefNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\n/** The repository itself not found (404). */\nexport class GitRepositoryNotFoundError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 404, false);\n\t}\n}\n\nexport interface MergeConflictDetail {\n\tfile: string;\n\tbaseLines?: string[];\n\tsourceLines?: string[];\n\ttargetLines?: string[];\n}\n\n/** A merge conflict (409), carrying per-file conflict detail. */\nexport class GitConflictError extends GitError {\n\tconflicts: MergeConflictDetail[];\n\n\tconstructor(message: string, conflicts: MergeConflictDetail[] = []) {\n\t\tsuper(message, 409, false);\n\t\tthis.conflicts = conflicts;\n\t}\n\n\toverride toJSON(): Record<string, unknown> {\n\t\treturn { ...super.toJSON(), conflicts: this.conflicts };\n\t}\n}\n\n/** Authentication failed (401). */\nexport class GitAuthenticationError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 401, false);\n\t}\n}\n\n/** Authorization failed (403). */\nexport class GitAuthorizationError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 403, false);\n\t}\n}\n\n/** Too many failed attempts (429). */\nexport class GitRateLimitError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 429, false);\n\t}\n}\n\n/** Malformed request (400). */\nexport class GitInvalidRequestError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 400, false);\n\t}\n}\n\n/** Git wire-protocol violation (400). */\nexport class GitProtocolError extends GitError {\n\tconstructor(message: string) {\n\t\tsuper(message, 400, false);\n\t}\n}\n\n/**\n * Map any error to an HTTP response shape. 401s carry the WWW-Authenticate\n * header git clients need before they will prompt for credentials. Non-GitError\n * failures are masked as opaque 500s — internal messages don't leak.\n */\nexport function formatErrorResponse(error: unknown): {\n\tstatus: number;\n\tbody: Record<string, unknown>;\n\theaders?: Record<string, string>;\n} {\n\tif (error instanceof GitError) {\n\t\treturn {\n\t\t\tstatus: error.statusCode,\n\t\t\tbody: error.toJSON(),\n\t\t\theaders:\n\t\t\t\terror.statusCode === 401\n\t\t\t\t\t? { \"WWW-Authenticate\": 'Basic realm=\"Git Repository\"' }\n\t\t\t\t\t: undefined,\n\t\t};\n\t}\n\n\t// The object store's circuit breaker is open (retry.ts's CircuitOpenError):\n\t// the backend is down, not this request — tell clients when to retry.\n\tif ((error as { code?: unknown } | null)?.code === \"EUNAVAILABLE\") {\n\t\treturn {\n\t\t\tstatus: 503,\n\t\t\tbody: {\n\t\t\t\terror: \"ServiceUnavailable\",\n\t\t\t\tmessage: \"Storage is temporarily unavailable\",\n\t\t\t\tretryable: true,\n\t\t\t},\n\t\t\theaders: { \"Retry-After\": \"30\" },\n\t\t};\n\t}\n\n\tif (error instanceof Error) {\n\t\treturn {\n\t\t\tstatus: 500,\n\t\t\tbody: {\n\t\t\t\terror: \"InternalServerError\",\n\t\t\t\tmessage: \"An internal error occurred\",\n\t\t\t\tretryable: true,\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\tstatus: 500,\n\t\tbody: {\n\t\t\terror: \"UnknownError\",\n\t\t\tmessage: \"An unknown error occurred\",\n\t\t\tretryable: true,\n\t\t},\n\t};\n}\n","/**\n * Typed view of a git `objects/pack` directory listing.\n *\n * Every pack is a set of sibling files sharing one base name\n * (`pack-<hash>.pack`, `.idx`, and optionally `.keep`/`.bitmap`/`.rev`).\n * Parsing names once into {@link PackFileName} lets callers group, filter and\n * rename by kind instead of re-matching filename strings at each call site.\n *\n * Edge-compatible: no node: imports.\n */\n\n/** Every file kind git writes into `objects/pack`. */\nexport const PACK_FILE_KINDS = [\n\t\"pack\",\n\t\"idx\",\n\t\"keep\",\n\t\"bitmap\",\n\t\"rev\",\n] as const;\nexport type PackFileKind = (typeof PACK_FILE_KINDS)[number];\n\n/** Kinds isomorphic-git actually reads; the rest are git-CLI accelerators. */\nexport const READABLE_PACK_FILE_KINDS: ReadonlySet<PackFileKind> = new Set([\n\t\"pack\",\n\t\"idx\",\n]);\n\nexport interface PackFileName {\n\t/** Shared base of a pack's sibling files, e.g. `pack-1a2b…`. */\n\treadonly base: string;\n\treadonly kind: PackFileKind;\n\t/** The file name as listed, e.g. `pack-1a2b….idx`. */\n\treadonly name: string;\n}\n\nconst KNOWN_KINDS: ReadonlySet<string> = new Set(PACK_FILE_KINDS);\n\nfunction isPackFileKind(value: string): value is PackFileKind {\n\treturn KNOWN_KINDS.has(value);\n}\n\n/** Parse a pack-directory entry; `null` for anything git didn't put there. */\nexport function parsePackFileName(name: string): PackFileName | null {\n\tconst dot = name.lastIndexOf(\".\");\n\tif (dot <= 0) return null;\n\tconst kind = name.slice(dot + 1);\n\tif (!isPackFileKind(kind)) return null;\n\treturn { base: name.slice(0, dot), kind, name };\n}\n\n/** File name of the `kind` sibling of the pack with this base name. */\nexport function packFileName(base: string, kind: PackFileKind): string {\n\treturn `${base}.${kind}`;\n}\n\n/** Parse a directory listing, dropping entries that aren't pack files. */\nexport function parsePackDirectory(entries: readonly string[]): PackFileName[] {\n\treturn entries\n\t\t.map(parsePackFileName)\n\t\t.filter((file): file is PackFileName => file !== null);\n}\n","/**\n * Git ref-name validation, mirroring isomorphic-git's own internal `isValidRef`\n * character-class rules (the check `git.branch` and top-level `git.writeRef`\n * run before touching disk).\n *\n * Several of isomorphic-git's OTHER ref-touching primitives — `git.commit`,\n * `git.merge`, `git.deleteBranch`, and top-level `git.resolveRef`/\n * `git.deleteRef` — do NOT run this check internally: they resolve straight\n * through `fs.write`/`fs.rm(join(gitdir, ref))` with no jail to the gitdir.\n * On a shared-storage server (many repos under one prefix or base directory),\n * every branch/ref name that originates from request input must be validated\n * against these predicates before it reaches any of those primitives —\n * otherwise a `\"../\"`-laden name lets a caller with write access to any single\n * repo read, corrupt, or delete another repo's ref/object files.\n */\n\nconst BAD_REF_COMPONENT =\n\t// biome-ignore lint/suspicious/noControlCharactersInRegex: control chars are exactly what git's own ref-name rules reject — this needs to match the same range.\n\t/(^|[/.])([/.]|$)|^@$|@\\{|[\\x00-\\x20\\x7f~^:?*[\\\\]|\\.lock(\\/|$)/;\n\nconst FULL_SHA_RE = /^[0-9a-f]{40}$/i;\n\n/** Validates a fully-qualified ref (must start with refs/heads/ or refs/tags/). */\nexport function isSafeFullRefName(ref: string): boolean {\n\tif (!ref.startsWith(\"refs/heads/\") && !ref.startsWith(\"refs/tags/\")) {\n\t\treturn false;\n\t}\n\treturn !BAD_REF_COMPONENT.test(ref);\n}\n\n/**\n * Validates a bare branch name (no refs/ prefix). Rejects anything that looks\n * like a full ref path — a name of `\"refs/heads/x\"` would otherwise sail\n * through unprefixed at call sites that build `refs/heads/${name}` themselves\n * (doubling the prefix into something that still resolves), or be used as-is\n * at call sites that pass a name already containing `\"refs/\"` straight\n * through. Also rejects 40-hex SHA-shaped values so a stored branch name can\n * never be ambiguous with a commit SHA at write time; use\n * {@link isSafeRefName} on read paths that accept both shapes.\n */\nexport function isSafeBranchName(name: string): boolean {\n\tif (!name || name.startsWith(\"refs/\") || name === \"HEAD\") return false;\n\tif (FULL_SHA_RE.test(name)) return false;\n\treturn !BAD_REF_COMPONENT.test(name);\n}\n\n/** True for a full 40-hex-char commit SHA — the shape {@link isSafeBranchName} deliberately rejects. */\nexport function isFullSha(value: string): boolean {\n\treturn FULL_SHA_RE.test(value);\n}\n\n/**\n * Validates a \"ref\" field that may name either a branch or a commit SHA it's\n * pinned to — the shape read-path route params take (permalinks, raw links).\n * Both shapes still go through the traversal check.\n */\nexport function isSafeRefName(value: string): boolean {\n\treturn isSafeBranchName(value) || isFullSha(value);\n}\n\n/**\n * Validates a repo-relative file path from request input: relative, no `..`\n * segments, no `.git/` prefix, no null bytes. Use this anywhere a path\n * segment comes straight off a URL or form field rather than re-deriving the\n * checks ad hoc.\n */\nexport function isSafeRepoPath(p: string): boolean {\n\tif (p.startsWith(\"/\")) return false;\n\tif (p.split(\"/\").some((segment) => segment === \"..\")) return false;\n\tif (/^\\.git(\\/|$)/i.test(p)) return false;\n\tif (p.includes(\"\\0\")) return false;\n\treturn true;\n}\n\n/**\n * Whether `p` can name a file written into a tree: what {@link isSafeRepoPath}\n * checks, plus every segment non-empty and neither `.` nor `..`, and no\n * `.git` segment anywhere (any case) — git itself refuses to check those out,\n * since a tracked `.git/config` in a subdirectory is a code-execution vector\n * on clone. Use it for paths that become tree entries; reads keep the looser\n * {@link isSafeRepoPath} (which also accepts `\"\"`, the root).\n */\nexport function isSafeTreePath(p: string): boolean {\n\tif (!isSafeRepoPath(p) || p.length === 0) return false;\n\treturn p\n\t\t.split(\"/\")\n\t\t.every(\n\t\t\t(segment) =>\n\t\t\t\tsegment.length > 0 &&\n\t\t\t\tsegment !== \".\" &&\n\t\t\t\tsegment !== \"..\" &&\n\t\t\t\tsegment.toLowerCase() !== \".git\",\n\t\t);\n}\n\n/**\n * Qualify a bare branch name to `refs/heads/<name>` before handing it to\n * isomorphic-git. `resolveRef`/`expand` try several candidate paths in\n * sequence for a bare name — `ref`, `refs/ref`, `refs/tags/ref`,\n * `refs/heads/ref`, … — missing (and, against object storage, paying a real\n * round trip for) the first three every time. For a branch-only ref model,\n * skip straight to the winner. Left untouched: already-qualified refs,\n * `\"HEAD\"` (its own first candidate, already optimal), and 40-hex oids\n * (resolved locally by isomorphic-git with no I/O at all).\n */\nexport function qualifyBranchRef(ref: string): string {\n\tif (ref.startsWith(\"refs/\") || ref === \"HEAD\" || FULL_SHA_RE.test(ref)) {\n\t\treturn ref;\n\t}\n\treturn `refs/heads/${ref}`;\n}\n"],"mappings":";AAQA,IAAM,cAAc,IAAI,YAAY;AACpC,IAAM,cAAc,IAAI,YAAY;AAc7B,SAAS,WAAW,MAAuC;AACjE,SAAO,YAAY,OAAO,IAAI;AAC/B;AAGO,SAAS,WAAW,MAA0B;AACpD,SAAO,YAAY,OAAO,IAAI;AAC/B;AAGO,SAAS,YAAY,MAA0B;AACrD,MAAI,IAAI;AACR,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ;AAChC,SAAK,OAAO,aAAa,KAAK,CAAC,CAAW;AAC3C,SAAO;AACR;AAOO,SAAS,UAAU,OAA8C;AACvE,MAAI,QAAQ;AACZ,aAAW,KAAK,MAAO,UAAS,EAAE;AAClC,QAAM,MAAM,IAAI,WAAW,KAAK;AAChC,MAAI,SAAS;AACb,aAAW,KAAK,OAAO;AACtB,QAAI,IAAI,GAAG,MAAM;AACjB,cAAU,EAAE;AAAA,EACb;AACA,SAAO;AACR;AAOO,SAAS,MAAM,MAA0B;AAC/C,MAAI,MAAM;AACV,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ;AAChC,WAAQ,KAAK,CAAC,EAAa,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AACxD,SAAO;AACR;AAGO,SAAS,SAAS,MAA0B;AAClD,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ;AAChC,cAAU,OAAO,aAAa,KAAK,CAAC,CAAW;AAChD,SAAO,KAAK,MAAM;AACnB;AAGO,SAAS,QAAQ,KAAsC;AAC7D,QAAM,QAAQ,IAAI,WAAW,IAAI,SAAS,CAAC;AAC3C,WAAS,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M;AAAA,EAC5B;AACF;AAYO,SAAS,iBAAiB,KAAqB;AACrD,MAAI,IAAI,WAAW,OAAO,KAAK,QAAQ,UAAU,YAAY,KAAK,GAAG,GAAG;AACvE,WAAO;AAAA,EACR;AACA,SAAO,cAAc,GAAG;AACzB;","names":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parsePackFileName
|
|
3
|
+
} from "./chunk-PASVUPKR.js";
|
|
4
|
+
|
|
5
|
+
// src/git-layout.ts
|
|
6
|
+
var HEX = new Set("0123456789abcdef");
|
|
7
|
+
function isHex(value, length) {
|
|
8
|
+
if (value.length !== length) return false;
|
|
9
|
+
for (const char of value) if (!HEX.has(char)) return false;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
function classifyGitdirPath(path) {
|
|
13
|
+
const segments = path.split("/");
|
|
14
|
+
const [first, second, third, ...rest] = segments;
|
|
15
|
+
if (segments.length === 1) {
|
|
16
|
+
if (first === "HEAD") return { kind: "head" };
|
|
17
|
+
if (first === "config") return { kind: "config" };
|
|
18
|
+
if (first === "refs") return { kind: "refs", path };
|
|
19
|
+
return { kind: "other" };
|
|
20
|
+
}
|
|
21
|
+
if (first === "refs") return { kind: "refs", path };
|
|
22
|
+
if (first !== "objects" || second === void 0) return { kind: "other" };
|
|
23
|
+
if (segments.length === 2 && second === "") return { kind: "objects-dir" };
|
|
24
|
+
if (second === "pack" && third !== void 0 && rest.length === 0) {
|
|
25
|
+
if (third === "") return { kind: "pack-dir" };
|
|
26
|
+
const file = parsePackFileName(third);
|
|
27
|
+
return file ? { kind: "pack-file", file } : { kind: "other" };
|
|
28
|
+
}
|
|
29
|
+
if (third !== void 0 && rest.length === 0 && isHex(second, 2) && isHex(third, 38)) {
|
|
30
|
+
return { kind: "loose-object", oid: second + third };
|
|
31
|
+
}
|
|
32
|
+
return { kind: "other" };
|
|
33
|
+
}
|
|
34
|
+
function isMutableGitdirEntry(entry) {
|
|
35
|
+
switch (entry.kind) {
|
|
36
|
+
case "head":
|
|
37
|
+
case "refs":
|
|
38
|
+
case "objects-dir":
|
|
39
|
+
case "pack-dir":
|
|
40
|
+
return true;
|
|
41
|
+
default:
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function parseLooseObjectPath(path) {
|
|
46
|
+
const segments = path.split("/");
|
|
47
|
+
if (segments.length < 3) return null;
|
|
48
|
+
const gitdirSegments = segments.slice(0, -3);
|
|
49
|
+
const entry = classifyGitdirPath(segments.slice(-3).join("/"));
|
|
50
|
+
if (entry.kind !== "loose-object") return null;
|
|
51
|
+
return { gitdir: gitdirSegments.join("/"), oid: entry.oid };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export {
|
|
55
|
+
classifyGitdirPath,
|
|
56
|
+
isMutableGitdirEntry,
|
|
57
|
+
parseLooseObjectPath
|
|
58
|
+
};
|
|
59
|
+
//# sourceMappingURL=chunk-ZB6GNJ2J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/git-layout.ts"],"sourcesContent":["/**\n * Typed classification of paths inside a git directory, so callers can\n * reason about \"a ref\", \"a loose object\" or \"the pack listing\" as values\n * instead of matching path strings against patterns.\n *\n * Edge-compatible: no node: imports.\n */\n\nimport { type PackFileName, parsePackFileName } from \"./pack-files.js\";\n\n/** What a gitdir-relative path refers to. Listing prefixes end in `/`. */\nexport type GitdirEntry =\n\t| { readonly kind: \"head\" }\n\t| { readonly kind: \"config\" }\n\t/** A ref file (`refs/heads/main`) or a refs listing (`refs/heads/`). */\n\t| { readonly kind: \"refs\"; readonly path: string }\n\t/** The `objects/` listing. */\n\t| { readonly kind: \"objects-dir\" }\n\t/** The `objects/pack/` listing. */\n\t| { readonly kind: \"pack-dir\" }\n\t| { readonly kind: \"pack-file\"; readonly file: PackFileName }\n\t| { readonly kind: \"loose-object\"; readonly oid: string }\n\t| { readonly kind: \"other\" };\n\nconst HEX = new Set(\"0123456789abcdef\");\n\nfunction isHex(value: string, length: number): boolean {\n\tif (value.length !== length) return false;\n\tfor (const char of value) if (!HEX.has(char)) return false;\n\treturn true;\n}\n\n/** Classify a path relative to a gitdir (no leading slash). */\nexport function classifyGitdirPath(path: string): GitdirEntry {\n\tconst segments = path.split(\"/\");\n\tconst [first, second, third, ...rest] = segments;\n\tif (segments.length === 1) {\n\t\tif (first === \"HEAD\") return { kind: \"head\" };\n\t\tif (first === \"config\") return { kind: \"config\" };\n\t\tif (first === \"refs\") return { kind: \"refs\", path };\n\t\treturn { kind: \"other\" };\n\t}\n\tif (first === \"refs\") return { kind: \"refs\", path };\n\tif (first !== \"objects\" || second === undefined) return { kind: \"other\" };\n\tif (segments.length === 2 && second === \"\") return { kind: \"objects-dir\" };\n\tif (second === \"pack\" && third !== undefined && rest.length === 0) {\n\t\tif (third === \"\") return { kind: \"pack-dir\" };\n\t\tconst file = parsePackFileName(third);\n\t\treturn file ? { kind: \"pack-file\", file } : { kind: \"other\" };\n\t}\n\tif (\n\t\tthird !== undefined &&\n\t\trest.length === 0 &&\n\t\tisHex(second, 2) &&\n\t\tisHex(third, 38)\n\t) {\n\t\treturn { kind: \"loose-object\", oid: second + third };\n\t}\n\treturn { kind: \"other\" };\n}\n\n/**\n * Whether reads of this entry can change between pushes: refs, `HEAD`, and\n * the object/pack listings. Everything else is content-addressed (objects)\n * or written once (config, a given pack file name).\n */\nexport function isMutableGitdirEntry(entry: GitdirEntry): boolean {\n\tswitch (entry.kind) {\n\t\tcase \"head\":\n\t\tcase \"refs\":\n\t\tcase \"objects-dir\":\n\t\tcase \"pack-dir\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * A loose-object path anywhere in the fs, split into its gitdir and oid —\n * for callers that don't know where the gitdir boundary is: a loose object\n * is always `<gitdir>/objects/<2 hex>/<38 hex>`.\n */\nexport function parseLooseObjectPath(\n\tpath: string,\n): { readonly gitdir: string; readonly oid: string } | null {\n\tconst segments = path.split(\"/\");\n\tif (segments.length < 3) return null;\n\tconst gitdirSegments = segments.slice(0, -3);\n\tconst entry = classifyGitdirPath(segments.slice(-3).join(\"/\"));\n\tif (entry.kind !== \"loose-object\") return null;\n\treturn { gitdir: gitdirSegments.join(\"/\"), oid: entry.oid };\n}\n"],"mappings":";;;;;AAwBA,IAAM,MAAM,IAAI,IAAI,kBAAkB;AAEtC,SAAS,MAAM,OAAe,QAAyB;AACtD,MAAI,MAAM,WAAW,OAAQ,QAAO;AACpC,aAAW,QAAQ,MAAO,KAAI,CAAC,IAAI,IAAI,IAAI,EAAG,QAAO;AACrD,SAAO;AACR;AAGO,SAAS,mBAAmB,MAA2B;AAC7D,QAAM,WAAW,KAAK,MAAM,GAAG;AAC/B,QAAM,CAAC,OAAO,QAAQ,OAAO,GAAG,IAAI,IAAI;AACxC,MAAI,SAAS,WAAW,GAAG;AAC1B,QAAI,UAAU,OAAQ,QAAO,EAAE,MAAM,OAAO;AAC5C,QAAI,UAAU,SAAU,QAAO,EAAE,MAAM,SAAS;AAChD,QAAI,UAAU,OAAQ,QAAO,EAAE,MAAM,QAAQ,KAAK;AAClD,WAAO,EAAE,MAAM,QAAQ;AAAA,EACxB;AACA,MAAI,UAAU,OAAQ,QAAO,EAAE,MAAM,QAAQ,KAAK;AAClD,MAAI,UAAU,aAAa,WAAW,OAAW,QAAO,EAAE,MAAM,QAAQ;AACxE,MAAI,SAAS,WAAW,KAAK,WAAW,GAAI,QAAO,EAAE,MAAM,cAAc;AACzE,MAAI,WAAW,UAAU,UAAU,UAAa,KAAK,WAAW,GAAG;AAClE,QAAI,UAAU,GAAI,QAAO,EAAE,MAAM,WAAW;AAC5C,UAAM,OAAO,kBAAkB,KAAK;AACpC,WAAO,OAAO,EAAE,MAAM,aAAa,KAAK,IAAI,EAAE,MAAM,QAAQ;AAAA,EAC7D;AACA,MACC,UAAU,UACV,KAAK,WAAW,KAChB,MAAM,QAAQ,CAAC,KACf,MAAM,OAAO,EAAE,GACd;AACD,WAAO,E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