@ref0/git 0.26.0 → 0.29.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/dist/client/git-http.mjs +29 -12
- package/dist/client/push-upload.mjs +13 -12
- package/dist/client/remote-helper.mjs +1 -1
- package/dist/client/remote.mjs +1 -1
- package/dist/client/run-remote-helper.mjs +7 -14
- package/dist/client/slice-push.d.mts +13 -9
- package/dist/client/slice-push.mjs +16 -5
- package/dist/client/slice-report.mjs +6 -8
- package/dist/client/transport.mjs +27 -5
- package/dist/contracts/git.d.mts +17 -2
- package/dist/contracts/store.d.mts +1 -1
- package/dist/core/forks.mjs +1 -1
- package/dist/core/purge.mjs +1 -1
- package/dist/http/push-uploads.mjs +10 -15
- package/dist/lfs/copy.d.mts +4 -1
- package/dist/lfs/copy.mjs +7 -6
- package/dist/lfs/layer.mjs +1 -1
- package/dist/lfs/objects.mjs +127 -8
- package/dist/lfs/upload-most.mjs +19 -3
- package/dist/merges/merges.d.mts +3 -2
- package/dist/protocol/bytes/buffers.mjs +26 -1
- package/dist/protocol/bytes/crc32.mjs +39 -6
- package/dist/protocol/bytes/deflate.d.mts +11 -31
- package/dist/protocol/bytes/deflate.mjs +133 -72
- package/dist/protocol/bytes/inflate.d.mts +11 -6
- package/dist/protocol/bytes/inflate.mjs +184 -119
- package/dist/protocol/bytes/sha1-hasher.mjs +12 -12
- package/dist/protocol/bytes/zlib-ng/LICENSE.md +19 -0
- package/dist/protocol/bytes/zlib-ng/README.md +132 -0
- package/dist/protocol/bytes/zlib-ng/bundled.d.mts +5 -0
- package/dist/protocol/bytes/zlib-ng/bundled.mjs +8 -0
- package/dist/protocol/bytes/zlib-ng/compile.d.mts +9 -0
- package/dist/protocol/bytes/zlib-ng/compile.mjs +19 -0
- package/dist/protocol/bytes/zlib-ng/embedded.mjs +4 -0
- package/dist/protocol/bytes/zlib-ng/instance.d.mts +1 -0
- package/dist/protocol/bytes/zlib-ng/instance.mjs +111 -0
- package/dist/protocol/bytes/zlib-ng/zlib-ng.wasm +0 -0
- package/dist/protocol/objects/fsck-names.mjs +27 -7
- package/dist/protocol/objects/fsck.mjs +100 -88
- package/dist/protocol/objects/object-rules.d.mts +1 -0
- package/dist/protocol/objects/tree.d.mts +1 -0
- package/dist/protocol/objects/tree.mjs +55 -6
- package/dist/protocol/packs/reader.mjs +35 -30
- package/dist/protocol/wire/push-uploads.mjs +12 -1
- package/dist/server/registry.mjs +12 -0
- package/dist/server/server.mjs +7 -1
- package/dist/storage/budget.d.mts +2 -0
- package/dist/storage/budget.mjs +26 -24
- package/dist/storage/calls.d.mts +1 -1
- package/dist/storage/calls.mjs +4 -2
- package/dist/storage/host-bucket.mjs +15 -5
- package/dist/storage/index-bitmaps.d.mts +1 -0
- package/dist/storage/index-bitmaps.mjs +15 -14
- package/dist/storage/index-build.d.mts +2 -1
- package/dist/storage/index-build.mjs +14 -15
- package/dist/storage/index-files.mjs +3 -3
- package/dist/storage/index-graph.mjs +3 -3
- package/dist/storage/index-remap.mjs +6 -7
- package/dist/storage/links.mjs +34 -2
- package/dist/storage/loose.mjs +2 -1
- package/dist/storage/memory-budget.d.mts +1 -0
- package/dist/storage/memory-budget.mjs +12 -3
- package/dist/storage/merge-most.mjs +2 -1
- package/dist/storage/merge-stream.mjs +4 -3
- package/dist/storage/merge-write.mjs +2 -2
- package/dist/storage/pack-reads.mjs +1 -1
- package/dist/storage/pack-receive.mjs +24 -8
- package/dist/storage/packs-memory.mjs +2 -1
- package/dist/storage/packs.d.mts +3 -1
- package/dist/storage/packs.mjs +34 -11
- package/dist/storage/put-holds.d.mts +1 -0
- package/dist/storage/put-holds.mjs +20 -0
- package/dist/storage/ready.mjs +4 -2
- package/dist/storage/receive-bounds.d.mts +1 -1
- package/dist/storage/receive-bounds.mjs +4 -4
- package/dist/storage/receive-links.mjs +31 -15
- package/dist/storage/receive-steps.mjs +21 -1
- package/dist/storage/runs.d.mts +1 -1
- package/dist/storage/runs.mjs +7 -5
- package/dist/store/door.mjs +9 -1
- package/dist/store/job-try.mjs +5 -5
- package/dist/store/repo-record.mjs +1 -1
- package/dist/sync/step.mjs +3 -4
- package/package.json +12 -9
- package/dist/http/node.d.mts +0 -62
- package/dist/http/node.mjs +0 -212
- package/dist/node.d.mts +0 -3
- package/dist/node.mjs +0 -1
- package/dist/server/edge-node.d.mts +0 -19
- package/dist/server/edge-node.mjs +0 -20
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { gitmodulesFault } from "./fsck-gitmodules.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { isDotFileAt, isDotgitAt, mayBeDotName } from "./fsck-names.mjs";
|
|
3
3
|
import { isObjectType } from "./object.mjs";
|
|
4
|
-
import { hexValue, latestSecond,
|
|
5
|
-
import {
|
|
4
|
+
import { hexValue, latestSecond, mostParents } from "./object-rules.mjs";
|
|
5
|
+
import { TreeEntries, compareNamesAt } from "./tree.mjs";
|
|
6
6
|
// src/protocol/objects/fsck.ts
|
|
7
7
|
/** Git refuses a `.gitattributes` line this long or longer. */
|
|
8
8
|
const attributesLineMost = 2048;
|
|
@@ -152,116 +152,128 @@ const tagFault = (bytes) => {
|
|
|
152
152
|
};
|
|
153
153
|
/** Our refusal of a date past the latest second held, once the object has no fault Git finds. */
|
|
154
154
|
const tooLate = () => finding("dateTooLate", "invalid author/committer line - date past the latest one held");
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const entryAt = (bytes, at) => {
|
|
160
|
-
const gap = bytes.indexOf(space, at);
|
|
161
|
-
const nul = gap < 0 ? -1 : bytes.indexOf(0, gap + 1);
|
|
162
|
-
if (nul < 0 || nul + 21 > bytes.length) return void 0;
|
|
163
|
-
const mode = octalMode(bytes, at, gap);
|
|
164
|
-
if (mode === void 0 || nul === gap + 1) return void 0;
|
|
165
|
-
return {
|
|
166
|
-
zeroPadded: bytes[at] === zero,
|
|
167
|
-
kind: modeKind(mode),
|
|
168
|
-
name: bytes.subarray(gap + 1, nul),
|
|
169
|
-
oid: bytes.subarray(nul + 1, nul + 21),
|
|
170
|
-
end: nul + 21
|
|
171
|
-
};
|
|
155
|
+
/** Whether `bytes` hold the same `length` bytes from `a` and from `b`. */
|
|
156
|
+
const sameAt = (bytes, a, b, length) => {
|
|
157
|
+
for (let at = 0; at < length; at += 1) if (bytes[a + at] !== bytes[b + at]) return false;
|
|
158
|
+
return true;
|
|
172
159
|
};
|
|
173
|
-
/** Whether `bytes`
|
|
174
|
-
const
|
|
175
|
-
for (let at =
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
160
|
+
/** Whether `bytes` hold `byte` from `start` to `end`. */
|
|
161
|
+
const holds = (bytes, start, end, byte) => {
|
|
162
|
+
for (let at = start; at < end; at += 1) if (bytes[at] === byte) return true;
|
|
163
|
+
return false;
|
|
164
|
+
};
|
|
165
|
+
/** Whether the name from `start` to `end` is the one byte `.`, or two of them. */
|
|
166
|
+
const isDots = (bytes, start, end, count) => {
|
|
167
|
+
if (end - start !== count) return false;
|
|
168
|
+
for (let at = start; at < end; at += 1) if (bytes[at] !== dot) return false;
|
|
180
169
|
return true;
|
|
181
170
|
};
|
|
182
|
-
/** Whether
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
for (let at = 0; at < a.length; at += 1) if (a[at] !== b[at]) return false;
|
|
171
|
+
/** Whether the 20-byte ID at `at` is all zeros. */
|
|
172
|
+
const isNullId = (bytes, at) => {
|
|
173
|
+
for (let index = at; index < at + 20; index += 1) if (bytes[index] !== 0) return false;
|
|
186
174
|
return true;
|
|
187
175
|
};
|
|
188
|
-
/**
|
|
189
|
-
* Each checked file Git reads `entry` as. A name may read as more than one, as `~1234567` or
|
|
190
|
-
* `.gitattributes:x\.gitmodules` do, and Git checks the blob as each (#801's red team).
|
|
191
|
-
*/
|
|
192
|
-
const checkedAs = (entry) => dotFiles.filter((file) => isDotFile(entry.name, file));
|
|
193
|
-
/** Whether `name` is the one byte `.`, or two of them. */
|
|
194
|
-
const isDots = (name, count) => name.length === count && name.every((byte) => byte === dot);
|
|
195
176
|
/** An entry's first fault, of its name, its ID and its mode, in the order Git lists them. */
|
|
196
177
|
const entryFault = (entry) => {
|
|
197
|
-
|
|
198
|
-
if (
|
|
199
|
-
if (
|
|
200
|
-
if (isDots(
|
|
201
|
-
if (
|
|
202
|
-
if (
|
|
203
|
-
if (
|
|
178
|
+
const { bytes, name, nul } = entry;
|
|
179
|
+
if (isNullId(bytes, nul + 1)) return finding("nullSha1", "contains entries pointing to null sha1");
|
|
180
|
+
if (holds(bytes, name, nul, slash)) return finding("fullPathname", "contains full pathnames");
|
|
181
|
+
if (isDots(bytes, name, nul, 1)) return finding("hasDot", "contains '.'");
|
|
182
|
+
if (isDots(bytes, name, nul, 2)) return finding("hasDotdot", "contains '..'");
|
|
183
|
+
if (isDotgitAt(bytes, name, nul)) return finding("hasDotgit", "contains '.git'");
|
|
184
|
+
if (nul - name > nameMost) return finding("largePathname", "contains excessively large pathname");
|
|
185
|
+
if (bytes[entry.at] === zero) return finding("zeroPaddedFilemode", "contains zero-padded file modes");
|
|
204
186
|
};
|
|
205
|
-
const duplicate = (
|
|
187
|
+
const duplicate = (bytes, start, end) => ({
|
|
206
188
|
...finding("duplicateEntries", "contains duplicate file entries"),
|
|
207
|
-
name: new TextDecoder().decode(
|
|
189
|
+
name: new TextDecoder().decode(bytes.subarray(start, end))
|
|
208
190
|
});
|
|
209
|
-
/** Whether an entry before `end` is a file, any kind but a folder, named `
|
|
210
|
-
const fileBefore = (bytes, end,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
if (entry
|
|
214
|
-
|
|
215
|
-
|
|
191
|
+
/** Whether an entry before `end` is a file, any kind but a folder, named as `bytes` from `start` to `nul`. */
|
|
192
|
+
const fileBefore = (bytes, end, start, nul) => {
|
|
193
|
+
const entry = new TreeEntries(bytes);
|
|
194
|
+
for (let at = 0; at < end; at = entry.end()) {
|
|
195
|
+
if (!entry.read(at)) return false;
|
|
196
|
+
const named = entry.nul - entry.name === nul - start && sameAt(bytes, entry.name, start, nul - start);
|
|
197
|
+
if (entry.kind !== "tree" && named) return true;
|
|
216
198
|
}
|
|
217
199
|
return false;
|
|
218
200
|
};
|
|
219
201
|
/**
|
|
220
|
-
* A
|
|
221
|
-
* one named twice, a file and a folder of one name among them. Each entry it reads is
|
|
222
|
-
* with every one before, so a file named as a later folder is, apart from that folder,
|
|
223
|
-
* only names it starts, each next by a byte before `/`. `files` holds the files that could
|
|
224
|
-
* be a later folder's, a stack of names each the start of the next
|
|
225
|
-
* doesn't start that way. An entry out of order is the fault,
|
|
226
|
-
* once more, for a file of its name.
|
|
202
|
+
* A tree's entries in their order, checked one at a time until the first fault: one out of Git's
|
|
203
|
+
* order, or one named twice, a file and a folder of one name among them. Each entry it reads is
|
|
204
|
+
* in order with every one before, so a file named as a later folder is, apart from that folder,
|
|
205
|
+
* before only names it starts, each next by a byte before `/`. `files` holds the files that could
|
|
206
|
+
* still be a later folder's, a stack of names each the start of the next, by where each starts
|
|
207
|
+
* and ends: an entry pops the ones it doesn't start that way. An entry out of order is the fault,
|
|
208
|
+
* so the entries before it are read once more, for a file of its name.
|
|
227
209
|
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
210
|
+
var Order = class {
|
|
211
|
+
#files = [];
|
|
212
|
+
#name = -1;
|
|
213
|
+
#nul = -1;
|
|
214
|
+
#tree = false;
|
|
215
|
+
/** The fault of `entry`, the next in the tree, if it's out of order or named twice. */
|
|
216
|
+
fault(entry) {
|
|
217
|
+
const { bytes, name, nul } = entry;
|
|
232
218
|
const tree = entry.kind === "tree";
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
219
|
+
const files = this.#files;
|
|
220
|
+
const before = this.#name;
|
|
221
|
+
const beforeNul = this.#nul;
|
|
222
|
+
const beforeTree = this.#tree;
|
|
223
|
+
this.#name = name;
|
|
224
|
+
this.#nul = nul;
|
|
225
|
+
this.#tree = tree;
|
|
226
|
+
if (before >= 0 && compareNamesAt(bytes, before, beforeNul, beforeTree, bytes, name, nul, tree) >= 0) {
|
|
227
|
+
const length = nul - name;
|
|
228
|
+
return beforeNul - before === length && sameAt(bytes, before, name, length) || tree && fileBefore(bytes, entry.at, name, nul) ? duplicate(bytes, name, nul) : finding("treeNotSorted", "not properly sorted");
|
|
240
229
|
}
|
|
241
|
-
|
|
242
|
-
|
|
230
|
+
while (files.length > 0) {
|
|
231
|
+
const top = files[files.length - 2] ?? 0;
|
|
232
|
+
const topLength = (files[files.length - 1] ?? 0) - top;
|
|
233
|
+
const length = nul - name;
|
|
234
|
+
if (tree && topLength === length && sameAt(bytes, top, name, length)) return duplicate(bytes, name, nul);
|
|
235
|
+
if (topLength < length && (bytes[name + topLength] ?? slash) < slash && sameAt(bytes, top, name, topLength)) break;
|
|
236
|
+
files.length -= 2;
|
|
237
|
+
}
|
|
238
|
+
if (!tree) files.push(name, nul);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
/** The files a tree's entry names that fsck checks the blob of, once every object is read, by place. */
|
|
242
|
+
const checkedFiles = [".gitmodules", ".gitattributes"];
|
|
243
|
+
/** Each `.gitmodules` and `.gitattributes` blob a whole tree names, but by a symlink, into `checked`, in order. */
|
|
244
|
+
const addChecked = (bytes, checked) => {
|
|
245
|
+
const entry = new TreeEntries(bytes);
|
|
246
|
+
for (let at = 0; at < bytes.length && entry.read(at); at = entry.end()) {
|
|
247
|
+
if (entry.kind === "link" || !mayBeDotName(bytes, entry.name, entry.nul)) continue;
|
|
248
|
+
for (const file of checkedFiles) if (isDotFileAt(bytes, entry.name, entry.nul, file)) checked.add(bytes.subarray(entry.nul + 1, entry.nul + 21), file);
|
|
249
|
+
}
|
|
243
250
|
};
|
|
244
251
|
/**
|
|
245
|
-
* A tree's first fault: an entry's, a `.gitmodules` symlink, or entries
|
|
246
|
-
* named twice, a file and a folder of one name among them. The
|
|
247
|
-
* `.gitattributes` it names, a submodule's too, go in `checked`, past its
|
|
248
|
-
*
|
|
252
|
+
* A tree's first fault: one that isn't a tree, an entry's, a `.gitmodules` symlink, or entries
|
|
253
|
+
* out of Git's order or named twice, a file and a folder of one name among them. The
|
|
254
|
+
* `.gitmodules` and `.gitattributes` it names, a submodule's too, go in `checked`, past its
|
|
255
|
+
* first fault as well, once its entries are all read: a tree that isn't one adds none. It reads
|
|
256
|
+
* each entry once, in place, and makes nothing an entry but a name Git may read as one of its
|
|
257
|
+
* files; a tree that names one is read a second time for their blobs, so what it holds for them
|
|
258
|
+
* doesn't grow with how many it names.
|
|
249
259
|
*/
|
|
250
260
|
const treeFault = (bytes, checked) => {
|
|
251
|
-
|
|
261
|
+
const entry = new TreeEntries(bytes);
|
|
262
|
+
const order = new Order();
|
|
263
|
+
let names = false;
|
|
252
264
|
let fault;
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const entry = entryAt(bytes, at);
|
|
256
|
-
if (entry === void 0) break;
|
|
265
|
+
for (let at = 0; at < bytes.length; at = entry.end()) {
|
|
266
|
+
if (!entry.read(at)) return finding("badTree", "cannot be parsed as a tree");
|
|
257
267
|
fault ??= entryFault(entry);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
268
|
+
if (mayBeDotName(bytes, entry.name, entry.nul)) {
|
|
269
|
+
const link = entry.kind === "link";
|
|
270
|
+
const modules = isDotFileAt(bytes, entry.name, entry.nul, ".gitmodules");
|
|
271
|
+
if (modules && link) fault ??= finding("gitmodulesSymlink", ".gitmodules is a symbolic link");
|
|
272
|
+
names ||= !link && (modules || isDotFileAt(bytes, entry.name, entry.nul, ".gitattributes"));
|
|
261
273
|
}
|
|
262
|
-
fault ??=
|
|
263
|
-
at = entry.end;
|
|
274
|
+
fault ??= order.fault(entry);
|
|
264
275
|
}
|
|
276
|
+
if (names) addChecked(bytes, checked);
|
|
265
277
|
return fault;
|
|
266
278
|
};
|
|
267
279
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../contracts/ids.mjs";
|
|
@@ -3,7 +3,7 @@ import { hexOf } from "../bytes/hex.mjs";
|
|
|
3
3
|
import { joinedBytes } from "../bytes/joined.mjs";
|
|
4
4
|
import { isOid, isWellFormed, quoted } from "../bytes/text.mjs";
|
|
5
5
|
import { isTreeMode, objectId } from "./object.mjs";
|
|
6
|
-
import { canonicalMode, octalMode } from "./object-rules.mjs";
|
|
6
|
+
import { canonicalMode, modeKind, octalMode } from "./object-rules.mjs";
|
|
7
7
|
import * as Effect from "effect/Effect";
|
|
8
8
|
import * as Result from "effect/Result";
|
|
9
9
|
import * as Hex from "effect/encoding/Hex";
|
|
@@ -17,13 +17,22 @@ function compareEntries(a, b) {
|
|
|
17
17
|
}
|
|
18
18
|
/** `compareEntries` by each entry's name and whether it's a folder, for a caller with no mode. */
|
|
19
19
|
function compareNames(a, aTree, b, bTree) {
|
|
20
|
-
|
|
20
|
+
return compareNamesAt(a, 0, a.length, aTree, b, 0, b.length, bTree);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `compareNames` of the names `a` holds from `aStart` to `aEnd` and `b` from `bStart` to `bEnd`,
|
|
24
|
+
* read in place, for a caller that reads a tree's entries by their offsets.
|
|
25
|
+
*/
|
|
26
|
+
function compareNamesAt(a, aStart, aEnd, aTree, b, bStart, bEnd, bTree) {
|
|
27
|
+
const aLength = aEnd - aStart;
|
|
28
|
+
const bLength = bEnd - bStart;
|
|
29
|
+
const length = Math.min(aLength, bLength);
|
|
21
30
|
for (let at = 0; at < length; at += 1) {
|
|
22
|
-
const x = a[at] ?? 0;
|
|
23
|
-
const y = b[at] ?? 0;
|
|
31
|
+
const x = a[aStart + at] ?? 0;
|
|
32
|
+
const y = b[bStart + at] ?? 0;
|
|
24
33
|
if (x !== y) return x - y;
|
|
25
34
|
}
|
|
26
|
-
return (a[length] ??
|
|
35
|
+
return (length < aLength ? a[aStart + length] ?? 0 : aTree ? 47 : 0) - (length < bLength ? b[bStart + length] ?? 0 : bTree ? 47 : 0);
|
|
27
36
|
}
|
|
28
37
|
const notATree = (message) => Result.fail(new WireDecodeError({
|
|
29
38
|
what: "tree",
|
|
@@ -45,6 +54,46 @@ const treeEntriesIn = (bytes) => {
|
|
|
45
54
|
return count;
|
|
46
55
|
};
|
|
47
56
|
/**
|
|
57
|
+
* A tree's entries, `<octal mode> <name>\0<id>`, read in place, as leniently as fsck reads them:
|
|
58
|
+
* a mode of octal digits, a name of one byte or more, and a whole ID. One cursor a tree, moved
|
|
59
|
+
* from entry to entry, so a reader of every entry makes nothing an entry: its name and ID are
|
|
60
|
+
* offsets into the tree's bytes. It finds each entry's space and NUL a byte at a time, since a
|
|
61
|
+
* mode and a name are short, and a call out for each costs more than reading them.
|
|
62
|
+
*/
|
|
63
|
+
var TreeEntries = class {
|
|
64
|
+
/** Where the entry starts. */
|
|
65
|
+
at = 0;
|
|
66
|
+
kind = "blob";
|
|
67
|
+
/** Where its name starts. */
|
|
68
|
+
name = 0;
|
|
69
|
+
/** Where its name ends, at its NUL, which its 20-byte ID follows. */
|
|
70
|
+
nul = 0;
|
|
71
|
+
bytes;
|
|
72
|
+
constructor(bytes) {
|
|
73
|
+
this.bytes = bytes;
|
|
74
|
+
}
|
|
75
|
+
/** Reads the entry at `at`, or `false` when its bytes aren't one. */
|
|
76
|
+
read(at) {
|
|
77
|
+
const bytes = this.bytes;
|
|
78
|
+
let gap = at;
|
|
79
|
+
while (gap < bytes.length && bytes[gap] !== 32) gap += 1;
|
|
80
|
+
let nul = gap + 1;
|
|
81
|
+
while (nul < bytes.length && bytes[nul] !== 0) nul += 1;
|
|
82
|
+
if (nul + 21 > bytes.length) return false;
|
|
83
|
+
const mode = octalMode(bytes, at, gap);
|
|
84
|
+
if (mode === void 0 || nul === gap + 1) return false;
|
|
85
|
+
this.at = at;
|
|
86
|
+
this.kind = modeKind(mode);
|
|
87
|
+
this.name = gap + 1;
|
|
88
|
+
this.nul = nul;
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/** Where the next entry starts. */
|
|
92
|
+
end() {
|
|
93
|
+
return this.nul + 21;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
48
97
|
* The entries of a tree's bytes, in their order. Bytes that aren't a tree Git walks as written
|
|
49
98
|
* fail: a mode that isn't octal, an empty name or one holding `/`, an ID cut short, or entries
|
|
50
99
|
* out of Git's order or named twice.
|
|
@@ -176,4 +225,4 @@ const treeMatches = (oid, entries) => encodeTree(entries).pipe(Effect.flatMap((b
|
|
|
176
225
|
type: "tree",
|
|
177
226
|
bytes
|
|
178
227
|
})), Effect.map((id) => id === oid));
|
|
179
|
-
export { compareEntries, compareNames, encodeTree, parseTreeBytes, treeBytes, treeEntriesIn, treeIdReader, treeMatches, treeReader };
|
|
228
|
+
export { TreeEntries, compareEntries, compareNames, compareNamesAt, encodeTree, parseTreeBytes, treeBytes, treeEntriesIn, treeIdReader, treeMatches, treeReader };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BufferError, allotOrFail, allotScoped, capacityOf } from "../bytes/buffers.mjs";
|
|
2
2
|
import { crc32Update } from "../bytes/crc32.mjs";
|
|
3
3
|
import { hexOf } from "../bytes/hex.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { chunkInflater, inflateWindow, inflaterBytes, openChunkInflater } from "../bytes/inflate.mjs";
|
|
5
5
|
import { flushPkt } from "../framing/pkt-line.mjs";
|
|
6
6
|
import { objectTypes } from "../objects/object.mjs";
|
|
7
7
|
import { stepEffect } from "./step.mjs";
|
|
@@ -60,6 +60,8 @@ const entryKinds = [
|
|
|
60
60
|
/** How much a reader asks of its transport at a time, and the size of its inflate output. */
|
|
61
61
|
const packReadBytes = 65536;
|
|
62
62
|
const sizeOfFlush = flushPkt.byteLength;
|
|
63
|
+
/** What an inflater takes in place of a chunk that's used up, so it keeps none. */
|
|
64
|
+
const noBytes = /* @__PURE__ */ new Uint8Array(0);
|
|
63
65
|
/** A transport's read that failed: a broken or cancelled body. */
|
|
64
66
|
var PackTransportError = class extends Schema.TaggedError()("PackTransportError", { cause: Schema.Unknown }) {};
|
|
65
67
|
/**
|
|
@@ -275,7 +277,7 @@ const readPackFrom = (source, hasher, sink, limits, meter, resume) => Effect.sco
|
|
|
275
277
|
yield* allotScoped(meter, "inflater", inflaterBytes);
|
|
276
278
|
yield* allotScoped(meter, "inflated", packReadBytes);
|
|
277
279
|
yield* allotScoped(meter, "header", 96 + sizeOfFlush);
|
|
278
|
-
const inflater = yield* Effect.mapError(
|
|
280
|
+
const inflater = yield* Effect.mapError(chunkInflater, (error) => fail("zlib", error.message));
|
|
279
281
|
const output = new Uint8Array(packReadBytes);
|
|
280
282
|
const header = new Uint8Array(headerBytesMost);
|
|
281
283
|
const fixed = /* @__PURE__ */ new Uint8Array(12);
|
|
@@ -306,6 +308,7 @@ const readPackFrom = (source, hasher, sink, limits, meter, resume) => Effect.sco
|
|
|
306
308
|
}
|
|
307
309
|
let at = 0;
|
|
308
310
|
let hashFrom = 0;
|
|
311
|
+
inflater.take(chunk);
|
|
309
312
|
while (at < chunk.byteLength) {
|
|
310
313
|
if (phase === "header") {
|
|
311
314
|
const take = Math.min(12 - fixedLength, chunk.byteLength - at);
|
|
@@ -388,7 +391,7 @@ const readPackFrom = (source, hasher, sink, limits, meter, resume) => Effect.sco
|
|
|
388
391
|
continue;
|
|
389
392
|
}
|
|
390
393
|
if (phase === "data" && entry !== void 0) {
|
|
391
|
-
const inflatedStep = inflater.
|
|
394
|
+
const inflatedStep = inflater.inflateAt(at, output.byteLength);
|
|
392
395
|
if (Result.isFailure(inflatedStep)) return yield* fail("zlib", inflatedStep.failure.message);
|
|
393
396
|
const inflated = inflatedStep.success;
|
|
394
397
|
if (crcs) crc = crc32Update(crc, chunk.subarray(at, at + inflated.consumed));
|
|
@@ -396,6 +399,7 @@ const readPackFrom = (source, hasher, sink, limits, meter, resume) => Effect.sco
|
|
|
396
399
|
compressed += inflated.consumed;
|
|
397
400
|
produced += inflated.produced;
|
|
398
401
|
if (produced > entry.size) return yield* fail("length", `an entry inflates past its ${entry.size} bytes`);
|
|
402
|
+
if (inflated.produced > 0) output.set(inflater.output(inflated.produced));
|
|
399
403
|
const took = inflated.produced > 0 ? sink.data(output.subarray(0, inflated.produced)) : void 0;
|
|
400
404
|
if (took !== void 0) yield* stepEffect(took);
|
|
401
405
|
if (inflated.kind !== "end") continue;
|
|
@@ -446,6 +450,7 @@ const readPackFrom = (source, hasher, sink, limits, meter, resume) => Effect.sco
|
|
|
446
450
|
hashFrom = at;
|
|
447
451
|
}
|
|
448
452
|
if (phase !== "trailer" && phase !== "after" && hashFrom < chunk.byteLength) yield* hasher.write(chunk.subarray(hashFrom));
|
|
453
|
+
inflater.take(noBytes);
|
|
449
454
|
}
|
|
450
455
|
return {
|
|
451
456
|
version,
|
|
@@ -456,14 +461,12 @@ const readPackFrom = (source, hasher, sink, limits, meter, resume) => Effect.sco
|
|
|
456
461
|
};
|
|
457
462
|
}));
|
|
458
463
|
const readUint32 = (bytes, at) => (bytes[at] ?? 0) * 2 ** 24 + ((bytes[at + 1] ?? 0) << 16) + ((bytes[at + 2] ?? 0) << 8) + (bytes[at + 3] ?? 0);
|
|
459
|
-
const entryParts = [
|
|
460
|
-
["inflater", inflaterBytes],
|
|
461
|
-
["inflated", packReadBytes],
|
|
462
|
-
["header", headerBytesMost]
|
|
463
|
-
];
|
|
464
|
+
const entryParts = [["inflater", inflaterBytes], ["header", headerBytesMost]];
|
|
464
465
|
/**
|
|
465
|
-
* Opens a reusable single-entry reader charged to `meter` (`inflater`, `
|
|
466
|
-
* `close()`.
|
|
466
|
+
* Opens a reusable single-entry reader charged to `meter` (`inflater`, `header`) until
|
|
467
|
+
* `close()`. It holds an inflater only while it reads: one opens at a read's first data and ends
|
|
468
|
+
* on every exit. An inflater's stream is in zlib-ng's memory, which a collection never frees, so
|
|
469
|
+
* a reader its owner never closes, as `PackBlocks`' readers aren't, still holds none of it.
|
|
467
470
|
*/
|
|
468
471
|
const openEntryReader = (meter) => {
|
|
469
472
|
const taken = [];
|
|
@@ -483,35 +486,33 @@ const openEntryReader = (meter) => {
|
|
|
483
486
|
}
|
|
484
487
|
taken.push(part);
|
|
485
488
|
}
|
|
486
|
-
|
|
487
|
-
if (Result.isFailure(opened)) {
|
|
488
|
-
freeAll();
|
|
489
|
-
return Result.fail(fail("zlib", opened.failure.message));
|
|
490
|
-
}
|
|
491
|
-
const inflater = opened.success;
|
|
492
|
-
let output = new Uint8Array(packReadBytes);
|
|
489
|
+
let inflater;
|
|
493
490
|
let header = new Uint8Array(headerBytesMost);
|
|
494
491
|
let closed = false;
|
|
495
|
-
|
|
492
|
+
/** The read's inflater, opened at its first data, or a failure saying why it couldn't be. */
|
|
493
|
+
const reading = () => {
|
|
494
|
+
if (inflater !== void 0) return Result.succeed(inflater);
|
|
495
|
+
const opened = openChunkInflater();
|
|
496
|
+
if (Result.isSuccess(opened)) inflater = opened.success;
|
|
497
|
+
return opened;
|
|
498
|
+
};
|
|
496
499
|
const close = () => {
|
|
497
500
|
if (closed) return;
|
|
498
501
|
closed = true;
|
|
499
|
-
|
|
500
|
-
inflater
|
|
501
|
-
output = void 0;
|
|
502
|
+
inflater?.end();
|
|
503
|
+
inflater = void 0;
|
|
502
504
|
header = void 0;
|
|
503
505
|
freeAll();
|
|
504
506
|
};
|
|
507
|
+
/** Ends the read's inflater, if it opened one: the next read opens its own. */
|
|
505
508
|
const reset = () => {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
if (Result.isFailure(inflater.reset())) close();
|
|
509
|
+
inflater?.end();
|
|
510
|
+
inflater = void 0;
|
|
509
511
|
};
|
|
510
512
|
/** Shared header + zlib inflate stepper used by both `tryReadSync` and `read`. */
|
|
511
513
|
const entryDecoder = (offset, limits, before, resume) => {
|
|
512
|
-
const outBuf = output;
|
|
513
514
|
const headBuf = header;
|
|
514
|
-
if (closed ||
|
|
515
|
+
if (closed || headBuf === void 0) throw new Error("a closed entry reader cannot read");
|
|
515
516
|
let headerLength = resume?.headerLength ?? 0;
|
|
516
517
|
let active = resume === void 0 ? void 0 : {
|
|
517
518
|
entry: resume.entry,
|
|
@@ -555,16 +556,19 @@ const openEntryReader = (meter) => {
|
|
|
555
556
|
if (active === void 0) return void 0;
|
|
556
557
|
}
|
|
557
558
|
const { entry, data } = active;
|
|
559
|
+
const opened = reading();
|
|
560
|
+
if (Result.isFailure(opened)) return fail("zlib", opened.failure.message);
|
|
561
|
+
const inflating = opened.success;
|
|
562
|
+
inflating.take(chunk);
|
|
558
563
|
while (at < chunk.byteLength) {
|
|
559
|
-
|
|
560
|
-
const step = inflater.inflate(chunk.subarray(at), outBuf);
|
|
564
|
+
const step = inflating.inflateAt(at, inflateWindow);
|
|
561
565
|
if (Result.isFailure(step)) return fail("zlib", step.failure.message);
|
|
562
566
|
const inflated = step.success;
|
|
563
567
|
at += inflated.consumed;
|
|
564
568
|
compressed += inflated.consumed;
|
|
565
569
|
if (produced + inflated.produced > entry.size) return fail("length", `an entry inflates past its ${entry.size} bytes`);
|
|
566
570
|
if (inflated.produced > 0) {
|
|
567
|
-
data.set(
|
|
571
|
+
data.set(inflating.output(inflated.produced), produced);
|
|
568
572
|
produced += inflated.produced;
|
|
569
573
|
}
|
|
570
574
|
if (inflated.kind === "end") return produced === entry.size ? {
|
|
@@ -572,8 +576,9 @@ const openEntryReader = (meter) => {
|
|
|
572
576
|
data,
|
|
573
577
|
stored: compressed
|
|
574
578
|
} : fail("length", `an entry inflated to ${produced}, not ${entry.size}`);
|
|
575
|
-
if (inflated.kind === "more")
|
|
579
|
+
if (inflated.kind === "more") break;
|
|
576
580
|
}
|
|
581
|
+
inflating.take(noBytes);
|
|
577
582
|
};
|
|
578
583
|
return {
|
|
579
584
|
stepChunk,
|
|
@@ -20,8 +20,19 @@ const capNumber = (capabilities, name, nonzero) => {
|
|
|
20
20
|
const pushUploadAbove = (capabilities) => capNumber(capabilities, pushUploadCapability, false);
|
|
21
21
|
/** The max pack bytes a receive-pack advertisement's `ref0-push-bytes=<most>` allows, if any. */
|
|
22
22
|
const pushBytesLimit = (capabilities) => capNumber(capabilities, "ref0-push-bytes", true);
|
|
23
|
+
/**
|
|
24
|
+
* The share of the time since an upload's claim that complete's 202 asks a client to wait. A push
|
|
25
|
+
* that lands at once is seen within about a second, and one that runs long is asked about less
|
|
26
|
+
* often, seen late by at most about this share of the time it took: a push of 64 MiB that landed
|
|
27
|
+
* 9.0 s after its 202 on Vercel was seen 13.2 s after it at half. The server knows the claim on any
|
|
28
|
+
* host, where a try's CPU, which some hosts don't name, says nothing of how long a push takes
|
|
29
|
+
* (#3103).
|
|
30
|
+
*/
|
|
31
|
+
const retryAfterShare = .25;
|
|
23
32
|
/** `seconds` within `retryAfterLeast` and `retryAfterMost`, whole. */
|
|
24
33
|
const retryAfterOf = (seconds) => Math.min(Math.max(Math.ceil(seconds), 1), 10);
|
|
34
|
+
/** The `Retry-After` for an upload claimed `claimedMs` ago: `retryAfterShare` of it, held. */
|
|
35
|
+
const retryAfterSince = (claimedMs) => retryAfterOf(retryAfterShare * claimedMs / 1e3);
|
|
25
36
|
/**
|
|
26
37
|
* The least time a claimed upload keeps before its row's `removeAt`, set at begin a day past its
|
|
27
38
|
* links' hour: complete claims an upload only this long or more before it, so upkeep leaves its
|
|
@@ -32,4 +43,4 @@ const retryAfterOf = (seconds) => Math.min(Math.max(Math.ceil(seconds), 1), 10);
|
|
|
32
43
|
* report.
|
|
33
44
|
*/
|
|
34
45
|
const completeMost = 432e5;
|
|
35
|
-
export { completeMost, pushBytesLimit, pushUploadAbove, pushUploadCapability, pushUploadOffer, retryAfterOf };
|
|
46
|
+
export { completeMost, pushBytesLimit, pushUploadAbove, pushUploadCapability, pushUploadOffer, retryAfterOf, retryAfterShare, retryAfterSince };
|
package/dist/server/registry.mjs
CHANGED
|
@@ -11,7 +11,9 @@ import { gitsOwnRefs, registeredRow } from "../protocol/wire/lines.mjs";
|
|
|
11
11
|
import { requestBudget } from "../store/call-count.mjs";
|
|
12
12
|
import { noCall, syncIn } from "../store/crossing.mjs";
|
|
13
13
|
import { gitJob } from "../store/job-try.mjs";
|
|
14
|
+
import { putHeldBytes } from "../storage/put-holds.mjs";
|
|
14
15
|
import { defaultFetchLimits } from "../storage/fetch.mjs";
|
|
16
|
+
import { putBusy } from "../storage/memory-budget.mjs";
|
|
15
17
|
import { answersMethod, bySpecificity, matchPath, routePath } from "./route-match.mjs";
|
|
16
18
|
import * as Effect from "effect/Effect";
|
|
17
19
|
import * as Context from "effect/Context";
|
|
@@ -76,6 +78,7 @@ const openRegistry = (served = unserved) => {
|
|
|
76
78
|
const repoScopes = [];
|
|
77
79
|
let rowsBase;
|
|
78
80
|
let recordsBase;
|
|
81
|
+
let budgetBase;
|
|
79
82
|
const ownedScopes = [...gitsOwnScopes];
|
|
80
83
|
const deliveries = [];
|
|
81
84
|
let makeDeliveries = () => [];
|
|
@@ -197,6 +200,12 @@ const openRegistry = (served = unserved) => {
|
|
|
197
200
|
fetchWindow: served.fetchWindow,
|
|
198
201
|
addSealCheck,
|
|
199
202
|
allowance: () => syncIn(requestBudget(served.requestMost), noCall),
|
|
203
|
+
putCharge: (multipart, body) => Effect.suspend(() => {
|
|
204
|
+
const held = putHeldBytes(multipart, body);
|
|
205
|
+
if (held === 0 || budgetBase === void 0) return Effect.void;
|
|
206
|
+
if (held > budgetBase.mostOf(true)) return Effect.die(/* @__PURE__ */ new RangeError(`A put holds ${held} bytes, past upkeep's ${budgetBase.mostOf(true)}`));
|
|
207
|
+
return Effect.asVoid(budgetBase.upkeep(held, putBusy));
|
|
208
|
+
}),
|
|
200
209
|
addPushCheck: (check) => adding(() => {
|
|
201
210
|
const entry = orderedOf(name, check);
|
|
202
211
|
checks.push({
|
|
@@ -320,6 +329,9 @@ const openRegistry = (served = unserved) => {
|
|
|
320
329
|
bindRecords: (records) => {
|
|
321
330
|
recordsBase = records;
|
|
322
331
|
},
|
|
332
|
+
bindBudget: (budget) => {
|
|
333
|
+
budgetBase = budget;
|
|
334
|
+
},
|
|
323
335
|
bindDeliveries: (make) => {
|
|
324
336
|
makeDeliveries = make;
|
|
325
337
|
},
|
package/dist/server/server.mjs
CHANGED
|
@@ -14,6 +14,7 @@ import { identifier } from "../auth/identify.mjs";
|
|
|
14
14
|
import { tokenCleanupJob } from "../auth/token-cleanup.mjs";
|
|
15
15
|
import { TokensBase } from "../auth/tokens-base.mjs";
|
|
16
16
|
import { blobCalls } from "../core/objects/blobs.mjs";
|
|
17
|
+
import { putHeldBytes } from "../storage/put-holds.mjs";
|
|
17
18
|
import { commitCalls } from "../core/objects/commits.mjs";
|
|
18
19
|
import { fileCalls } from "../core/objects/files.mjs";
|
|
19
20
|
import { mergeCalls } from "../core/objects/merges.mjs";
|
|
@@ -63,6 +64,7 @@ import { pushUploadMost, pushUploadUpkeep } from "../storage/push-uploads.mjs";
|
|
|
63
64
|
import { stageStepOf } from "../storage/receive-steps.mjs";
|
|
64
65
|
import { checkedLimits, countedMost, hookCallsBefore, lessBefore } from "../store/call-count.mjs";
|
|
65
66
|
import { jobLimitsOf, jobsWithin } from "../store/job-try.mjs";
|
|
67
|
+
import { putMemoryLeast } from "../storage/budget.mjs";
|
|
66
68
|
import { budgetOfObjects, requestBudgetOf } from "../storage/memory-budget.mjs";
|
|
67
69
|
import { RequestMemoryBudget, serverRequestBudget } from "../storage/request-cache.mjs";
|
|
68
70
|
import { pruneFloor } from "../storage/rows.mjs";
|
|
@@ -140,6 +142,10 @@ const wireServer = (options, wiring) => {
|
|
|
140
142
|
const indexed = wiring.access === void 0 ? void 0 : indexedOpen(options.objects, opening);
|
|
141
143
|
const objects = indexed ?? options.objects.open(opening);
|
|
142
144
|
const rawBudget = budgetOfObjects(objects);
|
|
145
|
+
const puts = adapter.bucket?.multipart;
|
|
146
|
+
const putMost = puts === void 0 ? 0 : putHeldBytes(puts);
|
|
147
|
+
if (puts !== void 0 && rawBudget !== void 0 && rawBudget.mostOf(true) < putMost) throw new RangeError(`The objects' memory leaves upkeep ${rawBudget.mostOf(true)} bytes, short of the ${putMost} one put to the bucket holds: give them at least ${putMemoryLeast(puts)}, as packs({ memory }) takes`);
|
|
148
|
+
extensions.registry.bindBudget(rawBudget);
|
|
143
149
|
const memoryBudget = rawBudget === void 0 ? void 0 : serverRequestBudget(requestBudgetOf(rawBudget));
|
|
144
150
|
const sealed = indexed === void 0 ? new SealedObjects(objects) : SealedObjects.indexed(indexed);
|
|
145
151
|
const cleanup = tokenCleanupJob(store, now);
|
|
@@ -320,7 +326,7 @@ const wireServer = (options, wiring) => {
|
|
|
320
326
|
staging,
|
|
321
327
|
attach: (above) => Effect.suspend(() => {
|
|
322
328
|
if (staging === void 0 || uploadsAttached !== void 0) return Effect.die(/* @__PURE__ */ new TypeError("The server takes push uploads: provide Git.layerUploads once"));
|
|
323
|
-
uploadsAttached = make$2(needs, staging, above
|
|
329
|
+
uploadsAttached = make$2(needs, staging, above);
|
|
324
330
|
return Effect.void;
|
|
325
331
|
})
|
|
326
332
|
});
|