@ref0/git 0.27.0 → 0.30.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.
Files changed (79) hide show
  1. package/dist/client/git-http.mjs +29 -12
  2. package/dist/client/push-upload.mjs +13 -12
  3. package/dist/client/remote-helper.mjs +1 -1
  4. package/dist/client/remote.mjs +1 -1
  5. package/dist/client/run-remote-helper.mjs +7 -14
  6. package/dist/client/slice-push.d.mts +13 -9
  7. package/dist/client/slice-push.mjs +16 -5
  8. package/dist/client/slice-report.mjs +6 -8
  9. package/dist/client/transport.mjs +27 -5
  10. package/dist/contracts/git.d.mts +17 -2
  11. package/dist/contracts/store.d.mts +1 -1
  12. package/dist/core/forks.mjs +1 -1
  13. package/dist/core/purge.mjs +1 -1
  14. package/dist/http/push-uploads.mjs +10 -15
  15. package/dist/lfs/copy.d.mts +4 -1
  16. package/dist/lfs/copy.mjs +7 -6
  17. package/dist/lfs/layer.mjs +1 -1
  18. package/dist/lfs/objects.mjs +127 -8
  19. package/dist/lfs/upload-most.mjs +19 -3
  20. package/dist/merges/merges.d.mts +3 -2
  21. package/dist/protocol/bytes/buffers.mjs +5 -5
  22. package/dist/protocol/bytes/crc32.mjs +39 -6
  23. package/dist/protocol/bytes/deflate.d.mts +11 -31
  24. package/dist/protocol/bytes/deflate.mjs +133 -72
  25. package/dist/protocol/bytes/inflate.mjs +2 -2
  26. package/dist/protocol/bytes/sha1-hasher.mjs +12 -12
  27. package/dist/protocol/bytes/zlib-ng/README.md +65 -38
  28. package/dist/protocol/bytes/zlib-ng/compile.d.mts +5 -4
  29. package/dist/protocol/bytes/zlib-ng/compile.mjs +5 -4
  30. package/dist/protocol/bytes/zlib-ng/embedded.mjs +1 -1
  31. package/dist/protocol/bytes/zlib-ng/instance.mjs +14 -8
  32. package/dist/protocol/bytes/zlib-ng/zlib-ng.wasm +0 -0
  33. package/dist/protocol/objects/fsck-names.mjs +27 -7
  34. package/dist/protocol/objects/fsck.mjs +100 -88
  35. package/dist/protocol/objects/object-rules.d.mts +1 -0
  36. package/dist/protocol/objects/tree.d.mts +1 -0
  37. package/dist/protocol/objects/tree.mjs +55 -6
  38. package/dist/protocol/wire/push-uploads.mjs +12 -1
  39. package/dist/server/registry.mjs +12 -0
  40. package/dist/server/server.mjs +7 -1
  41. package/dist/storage/budget.d.mts +2 -1
  42. package/dist/storage/budget.mjs +25 -9
  43. package/dist/storage/calls.d.mts +1 -1
  44. package/dist/storage/calls.mjs +4 -2
  45. package/dist/storage/host-bucket.mjs +15 -5
  46. package/dist/storage/index-bitmaps.d.mts +1 -0
  47. package/dist/storage/index-bitmaps.mjs +15 -14
  48. package/dist/storage/index-build.d.mts +2 -1
  49. package/dist/storage/index-build.mjs +14 -16
  50. package/dist/storage/index-files.mjs +3 -3
  51. package/dist/storage/index-graph.mjs +3 -3
  52. package/dist/storage/index-remap.mjs +6 -7
  53. package/dist/storage/links.mjs +34 -2
  54. package/dist/storage/memory-budget.mjs +12 -3
  55. package/dist/storage/merge-stream.mjs +4 -3
  56. package/dist/storage/merge-write.mjs +2 -2
  57. package/dist/storage/pack-receive.mjs +24 -8
  58. package/dist/storage/packs.d.mts +3 -1
  59. package/dist/storage/packs.mjs +33 -11
  60. package/dist/storage/put-holds.d.mts +1 -0
  61. package/dist/storage/put-holds.mjs +20 -0
  62. package/dist/storage/ready.mjs +4 -2
  63. package/dist/storage/receive-bounds.d.mts +1 -1
  64. package/dist/storage/receive-bounds.mjs +4 -4
  65. package/dist/storage/receive-links.mjs +31 -15
  66. package/dist/storage/receive-steps.mjs +21 -1
  67. package/dist/storage/runs.d.mts +1 -1
  68. package/dist/storage/runs.mjs +7 -5
  69. package/dist/store/door.mjs +9 -1
  70. package/dist/store/job-try.mjs +5 -5
  71. package/dist/store/repo-record.mjs +1 -1
  72. package/dist/sync/step.mjs +3 -4
  73. package/package.json +3 -9
  74. package/dist/http/node.d.mts +0 -62
  75. package/dist/http/node.mjs +0 -212
  76. package/dist/node.d.mts +0 -3
  77. package/dist/node.mjs +0 -1
  78. package/dist/server/edge-node.d.mts +0 -19
  79. package/dist/server/edge-node.mjs +0 -20
@@ -1,5 +1,6 @@
1
1
  import { Oid } from "../../contracts/ids.mjs";
2
2
  import { WireDecodeError, WireEncodeError } from "../bytes/errors.mjs";
3
+ import "./object-rules.mjs";
3
4
  import * as Effect from "effect/Effect";
4
5
  import "effect/Result";
5
6
  /**
@@ -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
- const length = Math.min(a.length, b.length);
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] ?? (aTree ? 47 : 0)) - (b[length] ?? (bTree ? 47 : 0));
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 };
@@ -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 };
@@ -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
  },
@@ -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, adapter.requestLimits.cpuMs);
329
+ uploadsAttached = make$2(needs, staging, above);
324
330
  return Effect.void;
325
331
  })
326
332
  });
@@ -1 +1,2 @@
1
- import "../protocol/bytes/buffers.mjs";
1
+ import "../protocol/bytes/buffers.mjs";
2
+ import "./put-holds.mjs";
@@ -2,11 +2,10 @@ import { allottableOf, defaultMemory, headroomBytes, idleHeapBytes } from "../pr
2
2
  import { receiveCheckedBytes } from "./fsck.mjs";
3
3
  import { receiveIndexHeldOf, receiveRoomAdmitted } from "./receive-admission.mjs";
4
4
  import { receiveTableMost } from "./receive-bounds.mjs";
5
+ import { putHeldBytes, uploadPartBytes } from "./put-holds.mjs";
5
6
  import { blockBytes, blockHeld, blocksHeld, packIndexerLimits, readCacheBytes } from "./pack-reads.mjs";
6
7
  // src/storage/budget.ts
7
8
  const mib = 1048576;
8
- /** The part a bucket's upload holds, R2's for a push of unknown size: 8 MiB. */
9
- const uploadPartBytes = 8 * mib;
10
9
  /** A reader's floors: a read cache of 2 MiB and one block. */
11
10
  const readerFloors = {
12
11
  cache: 2 * mib,
@@ -20,10 +19,20 @@ const readerMost = {
20
19
  blocks: 8 * blockHeld(blockBytes)
21
20
  };
22
21
  /**
23
- * The part a push's put holds: none when its length is known, `atMost` when that's under 8 MiB,
24
- * and the whole 8 MiB for a chunked body.
22
+ * What a staged receive's step puts of its pack: none. Its pack was staged whole before it, and a
23
+ * step reads it back from the bucket, so it holds no part of it on any bucket, whatever its length.
24
+ * The index files it puts are charged where they're put, in `receivePack`'s room (#3096).
25
25
  */
26
- const pushPartBytes = (size) => size.length !== void 0 ? 0 : Math.min(uploadPartBytes, size.atMost ?? 8388608);
26
+ const stagedPuts = {
27
+ partSize: uploadPartBytes,
28
+ buffersMost: 0,
29
+ wholeMost: Number.POSITIVE_INFINITY
30
+ };
31
+ /** The parts a push's put holds, its pack told its `length` when known: `putHeldBytes`. */
32
+ const pushPartBytes = (size) => putHeldBytes(size.multipart, {
33
+ size: size.length,
34
+ atMost: size.atMost
35
+ });
27
36
  /**
28
37
  * A push's floors, scaled to it, each capped at what push-90mib's receive took no more CPU at: a
29
38
  * base cache of `min(4 MiB, objects × 32 KiB)` and its pack's first two blocks as `blocksHeld`
@@ -84,10 +93,11 @@ const pushAdmissionOf = (size) => pushFixedOf(size) + receiveRoomAdmitted(size.o
84
93
  /**
85
94
  * The most objects a push of `size`'s length takes in a `packs()` instance of `memory`, at most
86
95
  * `receiveTableMost`: the most whose admission fits beside the read reserve, and whose index files
87
- * fit beside it too as they're made. In a Worker's 128 MB, 1,215,694 for a chunked push. What a
88
- * push takes is the less of it and what a prune walk holds an index of, `pushObjectsMostOf`.
96
+ * fit beside it too as they're made. In a Worker's 128 MB, 641,583 for a chunked push to R2 or
97
+ * Blob, whose put holds four 8 MiB parts, and 1,215,694 to the memory bucket, which holds one. What
98
+ * a push takes is the less of it and what a prune walk holds an index of, `pushObjectsMostOf`.
89
99
  */
90
- const receiveObjectsMostOf = (memory, size = {}) => {
100
+ const receiveObjectsMostOf = (memory, size) => {
91
101
  const room = allottableOf(memory) - readReserveBytes;
92
102
  let low = 0;
93
103
  let high = receiveTableMost;
@@ -127,6 +137,12 @@ const unpackInflatedMost = 16 * mib;
127
137
  */
128
138
  const readReserveBytes = fetchFloorBytes;
129
139
  /**
140
+ * The least memory whose upkeep share, all of it but the idle heap, the headroom and the read
141
+ * reserve, holds one put to a bucket of `multipart` alone, all a put of any body holds
142
+ * (`putHeldBytes`): what a server's objects take beside its bucket, as its puts are charged there.
143
+ */
144
+ const putMemoryLeast = (multipart) => idleHeapBytes + headroomBytes + readReserveBytes + putHeldBytes(multipart);
145
+ /**
130
146
  * The most decoded/base64 object-row bytes one fetch request's row cache keeps between `heldHaves`,
131
147
  * `planFetch`, and `rowsFirst` (#2899). Inline rows that fit both this byte cap and
132
148
  * `fetchRowCacheEntries` are reused across those phases without re-reading the store; rows past
@@ -134,4 +150,4 @@ const readReserveBytes = fetchFloorBytes;
134
150
  * pack streaming starts.
135
151
  */
136
152
  const fetchRowCacheBytes = 524288;
137
- export { allottableOf, defaultMemory, fetchFloorBytes, fetchRowCacheBytes, headroomBytes, idleHeapBytes, openTreeBytes, openTreesFloorBytes, pushAdmissionOf, pushFloorsOf, pushPartBytes, pushReaderFloorsOf, pushRulesOf, readReserveBytes, readerFloorBytes, readerFloors, readerMost, receiveObjectsMostOf, unpackInflatedMost, uploadPartBytes };
153
+ export { allottableOf, defaultMemory, fetchFloorBytes, fetchRowCacheBytes, headroomBytes, idleHeapBytes, openTreeBytes, openTreesFloorBytes, pushAdmissionOf, pushFloorsOf, pushPartBytes, pushReaderFloorsOf, pushRulesOf, putHeldBytes, putMemoryLeast, readReserveBytes, readerFloorBytes, readerFloors, readerMost, receiveObjectsMostOf, stagedPuts, unpackInflatedMost, uploadPartBytes };
@@ -3,7 +3,7 @@ import { Allotment, GitObject, ObjectHeader, ObjectHeadersInput, ObjectHeldInput
3
3
  import { GitError } from "../contracts/result.mjs";
4
4
  import { Listed } from "../contracts/store.mjs";
5
5
  import "../store/call-count.mjs";
6
- import "@ref0/infra";
6
+ import { Multipart } from "@ref0/infra";
7
7
  import * as Effect from "effect/Effect";
8
8
  import "effect/Context";
9
9
  import "effect/Scope";
@@ -392,12 +392,14 @@ const deleteCharge = (batch, keys) => {
392
392
  const bucketDeleteMany = (bucket, keys) => bucketDo(bucket.removeMany(keys));
393
393
  /**
394
394
  * Why `multipart` can't count a put, or `undefined`: a part size above 0, a whole most, whole
395
- * calls, and at least one for a put sent whole, since one that sends anything makes a call.
395
+ * calls, and at least one for a put sent whole, since one that sends anything makes a call, and at
396
+ * least one part held, since a put in parts holds the one it fills.
396
397
  */
397
- const uncountable = ({ partSize, begin, end, wholeMost, wholeCalls }) => {
398
+ const uncountable = ({ partSize, begin, end, wholeMost, wholeCalls, buffersMost }) => {
398
399
  if (partSize !== Number.POSITIVE_INFINITY && !(Number.isSafeInteger(partSize) && partSize > 0)) return `A bucket's multipart.partSize is a whole number of bytes above 0, not ${partSize}`;
399
400
  if (wholeMost !== Number.POSITIVE_INFINITY && !(Number.isSafeInteger(wholeMost) && wholeMost >= 0)) return `A bucket's multipart.wholeMost is a whole number of bytes, not ${wholeMost}`;
400
401
  if (!(Number.isSafeInteger(wholeCalls) && wholeCalls >= 1)) return `A bucket's multipart.wholeCalls is a whole number of calls above 0, not ${wholeCalls}`;
402
+ if (!(Number.isSafeInteger(buffersMost) && buffersMost >= 1)) return `A bucket's multipart.buffersMost is a whole number of buffers above 0, not ${buffersMost}`;
401
403
  return [begin, end].every((calls) => Number.isSafeInteger(calls) && calls >= 0) ? void 0 : `A bucket's multipart.begin and end are whole numbers of calls, not ${begin} and ${end}`;
402
404
  };
403
405
  /** `multipart`'s refusal as a defect when it can't count a put: a bucket's, never a caller's. */
@@ -30,11 +30,21 @@ const hostFailures = (bucket) => ({
30
30
  abortPut: (key, token) => Effect.catchDefect(bucket.abortPut(key, token), hostFailure)
31
31
  });
32
32
  /** The host's links, each call's defect a failure, as `hostFailures` says. */
33
- const hostLinks = (links) => ({
34
- url: (key, options) => Effect.catchDefect(links.url(key, options), hostFailure),
35
- putUrl: (key, options) => Effect.catchDefect(links.putUrl(key, options), hostFailure),
36
- head: (key) => Effect.catchDefect(links.head(key), hostFailure)
37
- });
33
+ const hostLinks = (links) => {
34
+ const calls = {
35
+ url: (key, options) => Effect.catchDefect(links.url(key, options), hostFailure),
36
+ putUrl: (key, options) => Effect.catchDefect(links.putUrl(key, options), hostFailure),
37
+ head: (key) => Effect.catchDefect(links.head(key), hostFailure)
38
+ };
39
+ return links.puts === "checked" ? {
40
+ puts: "checked",
41
+ ...calls
42
+ } : {
43
+ puts: "unchecked",
44
+ ...calls,
45
+ copy: (from, to) => Effect.catchDefect(links.copy(from, to), hostFailure)
46
+ };
47
+ };
38
48
  /** The host's uploads, each call's defect a failure, as `hostFailures` says. */
39
49
  const hostUploads = (uploads) => ({
40
50
  maxParts: uploads.maxParts,
@@ -1,5 +1,6 @@
1
1
  import "../contracts/objects.mjs";
2
2
  import "../contracts/result.mjs";
3
+ import "./budget.mjs";
3
4
  import "./memory-budget.mjs";
4
5
  import "./pack-order.mjs";
5
6
  import "effect/Effect";
@@ -1,9 +1,9 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
- import { Sha1 } from "../protocol/bytes/sha1.mjs";
2
+ import { sha1Now, sha1NowHasher } from "../protocol/bytes/sha1-hasher.mjs";
3
3
  import { bucketDo, bucketReading, bucketTry, readWhole } from "./calls.mjs";
4
4
  import { bitmapOf, bitmapWords, ewahExtent, ewahOf, mostDirty, orEwah } from "./ewah.mjs";
5
5
  import "./link-join.mjs";
6
- import { uploadPartBytes } from "./budget.mjs";
6
+ import { putHeldBytes, uploadPartBytes } from "./put-holds.mjs";
7
7
  import { startPut } from "./merge.mjs";
8
8
  import { readExactly } from "./pack-ranges.mjs";
9
9
  import * as Effect from "effect/Effect";
@@ -303,9 +303,7 @@ const orderKey = (order) => {
303
303
  view.setUint32(at * 8, position);
304
304
  view.setUint32(at * 8 + 4, number);
305
305
  }
306
- const sha = new Sha1();
307
- sha.update(bytes);
308
- return [...sha.digest()].map((byte) => byte.toString(16).padStart(2, "0")).join("");
306
+ return [...sha1Now([bytes])].map((byte) => byte.toString(16).padStart(2, "0")).join("");
309
307
  };
310
308
  /** The most bytes one part of a whole build's bitmaps holds: one upload part. */
311
309
  const partBytesMost = uploadPartBytes;
@@ -619,7 +617,7 @@ const walkBytes = (positions) => {
619
617
  */
620
618
  const bitmapsPut = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, key, positions, count) {
621
619
  const put = yield* startPut(bucket, key, { atMost: bitmapsMostBytes(positions, count) });
622
- const sha = new Sha1();
620
+ const sha = sha1NowHasher();
623
621
  const entries = [];
624
622
  let offset = 0;
625
623
  const write = (bytes) => {
@@ -691,12 +689,14 @@ const bitmapsPut = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, key, pos
691
689
  });
692
690
  /**
693
691
  * What `writeBitmaps` grows its allotment by before walking: the walk's buffers (`walkBytes`),
694
- * the bitmaps it keeps in `made` (`kept`), the streaming put buffer when writing `.bitmaps`
695
- * directly (not a part), and the layer-below arrays when updating.
692
+ * the bitmaps it keeps in `made` (`kept`), the streaming put's parts when writing `.bitmaps`
693
+ * directly, on a bucket of `put`'s multipart, and none for a part, and
694
+ * the layer-below arrays when updating.
696
695
  */
697
696
  const bitmapsWalkBytes = (positions, kept, options) => {
698
697
  const words = bitmapWords(positions);
699
- return walkBytes(positions) + kept + (options?.part === true ? 0 : Math.min(bitmapsMostBytes(positions, options?.count ?? 0), uploadPartBytes)) + (options?.below === true ? words * 12 : 0);
698
+ const put = options?.put;
699
+ return walkBytes(positions) + kept + (put === void 0 ? 0 : putHeldBytes(put, { atMost: bitmapsMostBytes(positions, options?.count ?? 0) })) + (options?.below === true ? words * 12 : 0);
700
700
  };
701
701
  /**
702
702
  * A bitmap for each of `input.chosen`, oldest first, each the set of positions its object
@@ -713,7 +713,7 @@ const writeBitmaps = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
713
713
  const order = bitmapOrder(input.chosen);
714
714
  const count = order.length;
715
715
  const held = input.walkReserved === true ? 0 : bitmapsWalkBytes(positions, input.kept, {
716
- part: part !== void 0,
716
+ ...part === void 0 && { put: input.bucket.multipart },
717
717
  below: below !== void 0,
718
718
  count
719
719
  });
@@ -835,12 +835,13 @@ const copyRunBytes = 1048576;
835
835
  /**
836
836
  * What `copyBitmaps` holds to copy `count` bitmaps over `positions` from files of `from`'s
837
837
  * positions: what `eachBitmap` holds of one file, the merged words and their EWAH, the piece it
838
- * writes through and the put's part. Its lists of the bitmaps are its caller's to charge.
838
+ * writes through and what its put holds on a bucket of `multipart`. Its lists of the bitmaps are
839
+ * its caller's to charge.
839
840
  */
840
- const copyHeldBytes = (positions, count, from) => {
841
+ const copyHeldBytes = (positions, count, from, multipart) => {
841
842
  const words = bitmapWords(positions);
842
843
  const reading = Math.max(0, ...from.map((each) => eachBitmapBytes(each, copyRunBytes)));
843
- const part = Math.min(bitmapsMostBytes(positions, count), uploadPartBytes);
844
+ const part = putHeldBytes(multipart, { atMost: bitmapsMostBytes(positions, count) });
844
845
  return reading + words * 4 + ewahMostWords(words) * 4 + pieceBytes + part;
845
846
  };
846
847
  /**
@@ -860,7 +861,7 @@ const copyBitmaps = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
860
861
  of.push(each);
861
862
  byFile.set(each.from, of);
862
863
  }
863
- const held = copyHeldBytes(positions, copied.length, [...byFile.keys()].map((from) => from.positions));
864
+ const held = copyHeldBytes(positions, copied.length, [...byFile.keys()].map((from) => from.positions), input.bucket.multipart);
864
865
  yield* input.allotment.grow(held);
865
866
  const put = yield* bitmapsPut(input.bucket, input.key, positions, copied.length);
866
867
  const all = new Uint32Array(words);
@@ -6,12 +6,13 @@ import "../contracts/store.mjs";
6
6
  import "../protocol/objects/commit.mjs";
7
7
  import "../store/call-count.mjs";
8
8
  import "./fetch.mjs";
9
+ import "./budget.mjs";
9
10
  import "./index-graph.mjs";
10
11
  import "./index-layers.mjs";
11
12
  import "./layout.mjs";
12
13
  import "./memory-budget.mjs";
13
14
  import "./pack-order.mjs";
14
- import { Moment, Row } from "@ref0/infra";
15
+ import { Moment, Multipart, Row } from "@ref0/infra";
15
16
  import "effect/Schema";
16
17
  import "effect/Effect";
17
18
  import "effect/Option";
@@ -1,16 +1,16 @@
1
1
  import { spentIn } from "../contracts/calls-spent.mjs";
2
2
  import { gitError } from "../contracts/result.mjs";
3
3
  import { hexOf } from "../protocol/bytes/hex.mjs";
4
- import { Sha1 } from "../protocol/bytes/sha1.mjs";
4
+ import { sha1Now } from "../protocol/bytes/sha1-hasher.mjs";
5
5
  import { writeCommitGraph } from "../protocol/packs/graph.mjs";
6
6
  import { IndexerCache } from "../protocol/packs/indexer.mjs";
7
7
  import { indexHeadBytes, oidBytes, tablesOf } from "../protocol/packs/idx.mjs";
8
- import { allottableOf } from "../protocol/bytes/buffers.mjs";
9
8
  import { noRepoRoots } from "../protocol/objects/commit.mjs";
10
9
  import { rawLinks } from "../protocol/objects/links-raw.mjs";
11
10
  import { rootsDigest } from "../store/repo-record.mjs";
12
11
  import { randomText } from "../store/random.mjs";
13
- import { uploadPartBytes } from "./budget.mjs";
12
+ import { allottableOf } from "../protocol/bytes/buffers.mjs";
13
+ import { putHeldBytes, uploadPartBytes } from "./put-holds.mjs";
14
14
  import { bucketDeleteMany, bucketDo, bucketPut, joined, readEach, readWhole, sizedPutCalls, streamedPutCalls } from "./calls.mjs";
15
15
  import { BitmapsPart, EdgeFiles, PriorParts, bitmapOrder, bitmapsMostBytes, bitmapsPut, bitmapsWalkBytes, copyBitmaps, copyHeldBytes, copyRunBytes, edgesBytesOf, edgesFileOf, ewahMostWords, noNumber, orderKey, partBitmaps, partBytesMost, priorFootersMost, priorPartsRoom, runsMost, storedBitmaps, storedSize, writeBitmaps } from "./index-bitmaps.mjs";
16
16
  import { BasesWriter, TypesWriter, indexBasesBytes, indexTypesBytes, openBases, openTypes, typeCodes } from "./index-files.mjs";
@@ -670,12 +670,11 @@ const readRegion = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, e
670
670
  return true;
671
671
  }), void 0, regionPageRows);
672
672
  if (whole !== "done") return whole;
673
- const sha = new Sha1();
674
- sha.update(ids.subarray(0, rows * 20));
673
+ const kept = ids.subarray(0, rows * 20);
675
674
  return {
676
- ids: ids.subarray(0, rows * 20),
675
+ ids: kept,
677
676
  rows,
678
- digest: hexOf(sha.digest())
677
+ digest: hexOf(sha1Now([kept]))
679
678
  };
680
679
  });
681
680
  /**
@@ -1494,7 +1493,7 @@ const bitmapsCutTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, files,
1494
1493
  };
1495
1494
  }
1496
1495
  const into = new BitmapsPart(partBytesMost);
1497
- const walkHeld = bitmapsWalkBytes(input.positions, input.kept, { part: true });
1496
+ const walkHeld = bitmapsWalkBytes(input.positions, input.kept);
1498
1497
  yield* allotment.grow(walkHeld);
1499
1498
  let priorCharged = 0;
1500
1499
  const made = yield* Effect.ensuring(Effect.gen(function* () {
@@ -1533,7 +1532,7 @@ const bitmapsCutTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, files,
1533
1532
  const { counted } = parts;
1534
1533
  const madeCalls = counted?.made();
1535
1534
  const callsFit = counted === void 0 || madeCalls === void 0 || directNeeds <= counted.most.bucket - madeCalls.bucket && directNeeds <= counted.most.subrequests - madeCalls.subrequests;
1536
- const putBuffer = Math.min(atMost, uploadPartBytes);
1535
+ const putBuffer = putHeldBytes(parts.bucket.multipart, { atMost });
1537
1536
  if (callsFit && (putBuffer === 0 || allotment.tryGrow(putBuffer))) return yield* Effect.ensuring(Effect.gen(function* () {
1538
1537
  const already = yield* storedSize(parts.bucket, files.bitmaps);
1539
1538
  const written = already === void 0 ? yield* Effect.scoped(Effect.gen(function* () {
@@ -1603,7 +1602,7 @@ const bitmapsJoined = /* @__PURE__ */ Effect.fnUntraced(function* (parts, files,
1603
1602
  if (counted !== void 0 && needs > counted.most.bucket - counted.made().bucket) return yield* Effect.fail(bitmapsUnjoined(needs, counted.most.bucket));
1604
1603
  const already = yield* storedSize(bucket, files.bitmaps);
1605
1604
  const written = already === void 0 ? yield* Effect.scoped(Effect.gen(function* () {
1606
- yield* allotment.grow(partBytesMost + Math.min(atMost, uploadPartBytes));
1605
+ yield* allotment.grow(partBytesMost + putHeldBytes(bucket.multipart, { atMost }));
1607
1606
  const put = yield* bitmapsPut(bucket, files.bitmaps, positions, cut.done);
1608
1607
  for (const [number, held] of cut.parts.entries()) {
1609
1608
  const key = files.bitmapsPart(cut.order, number);
@@ -1745,7 +1744,7 @@ const liveHeldBytes = (words, tips, rows) => words * 4 + orIntoBytes(words) + ti
1745
1744
  * the layout's rows; the copy's; or `.types` and `.bases`' chunks. Each phase's go before the
1746
1745
  * next's, and the bitmaps' entries stay through the union and the copy, `mergeEntryBytes` each.
1747
1746
  */
1748
- const mergeHeldMost = (merging) => {
1747
+ const mergeHeldMost = (merging, multipart) => {
1749
1748
  const { layers, tips } = merging;
1750
1749
  const positions = firstOf(layers);
1751
1750
  const words = bitmapWords(positions);
@@ -1757,7 +1756,7 @@ const mergeHeldMost = (merging) => {
1757
1756
  rows * 40,
1758
1757
  commits * 4 + mergeHeldBytes(layers.length),
1759
1758
  liveHeldBytes(words, tips, rows),
1760
- copyHeldBytes(positions, bitmaps, files),
1759
+ copyHeldBytes(positions, bitmaps, files, multipart),
1761
1760
  mergeFilesBytes
1762
1761
  ];
1763
1762
  return Math.max(...phases) + bitmaps * 640;
@@ -1788,10 +1787,9 @@ const mergedRegion = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, repo,
1788
1787
  region.set(ids, at);
1789
1788
  at += ids.byteLength;
1790
1789
  }
1791
- const sha = new Sha1();
1792
- sha.update(region);
1790
+ const digest = hexOf(sha1Now([region]));
1793
1791
  if (region.byteLength > 0) yield* putOnce(bucket, key, region);
1794
- return hexOf(sha.digest());
1792
+ return digest;
1795
1793
  });
1796
1794
  /**
1797
1795
  * The stored bitmaps a merge keeps: those a current tip's stored bitmap reaches, ORed through
@@ -1890,7 +1888,7 @@ const mergeStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, da
1890
1888
  };
1891
1889
  const past = callsPast(parts, mergeCallsAfterOpen(merging, bucket.multipart));
1892
1890
  if (past !== void 0) return yield* Effect.fail(past);
1893
- const held = mergeHeldMost(merging);
1891
+ const held = mergeHeldMost(merging, bucket.multipart);
1894
1892
  const most = parts.budget.mostOf(true);
1895
1893
  const tooLarge = mergePast(held, "bytes", most, "Raise `PacksOptions.memory`.");
1896
1894
  yield* allotment.grow(held, tooLarge);
@@ -1,5 +1,5 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
- import { Sha1 } from "../protocol/bytes/sha1.mjs";
2
+ import { sha1NowHasher } from "../protocol/bytes/sha1-hasher.mjs";
3
3
  import { readExactly } from "./pack-ranges.mjs";
4
4
  import * as Effect from "effect/Effect";
5
5
  // src/storage/index-files.ts
@@ -70,7 +70,7 @@ const broken = (message) => Effect.die(new Error(message));
70
70
  */
71
71
  var TypesWriter = class {
72
72
  positions;
73
- #sha = new Sha1();
73
+ #sha = sha1NowHasher();
74
74
  #carry = 0;
75
75
  #written = 0;
76
76
  constructor(positions) {
@@ -121,7 +121,7 @@ var TypesWriter = class {
121
121
  var BasesWriter = class {
122
122
  positions;
123
123
  deltas;
124
- #sha = new Sha1();
124
+ #sha = sha1NowHasher();
125
125
  #blocks;
126
126
  #block = 0;
127
127
  #rows = 0;
@@ -3,7 +3,7 @@ import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
3
3
  import { hexOf } from "../protocol/bytes/hex.mjs";
4
4
  import { noRepoRoots } from "../protocol/objects/commit.mjs";
5
5
  import { mostParents } from "../protocol/objects/object-rules.mjs";
6
- import { Sha1 } from "../protocol/bytes/sha1.mjs";
6
+ import { sha1NowHasher } from "../protocol/bytes/sha1-hasher.mjs";
7
7
  import { graphMagic } from "../protocol/packs/graph.mjs";
8
8
  import { PackTransportError, boundedSource, packReadBytes } from "../protocol/packs/reader.mjs";
9
9
  import { bucketStream } from "./calls.mjs";
@@ -84,7 +84,7 @@ const asIs = (value) => value;
84
84
  const indexGraphBytes = (commits, octopus) => 1040 + commits * 32 + octopus * 4 + 20;
85
85
  /** A file's bytes from one streamed read, taken a few at a time, hashed as they're taken. */
86
86
  const taker = (read) => {
87
- const sha = new Sha1();
87
+ const sha = sha1NowHasher();
88
88
  let piece = /* @__PURE__ */ new Uint8Array(0);
89
89
  let at = 0;
90
90
  return {
@@ -293,7 +293,7 @@ const firstSlot = (commit) => commit * 2;
293
293
  const octopusTarget = (entry) => (octopusFlag | entry) >>> 0;
294
294
  /** Bytes gathered into writes of `writeBytes`, each hashed. */
295
295
  const gathered = (write) => {
296
- const sha = new Sha1();
296
+ const sha = sha1NowHasher();
297
297
  let buffer = new Uint8Array(writeBytes);
298
298
  let filled = 0;
299
299
  const flush = Effect.suspend(() => {