git-fs-s3 0.9.0 → 0.11.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 +34 -2
- package/dist/chunk-G636FB7W.js +143 -0
- package/dist/chunk-G636FB7W.js.map +1 -0
- package/dist/{chunk-PASVUPKR.js → chunk-HO6OPXUS.js} +139 -1
- package/dist/chunk-HO6OPXUS.js.map +1 -0
- package/dist/{chunk-HBOJR5D3.js → chunk-QH3HS7VI.js} +41 -17
- package/dist/chunk-QH3HS7VI.js.map +1 -0
- package/dist/http.js +33 -70
- package/dist/http.js.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/ops.js +176 -10
- package/dist/ops.js.map +1 -1
- package/dist/s3.js +17 -0
- package/dist/s3.js.map +1 -1
- package/dist/types/edge-utils.d.ts +14 -0
- package/dist/types/http/pack-reuse.d.ts +0 -8
- package/dist/types/http/pkt-line.d.ts +11 -2
- package/dist/types/http/reachability.d.ts +14 -0
- package/dist/types/http/receive-pack.d.ts +13 -6
- package/dist/types/index.d.ts +1 -0
- package/dist/types/object-size.d.ts +6 -0
- package/dist/types/ops/diff.d.ts +15 -2
- package/dist/types/ops/index.d.ts +2 -1
- package/dist/types/ops/submodules.d.ts +13 -0
- package/dist/types/ops/tree.d.ts +1 -1
- package/dist/types/pack-entry.d.ts +63 -0
- package/dist/types/pack-index.d.ts +24 -0
- package/dist/types/semaphore.d.ts +22 -0
- package/dist/types/stores/memory.d.ts +1 -0
- package/dist/types/stores/s3.d.ts +1 -0
- package/dist/types/types.d.ts +10 -0
- package/package.json +1 -1
- package/dist/chunk-HBOJR5D3.js.map +0 -1
- package/dist/chunk-PASVUPKR.js.map +0 -1
- package/dist/chunk-ZB6GNJ2J.js +0 -59
- package/dist/chunk-ZB6GNJ2J.js.map +0 -1
package/README.md
CHANGED
|
@@ -153,6 +153,19 @@ The returned fs also exposes:
|
|
|
153
153
|
- `detectLooseObjects(gitdir)` — detect the loose-object hint up front (otherwise done on the first loose read).
|
|
154
154
|
- `prefetchPacks(gitdir, { maxPacks? })` — warm every `.pack`/`.idx` in parallel before a sequential walk (skipped past `maxPacks * 2` entries).
|
|
155
155
|
- `invalidate(pathPrefix)` — drop hints and registered gitdirs under the prefix and forward to the store's `invalidate` if it has one.
|
|
156
|
+
- `getRange(filepath, start, end)` — present only when the backing store supports range reads (see `ObjectStore.getRange`); `getObjectSize` is its only caller.
|
|
157
|
+
|
|
158
|
+
### `getObjectSize(repo, oid)`
|
|
159
|
+
|
|
160
|
+
An object's size in bytes, **without reading it** — or `null` when the size
|
|
161
|
+
isn't available (a loose object, an object no pack indexes, a store without
|
|
162
|
+
range reads, or a delta prefix too short to yield its header). Built for one
|
|
163
|
+
question: *is this object too large to render or diff?* A git object's length
|
|
164
|
+
lives in its pack entry, so without this the only way to ask is to inflate the
|
|
165
|
+
object — which is the cost a size limit exists to avoid. The answer is exact
|
|
166
|
+
(whole objects from the entry header, deltified ones from the delta header that
|
|
167
|
+
opens their deflated stream) and costs one `.idx` read plus one or two small
|
|
168
|
+
range reads of the pack.
|
|
156
169
|
|
|
157
170
|
### Git layout
|
|
158
171
|
|
|
@@ -160,7 +173,7 @@ The returned fs also exposes:
|
|
|
160
173
|
|
|
161
174
|
### `S3ObjectStore({ client, bucket, prefix?, contentType? })`
|
|
162
175
|
|
|
163
|
-
`ObjectStore` over `@aws-sdk/client-s3` (optional peer dependency, loaded only via the `/s3` subpath). Reuse one `S3Client` across stores so HTTP connections are pooled — a busy repo page can mean hundreds of object reads. `contentType(key)` optionally derives a `Content-Type` header for uploads.
|
|
176
|
+
`ObjectStore` over `@aws-sdk/client-s3` (optional peer dependency, loaded only via the `/s3` subpath). Implements the optional `getRange(key, start, end)` (S3's `Range` header, inclusive at both ends), which `getObjectSize` uses. Reuse one `S3Client` across stores so HTTP connections are pooled — a busy repo page can mean hundreds of object reads. `contentType(key)` optionally derives a `Content-Type` header for uploads.
|
|
164
177
|
|
|
165
178
|
### `MemoryObjectStore()`
|
|
166
179
|
|
|
@@ -248,7 +261,7 @@ Every client-supplied ref name in a push is validated with `isSafeFullRefName` (
|
|
|
248
261
|
- **Commits** — `commitFilesToBare` (write one or more files as a single commit against a branch, creating it if new), `deleteFileFromBare`, `authorNow`.
|
|
249
262
|
- **Trees** — `upsertTree`/`deleteFromTree` (overlay blobs onto a tree, return the new root oid), `listTreeEntries`, `findTreeEntry`.
|
|
250
263
|
- **History** — `getCommitLog`/`getCommitHistory` (memoized commit-chain walks; pages are slices of the deepest walk), `getFileContent`/`getTreeFromRef`, `getFileHistory` (per-file commit history), `getLastCommitsForTree` (the "last commit" column on a directory listing), `summarizeCommit`.
|
|
251
|
-
- **Diff** — `getCommitDiff` (a commit against its first parent) and `getDiffBetweenRefs` (a pull request's three-dot diff, against the merge base); unified patches via the `diff` package (optional peer dependency).
|
|
264
|
+
- **Diff** — `getCommitDiff` (a commit against its first parent) and `getDiffBetweenRefs` (a pull request's three-dot diff, against the merge base); unified patches via the `diff` package (optional peer dependency). A file over `MAX_DIFF_TEXT_BYTES` is reported as `kind: "too-large"` **without being read** — the size comes from its pack entry (see `getObjectSize`) — and a diff's blob reads are bounded (`MAX_CONCURRENT_READS`), so one wide commit can't fan out into a request per entry.
|
|
252
265
|
- **Merge** — `analyzeMerge` (fast-forward/diverged pre-check — not a real content-conflict check, see its doc comment) and `fastForwardMerge`. Neither does a real (non-fast-forward) content merge — for that, see [`git-edge`](https://www.npmjs.com/package/git-edge)'s `threeWayMerge`, an object-level three-way merge with no worktree needed, built on this package (same `{ fs, gitdir, cache? }` shape; it stores merges through `withPackedWrites`).
|
|
253
266
|
|
|
254
267
|
```typescript
|
|
@@ -266,6 +279,25 @@ const { entries } = await getCommitLog(repo, { ref: "main", depth: 50 });
|
|
|
266
279
|
|
|
267
280
|
`resultKeyPrefixes` (from `/ops`) lists the `ResultCache` key prefixes these functions write under — evict them after rewriting a repo's storage out of band (bulk sync, rename), or a cached walk result outlives the history it describes.
|
|
268
281
|
|
|
282
|
+
## Submodules
|
|
283
|
+
|
|
284
|
+
Tree entries retain Git's `type: "commit"` and mode `160000` for submodules.
|
|
285
|
+
HTTP reachability, receive-pack validation, upload-pack and repack treat these
|
|
286
|
+
as external pointers and never try to read the submodule commit in the parent.
|
|
287
|
+
`getFileHistory` tracks pointer changes; `getFileContent` only reads blobs.
|
|
288
|
+
|
|
289
|
+
`getCommitDiff` and `getDiffBetweenRefs` emit `kind: "submodule"` for additions,
|
|
290
|
+
removals, updates and conversions to/from blobs or trees. `oldEntry`/`newEntry`
|
|
291
|
+
carry the object ID, type and mode. Pointer changes do not count as text line
|
|
292
|
+
additions/deletions. Diff results also include the exact `oldRef` (parent or
|
|
293
|
+
merge base, absent for an empty base) and `newRef` used for navigation.
|
|
294
|
+
|
|
295
|
+
`getSubmodules(repo, ref, hooks?)` reads root `.gitmodules` at that revision;
|
|
296
|
+
`parseGitmodules(text)` parses its named path/URL records without I/O. Neither
|
|
297
|
+
expands includes nor follows URLs. Missing/oversized config returns no records;
|
|
298
|
+
malformed records and ambiguous duplicate paths are ignored. Browser URL
|
|
299
|
+
validation and authorization to other repositories belong to the application.
|
|
300
|
+
|
|
269
301
|
## Semantics & limitations
|
|
270
302
|
|
|
271
303
|
- **Bare repositories are the target.** Plumbing (`writeBlob`/`writeTree`/`writeCommit`/`readCommit`/`log`/refs/branches) is covered by the test suite. Worktree operations (`checkout`, `add`, `status`) want a real disk — hydrate to `/tmp` for those.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OBJ_OFS_DELTA,
|
|
3
|
+
OBJ_REF_DELTA,
|
|
4
|
+
OID_BYTES,
|
|
5
|
+
findPackIndexOffset,
|
|
6
|
+
inflatePrefix,
|
|
7
|
+
packFileName,
|
|
8
|
+
parsePackDirectory,
|
|
9
|
+
parsePackFileName,
|
|
10
|
+
rawFs,
|
|
11
|
+
readDeltaHeader,
|
|
12
|
+
readEntryHeader,
|
|
13
|
+
readOfsDeltaOffset
|
|
14
|
+
} from "./chunk-HO6OPXUS.js";
|
|
15
|
+
|
|
16
|
+
// src/git-layout.ts
|
|
17
|
+
var HEX = new Set("0123456789abcdef");
|
|
18
|
+
function isHex(value, length) {
|
|
19
|
+
if (value.length !== length) return false;
|
|
20
|
+
for (const char of value) if (!HEX.has(char)) return false;
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
function classifyGitdirPath(path) {
|
|
24
|
+
const segments = path.split("/");
|
|
25
|
+
const [first, second, third, ...rest] = segments;
|
|
26
|
+
if (segments.length === 1) {
|
|
27
|
+
if (first === "HEAD") return { kind: "head" };
|
|
28
|
+
if (first === "config") return { kind: "config" };
|
|
29
|
+
if (first === "refs") return { kind: "refs", path };
|
|
30
|
+
return { kind: "other" };
|
|
31
|
+
}
|
|
32
|
+
if (first === "refs") return { kind: "refs", path };
|
|
33
|
+
if (first !== "objects" || second === void 0) return { kind: "other" };
|
|
34
|
+
if (segments.length === 2 && second === "") return { kind: "objects-dir" };
|
|
35
|
+
if (second === "pack" && third !== void 0 && rest.length === 0) {
|
|
36
|
+
if (third === "") return { kind: "pack-dir" };
|
|
37
|
+
const file = parsePackFileName(third);
|
|
38
|
+
return file ? { kind: "pack-file", file } : { kind: "other" };
|
|
39
|
+
}
|
|
40
|
+
if (third !== void 0 && rest.length === 0 && isHex(second, 2) && isHex(third, 38)) {
|
|
41
|
+
return { kind: "loose-object", oid: second + third };
|
|
42
|
+
}
|
|
43
|
+
return { kind: "other" };
|
|
44
|
+
}
|
|
45
|
+
function isMutableGitdirEntry(entry) {
|
|
46
|
+
switch (entry.kind) {
|
|
47
|
+
case "head":
|
|
48
|
+
case "refs":
|
|
49
|
+
case "objects-dir":
|
|
50
|
+
case "pack-dir":
|
|
51
|
+
return true;
|
|
52
|
+
default:
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function parseLooseObjectPath(path) {
|
|
57
|
+
const segments = path.split("/");
|
|
58
|
+
if (segments.length < 3) return null;
|
|
59
|
+
const gitdirSegments = segments.slice(0, -3);
|
|
60
|
+
const entry = classifyGitdirPath(segments.slice(-3).join("/"));
|
|
61
|
+
if (entry.kind !== "loose-object") return null;
|
|
62
|
+
return { gitdir: gitdirSegments.join("/"), oid: entry.oid };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/object-size.ts
|
|
66
|
+
var ENTRY_PROBE_BYTES = 64;
|
|
67
|
+
var DELTA_PROBE_BYTES = 4 * 1024;
|
|
68
|
+
var DELTA_HEADER_MAX_BYTES = 20;
|
|
69
|
+
async function locatePackedObject(repo, oid) {
|
|
70
|
+
const fsp = rawFs(repo);
|
|
71
|
+
const packDir = `${repo.gitdir}/objects/pack`;
|
|
72
|
+
const indexes = parsePackDirectory(
|
|
73
|
+
await fsp.readdir(packDir).catch(() => [])
|
|
74
|
+
).filter((file) => file.kind === "idx");
|
|
75
|
+
for (const { base } of indexes) {
|
|
76
|
+
const idx = await fsp.readFile(`${packDir}/${packFileName(base, "idx")}`);
|
|
77
|
+
if (!(idx instanceof Uint8Array)) continue;
|
|
78
|
+
const offset = findPackIndexOffset(idx, oid);
|
|
79
|
+
if (offset !== null) {
|
|
80
|
+
return { packName: packFileName(base, "pack"), offset };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
function rangeReader(repo) {
|
|
86
|
+
const promises = rawFs(repo);
|
|
87
|
+
if (!promises.getRange) return null;
|
|
88
|
+
return (key, start, end) => {
|
|
89
|
+
if (!promises.getRange) return Promise.resolve(null);
|
|
90
|
+
return promises.getRange(key, start, end);
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async function deltaResultSize(read, packKey, dataStart) {
|
|
94
|
+
const compressed = await read(
|
|
95
|
+
packKey,
|
|
96
|
+
dataStart,
|
|
97
|
+
dataStart + DELTA_PROBE_BYTES - 1
|
|
98
|
+
);
|
|
99
|
+
if (!compressed || compressed.byteLength === 0) return null;
|
|
100
|
+
const inflated = await inflatePrefix(
|
|
101
|
+
new Uint8Array(compressed),
|
|
102
|
+
DELTA_HEADER_MAX_BYTES
|
|
103
|
+
);
|
|
104
|
+
if (!inflated) return null;
|
|
105
|
+
const header = readDeltaHeader(inflated, 0);
|
|
106
|
+
return header.length <= inflated.byteLength ? header.resultSize : null;
|
|
107
|
+
}
|
|
108
|
+
async function getObjectSize(repo, oid) {
|
|
109
|
+
const read = rangeReader(repo);
|
|
110
|
+
if (!read) return null;
|
|
111
|
+
const located = await locatePackedObject(repo, oid);
|
|
112
|
+
if (!located) return null;
|
|
113
|
+
const packKey = `${repo.gitdir}/objects/pack/${located.packName}`;
|
|
114
|
+
const probe = await read(
|
|
115
|
+
packKey,
|
|
116
|
+
located.offset,
|
|
117
|
+
located.offset + ENTRY_PROBE_BYTES - 1
|
|
118
|
+
);
|
|
119
|
+
if (!probe || probe.byteLength === 0) return null;
|
|
120
|
+
const header = readEntryHeader(probe, 0);
|
|
121
|
+
if (header.length > probe.byteLength) return null;
|
|
122
|
+
if (header.type !== OBJ_OFS_DELTA && header.type !== OBJ_REF_DELTA) {
|
|
123
|
+
return header.size;
|
|
124
|
+
}
|
|
125
|
+
const bodyStart = located.offset + header.length;
|
|
126
|
+
let dataStart;
|
|
127
|
+
if (header.type === OBJ_REF_DELTA) {
|
|
128
|
+
dataStart = bodyStart + OID_BYTES;
|
|
129
|
+
} else {
|
|
130
|
+
const base = readOfsDeltaOffset(probe, header.length);
|
|
131
|
+
if (header.length + base.length > probe.byteLength) return null;
|
|
132
|
+
dataStart = bodyStart + base.length;
|
|
133
|
+
}
|
|
134
|
+
return deltaResultSize(read, packKey, dataStart);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export {
|
|
138
|
+
classifyGitdirPath,
|
|
139
|
+
isMutableGitdirEntry,
|
|
140
|
+
parseLooseObjectPath,
|
|
141
|
+
getObjectSize
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=chunk-G636FB7W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/git-layout.ts","../src/object-size.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","/**\n * An object's size without reading (or inflating) the object.\n *\n * Why this exists: a git object's length lives in its pack entry, but the only\n * way isomorphic-git will hand you an object's bytes is by inflating the whole\n * thing — so \"is this blob too large to render or diff\" could only be asked\n * *after* loading it, which is exactly the cost a size limit is meant to avoid.\n * A 500 MB blob committed to a public repository would be materialised in\n * memory by a single page view before any limit could reject it.\n *\n * Reading the answer is cheap but not trivial, because git stores an object two\n * ways:\n *\n * - **whole** — the entry header records the size, so a small range read at the\n * entry's offset answers it;\n * - **as a delta** — the entry header records the size of the *delta stream*,\n * and the reconstructed size is the second varint inside the delta data, which\n * is itself deflated. Only a bounded prefix of that stream is needed, so\n * {@link inflatePrefix} recovers it without inflating the object.\n *\n * Either way the answer is exact, which matters because it decides whether a\n * caller may load the object at all. The cost is one `.idx` read (served from\n * the fs cache after the first) plus one or two small range reads of the pack,\n * so a caller can ask about a hundred objects without fetching a pack.\n *\n * `null` means \"not a packed object whose size could be read\" — a loose object,\n * a genuinely absent one, an unreadable index, a store without range reads, or\n * a delta prefix too short to yield its header. A caller must then read the\n * object rather than treating `null` as \"too large\"; see the call sites.\n */\nimport { inflatePrefix } from \"./edge-utils.js\";\nimport { rawFs } from \"./http/types.js\";\nimport type { Repo } from \"./ops/types.js\";\nimport {\n\tOBJ_OFS_DELTA,\n\tOBJ_REF_DELTA,\n\tOID_BYTES,\n\treadDeltaHeader,\n\treadEntryHeader,\n\treadOfsDeltaOffset,\n} from \"./pack-entry.js\";\nimport { packFileName, parsePackDirectory } from \"./pack-files.js\";\nimport { findPackIndexOffset } from \"./pack-index.js\";\n\n/**\n * Bytes fetched at an entry's offset. The entry header itself is at most 10\n * bytes for a 64-bit length, a `REF_DELTA`'s base id is 20, and an `OFS_DELTA`'s\n * base offset at most 10 — 40 bytes, so 64 answers the layout without a second\n * request.\n */\nconst ENTRY_PROBE_BYTES = 64;\n\n/**\n * Compressed bytes fetched from a delta's data. A delta header is two varints\n * (at most 10 bytes each) whose compressed form is smaller still, so this is\n * generous by orders of magnitude while staying a bounded read.\n */\nconst DELTA_PROBE_BYTES = 4 * 1024;\n\n/** The most a delta header can occupy once inflated: two 10-byte varints. */\nconst DELTA_HEADER_MAX_BYTES = 20;\n\n/** The pack holding `oid`, with the offset of its entry. */\nasync function locatePackedObject(\n\trepo: Repo,\n\toid: string,\n): Promise<{ packName: string; offset: number } | null> {\n\tconst fsp = rawFs(repo);\n\tconst packDir = `${repo.gitdir}/objects/pack`;\n\tconst indexes = parsePackDirectory(\n\t\tawait fsp.readdir(packDir).catch(() => [] as string[]),\n\t).filter((file) => file.kind === \"idx\");\n\n\tfor (const { base } of indexes) {\n\t\tconst idx = await fsp.readFile(`${packDir}/${packFileName(base, \"idx\")}`);\n\t\tif (!(idx instanceof Uint8Array)) continue;\n\t\tconst offset = findPackIndexOffset(idx, oid);\n\t\tif (offset !== null) {\n\t\t\treturn { packName: packFileName(base, \"pack\"), offset };\n\t\t}\n\t}\n\treturn null;\n}\n\n/** The store's range reader, or `null` when it has none. */\nfunction rangeReader(repo: Repo) {\n\tconst promises = rawFs(repo) as {\n\t\tgetRange?: (\n\t\t\tkey: string,\n\t\t\tstart: number,\n\t\t\tend: number,\n\t\t) => Promise<Uint8Array | null>;\n\t};\n\tif (!promises.getRange) return null;\n\treturn (key: string, start: number, end: number) => {\n\t\tif (!promises.getRange) return Promise.resolve(null);\n\t\treturn promises.getRange(key, start, end);\n\t};\n}\n\n/**\n * A delta entry's reconstructed size, read from the header its deflated data\n * opens with. `null` when the bounded prefix doesn't yield a complete header.\n */\nasync function deltaResultSize(\n\tread: NonNullable<ReturnType<typeof rangeReader>>,\n\tpackKey: string,\n\tdataStart: number,\n): Promise<number | null> {\n\tconst compressed = await read(\n\t\tpackKey,\n\t\tdataStart,\n\t\tdataStart + DELTA_PROBE_BYTES - 1,\n\t);\n\tif (!compressed || compressed.byteLength === 0) return null;\n\n\tconst inflated = await inflatePrefix(\n\t\tnew Uint8Array(compressed),\n\t\tDELTA_HEADER_MAX_BYTES,\n\t);\n\tif (!inflated) return null;\n\n\tconst header = readDeltaHeader(inflated, 0);\n\treturn header.length <= inflated.byteLength ? header.resultSize : null;\n}\n\n/**\n * `oid`'s size in bytes, or `null` when it isn't a packed object this can read\n * (see the module comment for what that means to a caller).\n */\nexport async function getObjectSize(\n\trepo: Repo,\n\toid: string,\n): Promise<number | null> {\n\t// Without range reads the pack would have to be fetched whole, which is the\n\t// cost this exists to avoid — so report \"unknown\" and let the caller read.\n\tconst read = rangeReader(repo);\n\tif (!read) return null;\n\n\tconst located = await locatePackedObject(repo, oid);\n\tif (!located) return null;\n\n\tconst packKey = `${repo.gitdir}/objects/pack/${located.packName}`;\n\tconst probe = await read(\n\t\tpackKey,\n\t\tlocated.offset,\n\t\tlocated.offset + ENTRY_PROBE_BYTES - 1,\n\t);\n\tif (!probe || probe.byteLength === 0) return null;\n\n\tconst header = readEntryHeader(probe, 0);\n\t// A header that ran off the end of the probe is a header this read, not one\n\t// it can interpret.\n\tif (header.length > probe.byteLength) return null;\n\tif (header.type !== OBJ_OFS_DELTA && header.type !== OBJ_REF_DELTA) {\n\t\treturn header.size;\n\t}\n\n\t// The base reference sits between the entry header and the deflated delta\n\t// data: 20 bytes of oid for `REF_DELTA`, or a backwards offset for\n\t// `OFS_DELTA`.\n\tconst bodyStart = located.offset + header.length;\n\tlet dataStart: number;\n\tif (header.type === OBJ_REF_DELTA) {\n\t\tdataStart = bodyStart + OID_BYTES;\n\t} else {\n\t\tconst base = readOfsDeltaOffset(probe, header.length);\n\t\tif (header.length + base.length > probe.byteLength) return null;\n\t\tdataStart = bodyStart + base.length;\n\t}\n\treturn deltaResultSize(read, packKey, dataStart);\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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KAAK,MAAM,iBAAiB,QAAQ,QAAQ;AAC/D,QAAM,QAAQ,MAAM;AAAA,IACnB;AAAA,IACA,QAAQ;AAAA,IACR,QAAQ,SAAS,oBAAoB;AAAA,EACtC;AACA,MAAI,CAAC,SAAS,MAAM,eAAe,EAAG,QAAO;AAE7C,QAAM,SAAS,gBAAgB,OAAO,CAAC;AAGvC,MAAI,OAAO,SAAS,MAAM,WAAY,QAAO;AAC7C,MAAI,OAAO,SAAS,iBAAiB,OAAO,SAAS,eAAe;AACnE,WAAO,OAAO;AAAA,EACf;AAKA,QAAM,YAAY,QAAQ,SAAS,OAAO;AAC1C,MAAI;AACJ,MAAI,OAAO,SAAS,eAAe;AAClC,gBAAY,YAAY;AAAA,EACzB,OAAO;AACN,UAAM,OAAO,mBAAmB,OAAO,OAAO,MAAM;AACpD,QAAI,OAAO,SAAS,KAAK,SAAS,MAAM,WAAY,QAAO;AAC3D,gBAAY,YAAY,KAAK;AAAA,EAC9B;AACA,SAAO,gBAAgB,MAAM,SAAS,SAAS;AAChD;","names":[]}
|
|
@@ -54,6 +54,28 @@ async function deflate(data) {
|
|
|
54
54
|
);
|
|
55
55
|
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
56
56
|
}
|
|
57
|
+
async function inflatePrefix(compressed, enough) {
|
|
58
|
+
const stream = new Response(compressed).body.pipeThrough(
|
|
59
|
+
new DecompressionStream("deflate")
|
|
60
|
+
);
|
|
61
|
+
const reader = stream.getReader();
|
|
62
|
+
const chunks = [];
|
|
63
|
+
let total = 0;
|
|
64
|
+
try {
|
|
65
|
+
while (total < enough) {
|
|
66
|
+
const { done, value } = await reader.read();
|
|
67
|
+
if (done) break;
|
|
68
|
+
chunks.push(value);
|
|
69
|
+
total += value.byteLength;
|
|
70
|
+
}
|
|
71
|
+
} catch {
|
|
72
|
+
} finally {
|
|
73
|
+
await reader.cancel().catch(() => {
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (total === 0) return null;
|
|
77
|
+
return concat(...chunks.map((chunk) => new Uint8Array(chunk)));
|
|
78
|
+
}
|
|
57
79
|
async function inflate(data) {
|
|
58
80
|
const stream = new Response(data).body.pipeThrough(
|
|
59
81
|
new DecompressionStream("deflate")
|
|
@@ -216,6 +238,18 @@ function parsePackDirectory(entries) {
|
|
|
216
238
|
return entries.map(parsePackFileName).filter((file) => file !== null);
|
|
217
239
|
}
|
|
218
240
|
|
|
241
|
+
// src/http/types.ts
|
|
242
|
+
var runStep = (hooks, label, fn) => hooks?.step ? hooks.step(label, fn) : fn();
|
|
243
|
+
function rawFs(repo) {
|
|
244
|
+
const fs = repo.fs;
|
|
245
|
+
if (!fs?.promises) {
|
|
246
|
+
throw new TypeError(
|
|
247
|
+
"This operation needs a promise fs (`fs.promises`) \u2014 node:fs and createGitFs both provide one"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return fs.promises;
|
|
251
|
+
}
|
|
252
|
+
|
|
219
253
|
// src/refs.ts
|
|
220
254
|
var BAD_REF_COMPONENT = (
|
|
221
255
|
// biome-ignore lint/suspicious/noControlCharactersInRegex: control chars are exactly what git's own ref-name rules reject — this needs to match the same range.
|
|
@@ -259,6 +293,98 @@ function qualifyBranchRef(ref) {
|
|
|
259
293
|
return `refs/heads/${ref}`;
|
|
260
294
|
}
|
|
261
295
|
|
|
296
|
+
// src/pack-entry.ts
|
|
297
|
+
var OBJ_OFS_DELTA = 6;
|
|
298
|
+
var OBJ_REF_DELTA = 7;
|
|
299
|
+
var OID_BYTES = 20;
|
|
300
|
+
function readEntryHeader(bytes, start) {
|
|
301
|
+
let byte = bytes[start];
|
|
302
|
+
const type = byte >> 4 & 7;
|
|
303
|
+
let size = byte & 15;
|
|
304
|
+
let shift = 4;
|
|
305
|
+
let at = start + 1;
|
|
306
|
+
while (byte & 128) {
|
|
307
|
+
byte = bytes[at++];
|
|
308
|
+
size += (byte & 127) * 2 ** shift;
|
|
309
|
+
shift += 7;
|
|
310
|
+
}
|
|
311
|
+
return { type, size, length: at - start };
|
|
312
|
+
}
|
|
313
|
+
function encodeEntryHeader(type, size) {
|
|
314
|
+
const bytes = [];
|
|
315
|
+
let rest = Math.floor(size / 16);
|
|
316
|
+
bytes.push((rest > 0 ? 128 : 0) | type << 4 | size % 16);
|
|
317
|
+
while (rest > 0) {
|
|
318
|
+
const low = rest % 128;
|
|
319
|
+
rest = Math.floor(rest / 128);
|
|
320
|
+
bytes.push((rest > 0 ? 128 : 0) | low);
|
|
321
|
+
}
|
|
322
|
+
return new Uint8Array(bytes);
|
|
323
|
+
}
|
|
324
|
+
function readOfsDeltaOffset(bytes, start) {
|
|
325
|
+
let at = start;
|
|
326
|
+
let byte = bytes[at++];
|
|
327
|
+
let distance = byte & 127;
|
|
328
|
+
while (byte & 128) {
|
|
329
|
+
byte = bytes[at++];
|
|
330
|
+
distance = (distance + 1) * 128 + (byte & 127);
|
|
331
|
+
}
|
|
332
|
+
return { distance, length: at - start };
|
|
333
|
+
}
|
|
334
|
+
function readVarint(bytes, start) {
|
|
335
|
+
let at = start;
|
|
336
|
+
let byte = bytes[at++];
|
|
337
|
+
let value = byte & 127;
|
|
338
|
+
let shift = 7;
|
|
339
|
+
while (byte & 128) {
|
|
340
|
+
byte = bytes[at++];
|
|
341
|
+
value += (byte & 127) * 2 ** shift;
|
|
342
|
+
shift += 7;
|
|
343
|
+
}
|
|
344
|
+
return { value, length: at - start };
|
|
345
|
+
}
|
|
346
|
+
function readDeltaHeader(bytes, start) {
|
|
347
|
+
const base = readVarint(bytes, start);
|
|
348
|
+
const result = readVarint(bytes, start + base.length);
|
|
349
|
+
return {
|
|
350
|
+
baseSize: base.value,
|
|
351
|
+
resultSize: result.value,
|
|
352
|
+
length: base.length + result.length
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/pack-index.ts
|
|
357
|
+
var IDX_V2 = {
|
|
358
|
+
magic: 4285812579,
|
|
359
|
+
version: 2,
|
|
360
|
+
headerBytes: 8,
|
|
361
|
+
fanoutEntries: 256,
|
|
362
|
+
/** Offsets with this bit set index the 64-bit large-offset table. */
|
|
363
|
+
largeOffsetFlag: 2147483648
|
|
364
|
+
};
|
|
365
|
+
function readPackIndex(idx) {
|
|
366
|
+
const view = new DataView(idx.buffer, idx.byteOffset, idx.byteLength);
|
|
367
|
+
const namesStart = IDX_V2.headerBytes + IDX_V2.fanoutEntries * 4;
|
|
368
|
+
if (idx.byteLength < namesStart || view.getUint32(0) !== IDX_V2.magic || view.getUint32(4) !== IDX_V2.version) {
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
const count = view.getUint32(namesStart - 4);
|
|
372
|
+
const crcStart = namesStart + count * OID_BYTES;
|
|
373
|
+
const offsetsStart = crcStart + count * 4;
|
|
374
|
+
if (idx.byteLength < offsetsStart + count * 4) return null;
|
|
375
|
+
const entries = [];
|
|
376
|
+
for (let i = 0; i < count; i++) {
|
|
377
|
+
const offset = view.getUint32(offsetsStart + i * 4);
|
|
378
|
+
if (offset & IDX_V2.largeOffsetFlag) return null;
|
|
379
|
+
const at = namesStart + i * OID_BYTES;
|
|
380
|
+
entries.push({ oid: toHex(idx.subarray(at, at + OID_BYTES)), offset });
|
|
381
|
+
}
|
|
382
|
+
return entries;
|
|
383
|
+
}
|
|
384
|
+
function findPackIndexOffset(idx, oid) {
|
|
385
|
+
return readPackIndex(idx)?.find((entry) => entry.oid === oid)?.offset ?? null;
|
|
386
|
+
}
|
|
387
|
+
|
|
262
388
|
export {
|
|
263
389
|
encodeUtf8,
|
|
264
390
|
decodeUtf8,
|
|
@@ -269,6 +395,7 @@ export {
|
|
|
269
395
|
fromHex,
|
|
270
396
|
sha1,
|
|
271
397
|
deflate,
|
|
398
|
+
inflatePrefix,
|
|
272
399
|
inflate,
|
|
273
400
|
hasNullByte,
|
|
274
401
|
readBlobContent,
|
|
@@ -289,6 +416,17 @@ export {
|
|
|
289
416
|
parsePackFileName,
|
|
290
417
|
packFileName,
|
|
291
418
|
parsePackDirectory,
|
|
419
|
+
runStep,
|
|
420
|
+
rawFs,
|
|
421
|
+
OBJ_OFS_DELTA,
|
|
422
|
+
OBJ_REF_DELTA,
|
|
423
|
+
OID_BYTES,
|
|
424
|
+
readEntryHeader,
|
|
425
|
+
encodeEntryHeader,
|
|
426
|
+
readOfsDeltaOffset,
|
|
427
|
+
readDeltaHeader,
|
|
428
|
+
readPackIndex,
|
|
429
|
+
findPackIndexOffset,
|
|
292
430
|
isSafeFullRefName,
|
|
293
431
|
isSafeBranchName,
|
|
294
432
|
isFullSha,
|
|
@@ -297,4 +435,4 @@ export {
|
|
|
297
435
|
isSafeTreePath,
|
|
298
436
|
qualifyBranchRef
|
|
299
437
|
};
|
|
300
|
-
//# sourceMappingURL=chunk-
|
|
438
|
+
//# sourceMappingURL=chunk-HO6OPXUS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/edge-utils.ts","../src/git-errors.ts","../src/pack-files.ts","../src/http/types.ts","../src/refs.ts","../src/pack-entry.ts","../src/pack-index.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/**\n * The first `enough` bytes of a deflate stream, given a prefix of that stream.\n *\n * Deflate emits output as it consumes input, so a bounded compressed prefix\n * yields a bounded uncompressed prefix — which is how a delta entry's header\n * (the only place its reconstructed size is recorded) can be read without\n * inflating the whole object. The prefix ends mid-symbol by construction, so\n * the stream errors after the bytes we wanted have already arrived; that error\n * carries no information and is not propagated.\n *\n * Returns `null` when fewer than `enough` bytes could be recovered, so a caller\n * distinguishes \"not readable from this prefix\" from a zero-length answer.\n */\nexport async function inflatePrefix(\n\tcompressed: Uint8Array<ArrayBuffer>,\n\tenough: number,\n): Promise<Uint8Array<ArrayBuffer> | null> {\n\tconst stream = (new Response(compressed).body as ReadableStream).pipeThrough(\n\t\tnew DecompressionStream(\"deflate\"),\n\t);\n\tconst reader = stream.getReader();\n\tconst chunks: Uint8Array[] = [];\n\tlet total = 0;\n\ttry {\n\t\twhile (total < enough) {\n\t\t\tconst { done, value } = await reader.read();\n\t\t\tif (done) break;\n\t\t\tchunks.push(value);\n\t\t\ttotal += value.byteLength;\n\t\t}\n\t} catch {\n\t\t// Expected: the compressed prefix is truncated. Whatever was emitted\n\t\t// before that is what this returns.\n\t} finally {\n\t\tawait reader.cancel().catch(() => {});\n\t}\n\tif (total === 0) return null;\n\treturn concat(...chunks.map((chunk) => new Uint8Array(chunk)));\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","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 * 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","/**\n * Parsing the entry headers inside a git packfile (`gitformat-pack(5)`).\n *\n * Shared by the two places that read a pack's structure rather than its\n * objects: `http/pack-reuse.ts` (copying stored entries into a new pack) and\n * `object-size.ts` (answering an object's size without inflating it).\n *\n * Edge-compatible: `Uint8Array` only.\n */\n\n/** Git pack object type bits (bits 6-4 of an entry's first byte). */\nexport const OBJ_COMMIT = 1;\nexport const OBJ_TREE = 2;\nexport const OBJ_BLOB = 3;\nexport const OBJ_TAG = 4;\nexport const OBJ_OFS_DELTA = 6;\nexport const OBJ_REF_DELTA = 7;\n\n/** Bytes in a pack object's id, and in a `REF_DELTA`'s base reference. */\nexport const OID_BYTES = 20;\n\n/** The variable-length type/size header that starts every pack entry. */\nexport interface EntryHeader {\n\treadonly type: number;\n\t/**\n\t * For a whole object, its size in bytes. For a delta entry, the size of the\n\t * **delta stream**, not of the object it reconstructs — that is in the delta\n\t * header (see {@link readDeltaHeader}).\n\t */\n\treadonly size: number;\n\t/** Bytes the header occupies. */\n\treadonly length: number;\n}\n\n/**\n * Read the entry header at `start`.\n *\n * A header that runs off the end of `bytes` yields whatever digits were\n * available: this reads from a bounded slice of a pack, and every caller\n * decides for itself whether the result is plausible (`length` beyond what it\n * read means \"unknown\", not \"zero\").\n */\nexport function readEntryHeader(bytes: Uint8Array, start: number): EntryHeader {\n\tlet byte = bytes[start] as number;\n\tconst type = (byte >> 4) & 0b111;\n\tlet size = byte & 0b1111;\n\tlet shift = 4;\n\tlet at = start + 1;\n\twhile (byte & 0x80) {\n\t\tbyte = bytes[at++] as number;\n\t\tsize += (byte & 0x7f) * 2 ** shift;\n\t\tshift += 7;\n\t}\n\treturn { type, size, length: at - start };\n}\n\n/** Serialize an entry header (the inverse of {@link readEntryHeader}). */\nexport function encodeEntryHeader(type: number, size: number): Uint8Array {\n\tconst bytes: number[] = [];\n\tlet rest = Math.floor(size / 16);\n\tbytes.push((rest > 0 ? 0x80 : 0) | (type << 4) | (size % 16));\n\twhile (rest > 0) {\n\t\tconst low = rest % 128;\n\t\trest = Math.floor(rest / 128);\n\t\tbytes.push((rest > 0 ? 0x80 : 0) | low);\n\t}\n\treturn new Uint8Array(bytes);\n}\n\n/** `OFS_DELTA`'s negative base offset: big-endian base-128 with +1 carries. */\nexport function readOfsDeltaOffset(\n\tbytes: Uint8Array,\n\tstart: number,\n): { distance: number; length: number } {\n\tlet at = start;\n\tlet byte = bytes[at++] as number;\n\tlet distance = byte & 0x7f;\n\twhile (byte & 0x80) {\n\t\tbyte = bytes[at++] as number;\n\t\tdistance = (distance + 1) * 128 + (byte & 0x7f);\n\t}\n\treturn { distance, length: at - start };\n}\n\n/** The two varints a delta stream opens with: base size, then result size. */\nexport interface DeltaHeader {\n\t/** Size of the object the delta is written against. */\n\treadonly baseSize: number;\n\t/** Size of the object the delta reconstructs. */\n\treadonly resultSize: number;\n\t/** Bytes the two varints occupy. */\n\treadonly length: number;\n}\n\n/** Read the base-128 little-endian varint at `start`, 7 bits per byte. */\nfunction readVarint(\n\tbytes: Uint8Array,\n\tstart: number,\n): { value: number; length: number } {\n\tlet at = start;\n\tlet byte = bytes[at++] as number;\n\tlet value = byte & 0x7f;\n\tlet shift = 7;\n\twhile (byte & 0x80) {\n\t\tbyte = bytes[at++] as number;\n\t\tvalue += (byte & 0x7f) * 2 ** shift;\n\t\tshift += 7;\n\t}\n\treturn { value, length: at - start };\n}\n\n/**\n * Read the delta header that follows an `OFS_DELTA` / `REF_DELTA` entry's own\n * header (and, for `REF_DELTA`, its 20-byte base id): the size of the object\n * being modified, then the size of the result. The result size is the answer\n * {@link ObjectSize} exists to get — it is the only place a deltified object's\n * real length is recorded.\n */\nexport function readDeltaHeader(bytes: Uint8Array, start: number): DeltaHeader {\n\tconst base = readVarint(bytes, start);\n\tconst result = readVarint(bytes, start + base.length);\n\treturn {\n\t\tbaseSize: base.value,\n\t\tresultSize: result.value,\n\t\tlength: base.length + result.length,\n\t};\n}\n","/**\n * Reading a pack's version-2 `.idx` (`gitformat-pack(5)`) — the oid → offset\n * table git writes beside every packfile.\n *\n * Kept separate from the code that reads pack *entries*: an index lookup is how\n * you find out which bytes to look at, and it is the cheap half of any question\n * about a packed object's contents (`http/pack-reuse.ts` copies entries into a\n * new pack; `object-size.ts` reads one entry's header).\n *\n * Edge-compatible: `Uint8Array` and `DataView` only.\n */\n\nimport { toHex } from \"./edge-utils.js\";\nimport { OID_BYTES } from \"./pack-entry.js\";\n\nconst IDX_V2 = {\n\tmagic: 0xff744f63,\n\tversion: 2,\n\theaderBytes: 8,\n\tfanoutEntries: 256,\n\t/** Offsets with this bit set index the 64-bit large-offset table. */\n\tlargeOffsetFlag: 0x80000000,\n} as const;\n\n/** An object's position in a pack, as listed by its `.idx`. */\nexport interface PackIndexEntry {\n\treadonly oid: string;\n\treadonly offset: number;\n}\n\n/**\n * Entries of a version-2 `.idx`, in the index's own (oid) order; `null` for any\n * other format, or for one whose declared object count doesn't fit the bytes\n * present — an index that fails either check is not something to guess about.\n */\nexport function readPackIndex(idx: Uint8Array): PackIndexEntry[] | null {\n\tconst view = new DataView(idx.buffer, idx.byteOffset, idx.byteLength);\n\tconst namesStart = IDX_V2.headerBytes + IDX_V2.fanoutEntries * 4;\n\tif (\n\t\tidx.byteLength < namesStart ||\n\t\tview.getUint32(0) !== IDX_V2.magic ||\n\t\tview.getUint32(4) !== IDX_V2.version\n\t) {\n\t\treturn null;\n\t}\n\t// The last fanout slot counts every object in the pack.\n\tconst count = view.getUint32(namesStart - 4);\n\tconst crcStart = namesStart + count * OID_BYTES;\n\tconst offsetsStart = crcStart + count * 4;\n\tif (idx.byteLength < offsetsStart + count * 4) return null;\n\n\tconst entries: PackIndexEntry[] = [];\n\tfor (let i = 0; i < count; i++) {\n\t\tconst offset = view.getUint32(offsetsStart + i * 4);\n\t\t// Packs over 2 GiB use the 64-bit offset table instead; callers that\n\t\t// can't handle it treat this as \"not readable\" rather than guessing.\n\t\tif (offset & IDX_V2.largeOffsetFlag) return null;\n\t\tconst at = namesStart + i * OID_BYTES;\n\t\tentries.push({ oid: toHex(idx.subarray(at, at + OID_BYTES)), offset });\n\t}\n\treturn entries;\n}\n\n/** Offset of `oid` in `idx`, or `null` when the index doesn't list it. */\nexport function findPackIndexOffset(\n\tidx: Uint8Array,\n\toid: string,\n): number | null {\n\treturn readPackIndex(idx)?.find((entry) => entry.oid === oid)?.offset ?? null;\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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KAAK,UAAU,aAAa,CAAC;AAC3C,QAAM,WAAW,aAAa,QAAQ;AACtC,QAAM,eAAe,WAAW,QAAQ;AACxC,MAAI,IAAI,aAAa,eAAe,QAAQ,EAAG,QAAO;AAEtD,QAAM,UAA4B,CAAC;AACnC,WAAS,IAAI,GAAG,IAAI,OAAO,KAAK;AAC/B,UAAM,SAAS,KAAK,UAAU,eAAe,IAAI,CAAC;AAGlD,QAAI,SAAS,OAAO,gBAAiB,QAAO;AAC5C,UAAM,KAAK,aAAa,IAAI;AAC5B,YAAQ,KAAK,EAAE,KAAK,MAAM,IAAI,SAAS,IAAI,KAAK,SAAS,CAAC,GAAG,OAAO,CAAC;AAAA,EACtE;AACA,SAAO;AACR;AAGO,SAAS,oBACf,KACA,KACgB;AAChB,SAAO,cAAc,GAAG,GAAG,KAAK,CAAC,UAAU,MAAM,QAAQ,GAAG,GAAG,UAAU;AAC1E;","names":[]}
|
|
@@ -7,9 +7,10 @@ import {
|
|
|
7
7
|
fromHex,
|
|
8
8
|
isSafeBranchName,
|
|
9
9
|
packFileName,
|
|
10
|
+
rawFs,
|
|
10
11
|
sha1,
|
|
11
12
|
toHex
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-HO6OPXUS.js";
|
|
13
14
|
|
|
14
15
|
// src/ops/branch.ts
|
|
15
16
|
import git from "isomorphic-git";
|
|
@@ -138,18 +139,6 @@ async function assertBranchExists(repo, name) {
|
|
|
138
139
|
await resolveLooseRefFast(repo, `refs/heads/${name}`);
|
|
139
140
|
}
|
|
140
141
|
|
|
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
142
|
// src/pack-write.ts
|
|
154
143
|
import git2 from "isomorphic-git";
|
|
155
144
|
var PACK_OBJECT_TYPE_BITS = {
|
|
@@ -214,6 +203,42 @@ async function storePack(repo, pack) {
|
|
|
214
203
|
return { base, oids };
|
|
215
204
|
}
|
|
216
205
|
|
|
206
|
+
// src/semaphore.ts
|
|
207
|
+
function createSemaphore(limit) {
|
|
208
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
209
|
+
throw new Error(
|
|
210
|
+
`createSemaphore: limit must be an integer >= 1, got ${limit}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
let active = 0;
|
|
214
|
+
const waiting = [];
|
|
215
|
+
function release() {
|
|
216
|
+
const next = waiting.shift();
|
|
217
|
+
if (next) next();
|
|
218
|
+
else active--;
|
|
219
|
+
}
|
|
220
|
+
function acquire() {
|
|
221
|
+
if (active < limit) {
|
|
222
|
+
active++;
|
|
223
|
+
return Promise.resolve();
|
|
224
|
+
}
|
|
225
|
+
return new Promise((resolve) => {
|
|
226
|
+
waiting.push(resolve);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return {
|
|
230
|
+
run(fn) {
|
|
231
|
+
return acquire().then(async () => {
|
|
232
|
+
try {
|
|
233
|
+
return await fn();
|
|
234
|
+
} finally {
|
|
235
|
+
release();
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
217
242
|
export {
|
|
218
243
|
assertSafeBranchName,
|
|
219
244
|
listLooseRefNames,
|
|
@@ -222,11 +247,10 @@ export {
|
|
|
222
247
|
createBranchFrom,
|
|
223
248
|
deleteBranchByName,
|
|
224
249
|
assertBranchExists,
|
|
225
|
-
runStep,
|
|
226
|
-
rawFs,
|
|
227
250
|
hashGitObject,
|
|
228
251
|
encodePack,
|
|
229
252
|
packBaseName,
|
|
230
|
-
storePack
|
|
253
|
+
storePack,
|
|
254
|
+
createSemaphore
|
|
231
255
|
};
|
|
232
|
-
//# sourceMappingURL=chunk-
|
|
256
|
+
//# sourceMappingURL=chunk-QH3HS7VI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ops/branch.ts","../src/pack-write.ts","../src/semaphore.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","/**\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","/**\n * A FIFO semaphore for bounding in-flight I/O.\n *\n * An unbounded `Promise.all` over a list whose size the caller (or an\n * attacker) controls — a git tree with tens of thousands of blob entries, say,\n * each costing one object-store read — issues that many concurrent requests\n * from a single push or clone. Sockets and memory then scale with the input,\n * and S3-compatible providers rate-limit per account, so one hostile push\n * degrades every other tenant. Bounding the *in-flight* count caps resource\n * use at `limit` no matter how wide the input is, while still letting reads\n * overlap up to that limit instead of running strictly sequentially.\n */\nexport interface Semaphore {\n\trun<T>(fn: () => Promise<T>): Promise<T>;\n}\n\n/**\n * Create a FIFO semaphore admitting at most `limit` concurrent `run`\n * executions. Waiters are queued as promises and released in call order — no\n * polling or timers — so a caller blocked on a full semaphore is woken the\n * instant a permit frees, not on the next tick of a poll loop.\n */\nexport function createSemaphore(limit: number): Semaphore {\n\tif (!Number.isInteger(limit) || limit < 1) {\n\t\tthrow new Error(\n\t\t\t`createSemaphore: limit must be an integer >= 1, got ${limit}`,\n\t\t);\n\t}\n\n\tlet active = 0;\n\tconst waiting: Array<() => void> = [];\n\n\t/**\n\t * Hand the permit to the next waiter instead of dropping it, so `active`\n\t * only decreases when nothing is queued and never exceeds `limit`.\n\t */\n\tfunction release(): void {\n\t\tconst next = waiting.shift();\n\t\tif (next) next();\n\t\telse active--;\n\t}\n\n\tfunction acquire(): Promise<void> {\n\t\tif (active < limit) {\n\t\t\tactive++;\n\t\t\treturn Promise.resolve();\n\t\t}\n\t\treturn new Promise<void>((resolve) => {\n\t\t\twaiting.push(resolve);\n\t\t});\n\t}\n\n\treturn {\n\t\trun<T>(fn: () => Promise<T>): Promise<T> {\n\t\t\treturn acquire().then(async () => {\n\t\t\t\ttry {\n\t\t\t\t\treturn await fn();\n\t\t\t\t} finally {\n\t\t\t\t\trelease();\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\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,mBAAmB,MAA0C;AAC3E,MAAI,CAAC,uBAAuB,KAAK,EAAE,EAAG,QAAO,oBAAI,IAAI;AACrD,QAAM,aAAa,cAAc,KAAK,EAAE;AACxC,MAAI,CAAC,WAAY,QAAO,oBAAI,IAAI;AAChC,MAAI;AACH,UAAM,UAAU,MAAM,WAAW;AAAA,MAChC,GAAG,KAAK,MAAM;AAAA,MACd;AAAA,IACD;AACA,UAAM,OAAO,oBAAI,IAAoB;AACrC,eAAW,QAAQ,kBA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