@ref0/git 0.14.0 → 0.20.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 (351) hide show
  1. package/dist/auth/access-jwt.mjs +2 -2
  2. package/dist/auth/authorize.mjs +3 -3
  3. package/dist/auth/fences.d.mts +1 -2
  4. package/dist/auth/fences.mjs +3 -3
  5. package/dist/auth/grants.mjs +4 -4
  6. package/dist/auth/host-function.mjs +18 -1
  7. package/dist/auth/identify.d.mts +1 -1
  8. package/dist/auth/identify.mjs +3 -3
  9. package/dist/auth/token-cleanup.mjs +67 -0
  10. package/dist/auth/token-rows.mjs +1 -1
  11. package/dist/auth/token-text.mjs +9 -1
  12. package/dist/auth/tokens-base.d.mts +35 -0
  13. package/dist/auth/tokens-base.mjs +13 -0
  14. package/dist/auth/tokens-layer.d.mts +2 -27
  15. package/dist/auth/tokens-layer.mjs +6 -11
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens.d.mts +7 -10
  18. package/dist/auth/tokens.mjs +9 -80
  19. package/dist/client/answer.mjs +21 -42
  20. package/dist/client/client.d.mts +2 -4
  21. package/dist/client/git-http.mjs +17 -7
  22. package/dist/client/local.mjs +14 -13
  23. package/dist/client/push-upload.mjs +9 -8
  24. package/dist/client/remote.mjs +8 -10
  25. package/dist/client/run-remote-helper.d.mts +1 -0
  26. package/dist/client/run-remote-helper.mjs +58 -24
  27. package/dist/client/slice-push.d.mts +1 -1
  28. package/dist/client/transport.mjs +105 -46
  29. package/dist/contracts/blobs.d.mts +55 -8
  30. package/dist/contracts/blobs.mjs +16 -2
  31. package/dist/contracts/call-allowance.d.mts +13 -0
  32. package/dist/contracts/call-allowance.mjs +44 -0
  33. package/dist/contracts/calls-spent.mjs +8 -3
  34. package/dist/contracts/client.d.mts +15 -16
  35. package/dist/contracts/commits.d.mts +24 -24
  36. package/dist/contracts/engine.d.mts +6 -1
  37. package/dist/contracts/engine.mjs +10 -1
  38. package/dist/contracts/files.d.mts +10 -10
  39. package/dist/contracts/forks.d.mts +17 -17
  40. package/dist/contracts/git-events.d.mts +29 -1
  41. package/dist/contracts/git-hooks.d.mts +1 -1
  42. package/dist/contracts/git.d.mts +21 -0
  43. package/dist/contracts/grants.d.mts +24 -4
  44. package/dist/contracts/handlers.d.mts +1 -1
  45. package/dist/contracts/lfs.d.mts +28 -2
  46. package/dist/contracts/merges.d.mts +3 -2
  47. package/dist/contracts/objects.d.mts +23 -25
  48. package/dist/contracts/queue.d.mts +40 -12
  49. package/dist/contracts/queue.mjs +3 -4
  50. package/dist/contracts/refs.d.mts +26 -23
  51. package/dist/contracts/remote.d.mts +6 -7
  52. package/dist/contracts/remote.mjs +4 -1
  53. package/dist/contracts/repos.d.mts +29 -138
  54. package/dist/contracts/repos.mjs +5 -3
  55. package/dist/contracts/result.d.mts +35 -16
  56. package/dist/contracts/result.mjs +35 -7
  57. package/dist/contracts/server.d.mts +25 -50
  58. package/dist/contracts/services.d.mts +1 -1
  59. package/dist/contracts/store.d.mts +6 -5
  60. package/dist/contracts/sync.d.mts +11 -7
  61. package/dist/contracts/sync.mjs +12 -2
  62. package/dist/contracts/tags.d.mts +10 -10
  63. package/dist/contracts/time.d.mts +3 -0
  64. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  65. package/dist/contracts/tokens.d.mts +15 -17
  66. package/dist/contracts/tokens.mjs +3 -2
  67. package/dist/contracts/topics.d.mts +1 -1
  68. package/dist/contracts/trees.d.mts +12 -12
  69. package/dist/contracts/work.d.mts +24 -13
  70. package/dist/core/access.d.mts +1 -2
  71. package/dist/core/access.mjs +20 -9
  72. package/dist/core/ancestry.d.mts +1 -0
  73. package/dist/core/asked.mjs +1 -1
  74. package/dist/core/call-names.mjs +6 -1
  75. package/dist/core/call-services.mjs +11 -3
  76. package/dist/core/events/deliver.d.mts +1 -2
  77. package/dist/core/events/deliver.mjs +43 -36
  78. package/dist/core/events/retired.mjs +119 -0
  79. package/dist/core/forks.mjs +928 -432
  80. package/dist/core/hooks/groups.mjs +1 -1
  81. package/dist/core/imports.mjs +29 -23
  82. package/dist/core/index-job.mjs +122 -34
  83. package/dist/core/index-lost.d.mts +1 -2
  84. package/dist/core/index-lost.mjs +2 -2
  85. package/dist/core/loose-tally.mjs +1 -1
  86. package/dist/core/objects/blobs.mjs +129 -3
  87. package/dist/core/objects/lines.mjs +2 -2
  88. package/dist/core/objects/merges.mjs +4 -1
  89. package/dist/core/objects/objects-layer.d.mts +1 -1
  90. package/dist/core/objects/objects-layer.mjs +3 -3
  91. package/dist/core/objects/reading.mjs +24 -13
  92. package/dist/core/objects/tags.mjs +4 -1
  93. package/dist/core/objects/trees.mjs +2 -2
  94. package/dist/core/objects/writing.mjs +2 -2
  95. package/dist/core/own-writes.mjs +1 -1
  96. package/dist/core/parts.d.mts +4 -5
  97. package/dist/core/parts.mjs +3 -8
  98. package/dist/core/promise.mjs +9 -12
  99. package/dist/core/purge.mjs +287 -83
  100. package/dist/core/push-decide.mjs +2 -0
  101. package/dist/core/push-files.d.mts +1 -1
  102. package/dist/core/push.mjs +58 -47
  103. package/dist/core/receipts.mjs +8 -3
  104. package/dist/core/ref-index-job.mjs +4 -4
  105. package/dist/core/ref-view.mjs +2 -2
  106. package/dist/core/refs.mjs +5 -5
  107. package/dist/core/registered-rows.mjs +2 -2
  108. package/dist/core/repack.mjs +36 -21
  109. package/dist/core/repo-info.mjs +3 -3
  110. package/dist/core/repos.mjs +21 -9
  111. package/dist/core/rules/commit-changes.d.mts +0 -1
  112. package/dist/core/saved-caller-views.d.mts +7 -2
  113. package/dist/core/saved-caller-views.mjs +2 -2
  114. package/dist/core/saved-callers.d.mts +19 -2
  115. package/dist/core/seam.d.mts +16 -26
  116. package/dist/core/seam.mjs +7 -28
  117. package/dist/core/tokens.mjs +1 -1
  118. package/dist/core/view.mjs +7 -15
  119. package/dist/core/work.mjs +59 -14
  120. package/dist/effect.d.mts +3 -12
  121. package/dist/effect.mjs +1 -10
  122. package/dist/engine/failures.mjs +2 -1
  123. package/dist/engine/reads.mjs +4 -4
  124. package/dist/event-streams/stream.d.mts +2 -2
  125. package/dist/event-streams/stream.mjs +37 -14
  126. package/dist/extend.d.mts +2 -3
  127. package/dist/extend.mjs +2 -1
  128. package/dist/http/answers.mjs +8 -5
  129. package/dist/http/core-parts.mjs +95 -79
  130. package/dist/http/handler.mjs +34 -7
  131. package/dist/http/node.d.mts +14 -1
  132. package/dist/http/node.mjs +56 -27
  133. package/dist/http/parts.d.mts +1 -0
  134. package/dist/http/push-upload-job.mjs +30 -26
  135. package/dist/http/push-uploads.mjs +36 -21
  136. package/dist/http/upload-pack.mjs +3 -3
  137. package/dist/index.d.mts +14 -14
  138. package/dist/index.mjs +2 -2
  139. package/dist/lfs/answer.mjs +37 -0
  140. package/dist/lfs/base.d.mts +2 -0
  141. package/dist/lfs/base.mjs +25 -1
  142. package/dist/lfs/copy.d.mts +21 -7
  143. package/dist/lfs/copy.mjs +89 -6
  144. package/dist/lfs/layer.d.mts +15 -1
  145. package/dist/lfs/layer.mjs +24 -11
  146. package/dist/lfs/locks.mjs +2 -2
  147. package/dist/lfs/objects.d.mts +1 -0
  148. package/dist/lfs/objects.mjs +87 -17
  149. package/dist/lfs/pointers.mjs +2 -2
  150. package/dist/lfs/rows.mjs +42 -8
  151. package/dist/lfs/upkeep.mjs +48 -14
  152. package/dist/lfs/wire.mjs +6 -31
  153. package/dist/merges/merges.mjs +2 -2
  154. package/dist/node.d.mts +2 -2
  155. package/dist/protocol/bytes/buffers.mjs +13 -5
  156. package/dist/protocol/bytes/reader.mjs +6 -1
  157. package/dist/protocol/bytes/streams.mjs +27 -1
  158. package/dist/protocol/diff/read.d.mts +4 -3
  159. package/dist/protocol/diff/read.mjs +8 -3
  160. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  161. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  162. package/dist/protocol/objects/links-raw.mjs +24 -10
  163. package/dist/protocol/objects/tag.d.mts +1 -1
  164. package/dist/protocol/objects/tree.mjs +23 -6
  165. package/dist/protocol/packs/delta.d.mts +6 -3
  166. package/dist/protocol/packs/delta.mjs +96 -32
  167. package/dist/protocol/packs/idx.d.mts +2 -1
  168. package/dist/protocol/packs/idx.mjs +22 -3
  169. package/dist/protocol/packs/parts.d.mts +4 -1
  170. package/dist/protocol/packs/parts.mjs +10 -7
  171. package/dist/protocol/packs/reader.d.mts +5 -0
  172. package/dist/protocol/packs/reader.mjs +3 -2
  173. package/dist/protocol/packs/writer.mjs +26 -8
  174. package/dist/queue/advance.mjs +21 -24
  175. package/dist/queue/base.d.mts +55 -0
  176. package/dist/queue/base.mjs +44 -0
  177. package/dist/queue/calls.mjs +51 -54
  178. package/dist/queue/commit.mjs +1 -1
  179. package/dist/queue/host.d.mts +1 -15
  180. package/dist/queue/host.mjs +2 -7
  181. package/dist/queue/layer.d.mts +2 -1
  182. package/dist/queue/layer.mjs +10 -3
  183. package/dist/queue/limits.mjs +2 -0
  184. package/dist/queue/push-option.mjs +9 -24
  185. package/dist/queue/schedule.mjs +1 -1
  186. package/dist/queue/state.mjs +2 -10
  187. package/dist/queue/trim.mjs +5 -3
  188. package/dist/rest/blobs.mjs +29 -5
  189. package/dist/rest/caller.d.mts +4 -4271
  190. package/dist/rest/caller.mjs +4 -0
  191. package/dist/rest/client.d.mts +8 -5
  192. package/dist/rest/client.mjs +19 -2
  193. package/dist/rest/handlers.mjs +50 -5
  194. package/dist/rest/layer.d.mts +2 -2
  195. package/dist/rest/layer.mjs +5 -12
  196. package/dist/rest/me.d.mts +3 -432
  197. package/dist/server/check-fetch.mjs +3 -3
  198. package/dist/server/edge-node.d.mts +11 -8
  199. package/dist/server/edge-node.mjs +9 -6
  200. package/dist/server/edge.d.mts +21 -7
  201. package/dist/server/edge.mjs +32 -11
  202. package/dist/server/extension.mjs +1 -1
  203. package/dist/server/git-layer.d.mts +5 -5
  204. package/dist/server/git-layer.mjs +28 -22
  205. package/dist/server/git-namespace.d.mts +4 -3
  206. package/dist/server/git-namespace.mjs +3 -2
  207. package/dist/server/joined.d.mts +6 -18
  208. package/dist/server/joined.mjs +9 -36
  209. package/dist/server/lifecycle.mjs +18 -106
  210. package/dist/server/registry.mjs +24 -7
  211. package/dist/server/server.mjs +205 -346
  212. package/dist/signin/context.d.mts +1 -2
  213. package/dist/signin/layer.d.mts +1 -1
  214. package/dist/signin/layer.mjs +1 -1
  215. package/dist/storage/allotted.mjs +18 -3
  216. package/dist/storage/batch-upkeep.mjs +274 -0
  217. package/dist/storage/batches.d.mts +8 -0
  218. package/dist/storage/batches.mjs +344 -0
  219. package/dist/storage/calls.d.mts +1 -2
  220. package/dist/storage/calls.mjs +144 -158
  221. package/dist/storage/chunks.d.mts +9 -0
  222. package/dist/storage/chunks.mjs +297 -0
  223. package/dist/storage/clean-up.mjs +72 -9
  224. package/dist/storage/counted-bucket.mjs +4 -4
  225. package/dist/storage/fetch.d.mts +1 -0
  226. package/dist/storage/fetch.mjs +287 -210
  227. package/dist/storage/host-bucket.mjs +1 -2
  228. package/dist/storage/id-mix.mjs +19 -5
  229. package/dist/storage/index-bitmaps.mjs +9 -2
  230. package/dist/storage/index-build.d.mts +0 -1
  231. package/dist/storage/index-build.mjs +80 -23
  232. package/dist/storage/index-fetch.mjs +113 -72
  233. package/dist/storage/index-files.d.mts +3 -0
  234. package/dist/storage/index-files.mjs +10 -5
  235. package/dist/storage/index-graph.mjs +72 -22
  236. package/dist/storage/index-remap.mjs +200 -64
  237. package/dist/storage/index-whole.mjs +127 -0
  238. package/dist/storage/largest-files.mjs +1 -1
  239. package/dist/storage/layout.mjs +23 -0
  240. package/dist/storage/loose.d.mts +7 -4
  241. package/dist/storage/loose.mjs +212 -67
  242. package/dist/storage/memory-budget.mjs +16 -4
  243. package/dist/storage/merge-plan.mjs +3 -2
  244. package/dist/storage/merge-row.mjs +7 -1
  245. package/dist/storage/merge-stream.mjs +164 -25
  246. package/dist/storage/merge-walk.mjs +8 -4
  247. package/dist/storage/merge-write.mjs +1 -1
  248. package/dist/storage/merge.d.mts +1 -1
  249. package/dist/storage/merge.mjs +1 -1
  250. package/dist/storage/object-rows.d.mts +1 -0
  251. package/dist/storage/object-rows.mjs +385 -65
  252. package/dist/storage/oid-table.mjs +171 -0
  253. package/dist/storage/pack-order.mjs +8 -4
  254. package/dist/storage/pack-ranges.d.mts +1 -2
  255. package/dist/storage/pack-ranges.mjs +4 -5
  256. package/dist/storage/pack-reads.d.mts +2 -1
  257. package/dist/storage/pack-reads.mjs +158 -42
  258. package/dist/storage/pack-receive.d.mts +1 -1
  259. package/dist/storage/pack-receive.mjs +2 -2
  260. package/dist/storage/packs.d.mts +1 -1
  261. package/dist/storage/packs.mjs +136 -66
  262. package/dist/storage/placed-reads.mjs +1 -1
  263. package/dist/storage/plan-columns.d.mts +4 -0
  264. package/dist/storage/plan-columns.mjs +238 -0
  265. package/dist/storage/prune-keep.mjs +134 -41
  266. package/dist/storage/prune-walk.mjs +202 -62
  267. package/dist/storage/prune.mjs +194 -91
  268. package/dist/storage/push-allotment.mjs +91 -12
  269. package/dist/storage/push-uploads.mjs +4 -4
  270. package/dist/storage/pushed-commits.mjs +4 -2
  271. package/dist/storage/quarantine.d.mts +1 -1
  272. package/dist/storage/range-cache.mjs +125 -8
  273. package/dist/storage/ready.d.mts +1 -1
  274. package/dist/storage/ready.mjs +8 -6
  275. package/dist/storage/receive-bounds.mjs +23 -8
  276. package/dist/storage/repack-backlog.mjs +6 -3
  277. package/dist/storage/repack.d.mts +1 -1
  278. package/dist/storage/rows.d.mts +1 -1
  279. package/dist/storage/rows.mjs +1 -1
  280. package/dist/storage/runs.mjs +195 -43
  281. package/dist/storage/send-list.d.mts +1 -0
  282. package/dist/storage/send-list.mjs +54 -10
  283. package/dist/storage/single-flight.mjs +13 -7
  284. package/dist/storage/stream-whole.mjs +127 -26
  285. package/dist/storage/unpack.mjs +371 -79
  286. package/dist/storage/visible.mjs +2 -2
  287. package/dist/storage/walk.mjs +192 -38
  288. package/dist/storage/wants.mjs +5 -5
  289. package/dist/store/bodies.mjs +38 -0
  290. package/dist/store/call-count.d.mts +8 -12
  291. package/dist/store/call-count.mjs +34 -46
  292. package/dist/store/catalogue.d.mts +2 -2
  293. package/dist/store/catalogue.mjs +145 -35
  294. package/dist/store/crossing.mjs +1 -3
  295. package/dist/store/cursor-seal.d.mts +1 -2
  296. package/dist/store/cursor-seal.mjs +16 -6
  297. package/dist/store/door.mjs +183 -0
  298. package/dist/store/errors.d.mts +3 -4
  299. package/dist/store/errors.mjs +15 -33
  300. package/dist/store/git-store.mjs +25 -7
  301. package/dist/store/job-try.mjs +9 -32
  302. package/dist/store/list-job.mjs +44 -8
  303. package/dist/store/records.d.mts +3 -0
  304. package/dist/store/records.mjs +3 -0
  305. package/dist/store/repo-record.d.mts +1 -2
  306. package/dist/store/repo-record.mjs +32 -20
  307. package/dist/store/reservations.mjs +1 -1
  308. package/dist/store/scopes.mjs +11 -0
  309. package/dist/store/settle.mjs +4 -4
  310. package/dist/sync/github.mjs +3 -3
  311. package/dist/sync/import.mjs +31 -18
  312. package/dist/sync/lfs-batch.mjs +4 -5
  313. package/dist/sync/lfs-copy.mjs +17 -6
  314. package/dist/sync/mirror.mjs +34 -31
  315. package/dist/sync/said.mjs +16 -37
  316. package/dist/sync/step.mjs +33 -25
  317. package/dist/sync/tries.mjs +9 -9
  318. package/dist/topics/advance.mjs +10 -11
  319. package/dist/topics/base.d.mts +15 -0
  320. package/dist/topics/base.mjs +8 -0
  321. package/dist/topics/host.mjs +1 -1
  322. package/dist/topics/layer.d.mts +4 -9
  323. package/dist/topics/layer.mjs +2 -3
  324. package/dist/topics/members.mjs +4 -4
  325. package/dist/topics/public.d.mts +2 -1
  326. package/dist/topics/topic.mjs +2 -2
  327. package/package.json +5 -4
  328. package/dist/contracts/promises.d.mts +0 -39
  329. package/dist/core/call-names.d.mts +0 -3
  330. package/dist/core/clock.mjs +0 -18
  331. package/dist/lfs/calls.mjs +0 -26
  332. package/dist/rest/api.d.mts +0 -23
  333. package/dist/rest/blobs.d.mts +0 -833
  334. package/dist/rest/commits.d.mts +0 -3543
  335. package/dist/rest/errors.d.mts +0 -2124
  336. package/dist/rest/events.d.mts +0 -426
  337. package/dist/rest/files.d.mts +0 -1342
  338. package/dist/rest/forks.d.mts +0 -2160
  339. package/dist/rest/handlers.d.mts +0 -8
  340. package/dist/rest/merges.d.mts +0 -477
  341. package/dist/rest/queue.d.mts +0 -5917
  342. package/dist/rest/refs.d.mts +0 -2988
  343. package/dist/rest/repos.d.mts +0 -2567
  344. package/dist/rest/tags.d.mts +0 -1316
  345. package/dist/rest/tokens.d.mts +0 -2614
  346. package/dist/rest/topics.d.mts +0 -2224
  347. package/dist/rest/trees.d.mts +0 -1709
  348. package/dist/rest/work.d.mts +0 -1695
  349. package/dist/server/lifecycle.d.mts +0 -2
  350. package/dist/store/promises.d.mts +0 -11
  351. package/dist/store/promises.mjs +0 -327
@@ -1,29 +1,51 @@
1
+ import { streamThen } from "../protocol/bytes/streams.mjs";
1
2
  import { handingOn } from "../protocol/packs/writer.mjs";
2
3
  import { newChangeId } from "../store/scopes.mjs";
3
4
  import { callScope } from "../store/call-count.mjs";
4
- import { answering, cancelsBody, objectReader } from "./calls.mjs";
5
+ import { cancelsBody, objectReader } from "./calls.mjs";
5
6
  import { fetchPack } from "./fetch.mjs";
6
7
  import { pushedCommitsPage } from "./pushed-commits.mjs";
7
- import { copyRowsPage, eachHeldRow, gitObjectOf, heldRows, rowHeaders, rowSizes, rowsStartingWith, startingOf } from "./object-rows.mjs";
8
+ import { copyRowsPage, eachHeldRow, gitObjectOf, heldRows, readsOwnChunks, rowHeaders, rowSizes, rowsStartingWith, startingOf } from "./object-rows.mjs";
8
9
  import { allotmentWithin } from "../contracts/object-values.mjs";
9
10
  import { allottedRows } from "./allotted.mjs";
11
+ import { looseUpkeep } from "./batch-upkeep.mjs";
12
+ import { abandonBatch, openBatch, rowsChange } from "./batches.mjs";
13
+ import { allottableOf, defaultMemory, readReserveBytes } from "./budget.mjs";
14
+ import { ChunkReader, chunkRawBytes, chunkedReadBytes, chunkedRow, fitsRow, stageChunk } from "./chunks.mjs";
15
+ import { MemoryBudget } from "./memory-budget.mjs";
10
16
  import { pointersOfObjects } from "./lfs-pointers.mjs";
11
17
  import { largestOf } from "./largest-files.mjs";
12
18
  import { wholeRoots } from "./roots.mjs";
13
19
  import { commitBytes, unpackObjects } from "./unpack.mjs";
14
20
  import { gitError } from "../contracts/result.mjs";
21
+ import * as Clock from "effect/Clock";
15
22
  import * as Effect from "effect/Effect";
23
+ import * as Exit from "effect/Exit";
24
+ import * as Scope from "effect/Scope";
16
25
  // src/storage/loose.ts
17
26
  /** The most objects one push may carry into `loose()` storage, each a row of its commit. */
18
27
  const looseObjectsMost = 1e4;
28
+ /** The bytes one object takes in `loose()` storage at most, as Cloudflare Artifacts takes a file. */
29
+ const looseFileBytesMost = 33554432;
19
30
  /**
20
- * What one push may carry into `loose()` storage: its `objects`, and the `bytes` of its rows as
21
- * JSON, which its commit holds.
31
+ * What one push may carry into `loose()` storage: its `objects`, the `bytes` of its rows as JSON,
32
+ * which its commit holds, and the bytes of each object, `fileBytes`, one past a row kept as chunks.
22
33
  */
23
34
  const looseLimits = {
24
35
  objects: looseObjectsMost,
25
- bytes: commitBytes
36
+ bytes: commitBytes,
37
+ fileBytes: looseFileBytesMost
26
38
  };
39
+ /**
40
+ * The bytes a push's objects past one row take in all, a delta's results among them: eight of the
41
+ * largest. Without it, a pack of small deltas, each making a large object, could make gigabytes.
42
+ */
43
+ const largeBytesMost = 8 * looseFileBytesMost;
44
+ /**
45
+ * What a receive holds before any object past a row: its entries, their objects read whole and
46
+ * their rows, each within `bytes`, its reader's buffers, and a chunk filling, waiting and encoded.
47
+ */
48
+ const receiveFloorOf = (bytes) => 3 * bytes + 1048576 + 3 * chunkRawBytes;
27
49
  /** `limits` checked, each a whole number from 1 to `looseLimits`' own, or a `RangeError`. */
28
50
  const checkedLoose = (limits) => {
29
51
  const each = (kind) => {
@@ -33,7 +55,8 @@ const checkedLoose = (limits) => {
33
55
  };
34
56
  return {
35
57
  objects: each("objects"),
36
- bytes: each("bytes")
58
+ bytes: each("bytes"),
59
+ fileBytes: each("fileBytes")
37
60
  };
38
61
  };
39
62
  const tooMany = (most) => (count) => gitError("RESOURCE_EXHAUSTED", `push has ${count.toLocaleString("en-US")} objects; this server takes ${most.toLocaleString("en-US")} per push`, {
@@ -52,29 +75,63 @@ const received = /* @__PURE__ */ new WeakSet();
52
75
  * as Git's HTTP does; `packs()`'s, whose small pushes are rows too, isn't one.
53
76
  */
54
77
  const isLoose = (quarantine) => received.has(quarantine);
55
- /** A push's pack as rows for its commit: no quarantine row, since nothing outlives the commit. */
56
- const receiveRows = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, receive, limits) {
78
+ /**
79
+ * A push's pack as rows for its commit, its objects past one row as chunks, in its memory's
80
+ * allotment of `budget`: no quarantine row within one commit's rows, and a batch's past them, or
81
+ * once its first chunk opens one. A receive that fails after it opened one abandons it.
82
+ */
83
+ const receiveRows = (store, listed, receive, limits, budget) => Effect.scoped(Effect.gen(function* () {
84
+ const allotment = yield* budget.admit(receiveFloorOf(limits.bytes));
85
+ const { repo } = listed;
86
+ let opened;
87
+ const large = {
88
+ fileBytes: limits.fileBytes,
89
+ totalBytes: largeBytesMost,
90
+ stage: Effect.fnUntraced(function* (part, index, bytes) {
91
+ opened ??= yield* openBatch({
92
+ store,
93
+ repo,
94
+ at: yield* Clock.currentTimeMillis
95
+ });
96
+ yield* stageChunk(store, repo, opened, part, index, bytes);
97
+ }),
98
+ hold: (bytes) => allotment.grow(bytes),
99
+ staged: (object) => Effect.map(new ChunkReader(store, repo, object.oid, rowOf(object).value, () => Effect.succeed(void 0)).whole(), ({ bytes }) => bytes),
100
+ row: (object) => rowOf(object)
101
+ };
102
+ const rowOf = (object) => chunkedRow(object.oid, object.type, object.size, opened.batch, object.part);
103
+ return yield* receivedRows(store, listed, receive, limits, large, () => opened).pipe(Effect.onError(() => opened === void 0 ? Effect.void : abandonBatch(store, repo, opened.batch)));
104
+ }));
105
+ /** `receiveRows`' receive, its batch `opened()` once its first chunk is staged. */
106
+ const receivedRows = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, receive, limits, large, opened) {
107
+ const heldWhole = heldRows(store, listed);
57
108
  const unpacked = yield* unpackObjects({
58
109
  receive,
59
110
  limits,
60
111
  tooMany: tooMany(limits.objects),
61
- held: heldRows(store, listed),
62
- offsetDeltas: "resolve"
112
+ held: Effect.fnUntraced(function* (oids) {
113
+ const chunked = [...(yield* rowHeaders(store, listed)(oids)).values()].filter(({ type, size }) => !fitsRow(type, size));
114
+ yield* large.hold(chunked.reduce((sum, { size }) => sum + size, 0));
115
+ return yield* heldWhole(oids);
116
+ }),
117
+ headers: rowHeaders(store, listed),
118
+ offsetDeltas: "resolve",
119
+ large
63
120
  });
121
+ const staged = yield* rowsChange(store, listed.repo, unpacked.rows, unpacked.moved, opened());
122
+ readsOwnChunks(staged.change, (oid, chunked) => new ChunkReader(store, listed.repo, oid, chunked, () => Effect.succeed(void 0)));
64
123
  const quarantine = {
65
124
  id: newChangeId(),
66
- change: {
67
- put: unpacked.rows,
68
- rows: unpacked.moved
69
- },
125
+ change: staged.change,
70
126
  bytes: unpacked.bytes,
71
- objects: unpacked.objects.length,
127
+ objects: unpacked.count,
72
128
  lfsPointers: yield* pointersOfObjects(unpacked.objects),
73
- ...largestOf(unpacked.objects)
129
+ ...largestOf([...unpacked.objects, ...unpacked.chunked])
74
130
  };
75
131
  if (unpacked.cut.length > 0) quarantine.cut = unpacked.cut;
132
+ if (staged.quarantine !== void 0) quarantine.quarantine = staged.quarantine;
76
133
  received.add(quarantine);
77
- const whole = receive.partial === true || receive.boundary !== void 0 ? void 0 : wholeRoots(unpacked.objects);
134
+ const whole = receive.partial === true || receive.boundary !== void 0 || unpacked.chunked.length > 0 ? void 0 : wholeRoots(unpacked.objects);
78
135
  if (whole === void 0) return quarantine;
79
136
  quarantine.roots = whole.roots;
80
137
  if (whole.outside.length > 64) return quarantine;
@@ -85,15 +142,112 @@ const receiveRows = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed,
85
142
  };
86
143
  return quarantine;
87
144
  });
88
- const readObject = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, oid) {
89
- const object = (yield* heldRows(store, listed)([oid])).get(oid);
90
- return object === void 0 ? void 0 : gitObjectOf(object);
145
+ /**
146
+ * What reading a chunked object of `size` bytes whole holds, allotted from `budget` before its
147
+ * first chunk, and handed to `own` in the step the allot ends in: held until its allotment's
148
+ * `release`, which no scope makes for it. The allot's scope is closed by its failure, so an
149
+ * interrupt or a refusal leaves nothing allotted that no one owns.
150
+ */
151
+ const chunkedCharge = (budget, size, own) => Effect.uninterruptibleMask((restore) => Effect.flatMap(Scope.make(), (scope) => restore(Scope.provide(scope)(budget.allot(chunkedReadBytes(size)))).pipe(Effect.onError(() => Scope.close(scope, Exit.void)), Effect.map((allotment) => {
152
+ own(allotment);
153
+ return allotment;
154
+ }))));
155
+ /**
156
+ * A reader's charges for the chunked objects `objects` reads whole, each a `chunkedCharge`, held
157
+ * until `give` gives it back, or the reader's `release`.
158
+ */
159
+ const readerCharges = (budget) => {
160
+ const held = /* @__PURE__ */ new Set();
161
+ const charge = (size) => chunkedCharge(budget, size, (allotment) => void held.add(allotment));
162
+ const give = (allotment) => {
163
+ held.delete(allotment);
164
+ allotment.release();
165
+ };
166
+ const release = () => {
167
+ for (const allotment of held) allotment.release();
168
+ held.clear();
169
+ };
170
+ return {
171
+ charge,
172
+ give,
173
+ release
174
+ };
175
+ };
176
+ /**
177
+ * `oid`'s object, or `undefined`. One kept as chunks is read whole once `budget` allots what that
178
+ * holds, and handed on as its body, uncopied, its charge given back once the body is read to its
179
+ * end or cancelled, as every caller does with a body it leaves: not at the reader's release, which
180
+ * comes before a caller streams the body on.
181
+ */
182
+ const readObject = /* @__PURE__ */ Effect.fnUntraced(function* (store, listed, oid, budget) {
183
+ const read = {};
184
+ const before = (_, size) => Effect.as(chunkedCharge(budget, size, (allotment) => void (read.charged = allotment)), true);
185
+ yield* eachHeldRow(store, listed, before)([oid], (object) => Effect.sync(() => void (read.object = object))).pipe(Effect.onError(() => Effect.sync(() => read.charged?.release())));
186
+ const { object, charged } = read;
187
+ if (object === void 0) return void 0;
188
+ if (charged === void 0) return gitObjectOf(object);
189
+ return {
190
+ oid: object.oid,
191
+ type: object.type,
192
+ size: object.bytes.byteLength,
193
+ bytes: streamThen(object.bytes, () => charged.release())
194
+ };
91
195
  });
92
196
  /**
197
+ * `before`, with each chunked object's bytes charged to `charges` first: given back if `before`
198
+ * leaves it, and held, if it keeps it, until the reader's release.
199
+ */
200
+ const chargedFirst = (charges, before) => (oid, size) => Effect.flatMap(charges.charge(size), (allotment) => before(oid, size).pipe(Effect.tap((kept) => kept ? Effect.void : Effect.sync(() => charges.give(allotment))), Effect.onError(() => Effect.sync(() => charges.give(allotment)))));
201
+ /**
202
+ * A fetch's reads of `listed`'s rows. A chunked object is read whole, what that holds allotted
203
+ * from `budget` before its first chunk: for a window, until the writer's next window or the fetch's
204
+ * end, which `ended` gives back; for `each`, until its callback ends, so a walk past several holds
205
+ * one at a time.
206
+ */
207
+ const fetchReads = (calls, listed, budget) => {
208
+ let window;
209
+ const ended = Effect.suspend(() => {
210
+ const open = window;
211
+ window = void 0;
212
+ return open === void 0 ? Effect.void : Scope.close(open, Exit.void);
213
+ });
214
+ const allotted = (scope) => (_, size) => Effect.as(Scope.provide(scope)(budget.allot(chunkedReadBytes(size))), true);
215
+ const held = Effect.fnUntraced(function* (oids) {
216
+ yield* ended;
217
+ const scope = yield* Scope.make();
218
+ window = scope;
219
+ const objects = /* @__PURE__ */ new Map();
220
+ yield* eachHeldRow(calls, listed, allotted(scope))(oids, (object) => Effect.sync(() => void objects.set(object.oid, object)));
221
+ return objects;
222
+ });
223
+ const each = (oids, take) => {
224
+ let open;
225
+ const closed = Effect.suspend(() => {
226
+ const scope = open;
227
+ open = void 0;
228
+ return scope === void 0 ? Effect.void : Scope.close(scope, Exit.void);
229
+ });
230
+ const before = (oid, size) => Effect.flatMap(closed, () => Effect.flatMap(Scope.make(), (scope) => {
231
+ open = scope;
232
+ return allotted(scope)(oid, size);
233
+ }));
234
+ return Effect.ensuring(eachHeldRow(calls, listed, before)(oids, (object) => Effect.ensuring(take(object), closed)), closed);
235
+ };
236
+ return {
237
+ reads: {
238
+ held,
239
+ each,
240
+ sizes: rowSizes(calls, listed)
241
+ },
242
+ ended
243
+ };
244
+ };
245
+ /**
93
246
  * `loose()`: each object a row of the repo's scope, with no bucket. A push of more than
94
247
  * `options.objects` objects, 10,000 by default, is refused whole, and so is one whose rows pass
95
- * `options.bytes`, one commit's 8 MiB by default, or with an object whose row passes one row's
96
- * 1 MiB, as `object-too-large`. A whole push names its roots and the rows it links to, so it can
248
+ * `options.bytes`, one commit's 8 MiB by default, of rows within one row's 1 MiB. An object past
249
+ * one row is kept as chunk rows, to `options.fileBytes`, 32 MiB by default, and one past that is
250
+ * refused as `object-too-large`. A whole push names its roots and the rows it links to, so it can
97
251
  * keep a repo's whole-clone mark. The client's default.
98
252
  */
99
253
  const loose = (options = {}) => {
@@ -101,59 +255,50 @@ const loose = (options = {}) => {
101
255
  return {
102
256
  needsBucket: false,
103
257
  open: ({ store: calls, fetchLimits }) => {
104
- const openReader = (listed, scope, listedOnly) => objectReader(listedOnly === true ? {
105
- object: () => Effect.succeed(void 0),
106
- sizes: () => Effect.succeed(/* @__PURE__ */ new Map()),
107
- headers: () => Effect.succeed(/* @__PURE__ */ new Map()),
108
- has: () => Effect.succeed(/* @__PURE__ */ new Set()),
109
- startingWith: () => Effect.succeed({
110
- oids: [],
111
- more: false
112
- }),
113
- objects: () => Effect.succeed({
114
- objects: /* @__PURE__ */ new Map(),
115
- left: []
116
- }),
117
- allotment: allotmentWithin,
118
- release: () => {}
119
- } : {
120
- object: (oid) => readObject(calls, listed, oid),
121
- sizes: rowSizes(calls, listed),
122
- headers: rowHeaders(calls, listed),
123
- has: (oids) => Effect.map(rowHeaders(calls, listed)(oids), (headers) => new Set(headers.keys())),
124
- startingWith: (prefix, most) => Effect.map(rowsStartingWith(calls, listed.repo, prefix, most + 1), ({ oids }) => startingOf([oids], most)),
125
- objects: (oids, bytes) => allottedRows(eachHeldRow(calls, listed), oids, bytes),
126
- allotment: allotmentWithin,
127
- release: () => {}
128
- }, scope);
129
- const face = {
258
+ const budget = new MemoryBudget(allottableOf(defaultMemory), readReserveBytes);
259
+ const openReader = (listed, scope, listedOnly) => {
260
+ const charges = readerCharges(budget);
261
+ return objectReader(listedOnly === true ? {
262
+ object: () => Effect.succeed(void 0),
263
+ sizes: () => Effect.succeed(/* @__PURE__ */ new Map()),
264
+ headers: () => Effect.succeed(/* @__PURE__ */ new Map()),
265
+ has: () => Effect.succeed(/* @__PURE__ */ new Set()),
266
+ startingWith: () => Effect.succeed({
267
+ oids: [],
268
+ more: false
269
+ }),
270
+ objects: () => Effect.succeed({
271
+ objects: /* @__PURE__ */ new Map(),
272
+ left: []
273
+ }),
274
+ allotment: allotmentWithin,
275
+ release: () => {}
276
+ } : {
277
+ object: (oid) => readObject(calls, listed, oid, budget),
278
+ sizes: rowSizes(calls, listed),
279
+ headers: rowHeaders(calls, listed),
280
+ has: (oids) => Effect.map(rowHeaders(calls, listed)(oids), (headers) => new Set(headers.keys())),
281
+ startingWith: (prefix, most) => Effect.map(rowsStartingWith(calls, listed.repo, prefix, most + 1), ({ oids }) => startingOf([oids], most)),
282
+ objects: (oids, bytes) => allottedRows((before) => eachHeldRow(calls, listed, chargedFirst(charges, before)), oids, bytes),
283
+ allotment: allotmentWithin,
284
+ release: charges.release
285
+ }, scope);
286
+ };
287
+ return {
130
288
  reader: (listed, input) => Effect.map(callScope, (scope) => openReader(listed, scope, input?.listedOnly)),
131
289
  pushedCommits: (_, input) => pushedCommitsPage(void 0, input),
132
- receive: (listed, input) => cancelsBody(input.pack, receiveRows(calls, listed, input, limits)),
290
+ receive: (listed, input) => cancelsBody(input.pack, receiveRows(calls, listed, input, limits, budget)),
133
291
  fetch: (listed, input) => {
134
- const reads = {
135
- held: heldRows(calls, listed),
136
- each: eachHeldRow(calls, listed),
137
- sizes: rowSizes(calls, listed)
138
- };
139
- return handingOn(fetchPack(reads, input, fetchLimits));
292
+ const { reads, ended } = fetchReads(calls, listed, budget);
293
+ return handingOn(Effect.onError(fetchPack(reads, input, fetchLimits, { ended }), () => ended));
140
294
  },
141
- maintain: () => Effect.succeed(void 0),
295
+ maintain: (listed, input) => looseUpkeep(input.store, listed, input.at),
142
296
  share: () => Effect.void,
143
- copyRows: (listed, input) => copyRowsPage(calls, listed, input)
144
- };
145
- return {
146
- reader: answering(face.reader),
147
- pushedCommits: answering(face.pushedCommits),
148
- receive: answering(face.receive),
149
- fetch: answering(face.fetch),
150
- maintain: answering(face.maintain),
151
- share: answering(face.share),
152
- copyRows: answering(face.copyRows),
297
+ copyRows: (listed, input) => copyRowsPage(calls, listed, input),
153
298
  readyShallow: false,
154
299
  pushObjectsMost: limits.objects
155
300
  };
156
301
  }
157
302
  };
158
303
  };
159
- export { isLoose, loose, looseLimits, looseObjectsMost };
304
+ export { isLoose, loose, looseFileBytesMost, looseLimits, looseObjectsMost };
@@ -562,9 +562,10 @@ var MemoryBudget = class {
562
562
  }
563
563
  /**
564
564
  * The queue's one wake, run wherever bytes or a waiter leave, granted, refused, interrupted or
565
- * released: it lets in one waiter at a time by `#next`, until none fits. A grant resumes its
566
- * waiter in the same step, which may give bytes back and wake the queue again inside this one.
567
- * Two things keep that safe. `#next` reads the queues as they are after every grant, so no
565
+ * released: it lets in one waiter at a time by `#next`, until none fits. A grant hands its
566
+ * waiter what it's granted in this step, and resumes the waiter's fiber a turn later, in its own
567
+ * request (#2719). Bytes given back in this step, by a refusal or a release a grant leads to,
568
+ * wake the queue again inside this one. Two things keep that safe. `#next` reads the queues as they are after every grant, so no
568
569
  * waiter is granted twice. A wake inside a wake returns at once, marking another pass due, so a
569
570
  * release that lets in a burst of waiters, each giving its bytes back at once, runs flat in this
570
571
  * loop instead of a stack frame for each, which would overflow at about a thousand.
@@ -598,10 +599,21 @@ var MemoryBudget = class {
598
599
  * Waits in `queue` as the waiter `enter` makes, `ms` at most; `None` past it. A wait interrupted,
599
600
  * by its timeout too, leaves the queue and wakes it, since the waiter may have held up others,
600
601
  * and runs its `left`.
602
+ *
603
+ * A grant comes in the step of whatever freed the bytes, often another request's. The waiter
604
+ * takes what it's granted in that step, through `enter`'s own bookkeeping, but its fiber resumes
605
+ * through a promise whose `then` it registered as it parked, so on a Worker it runs again in its
606
+ * own request: workerd refuses to resume one request's fiber in another's step, and the step
607
+ * that freed the bytes would fail instead (#2719). An interrupt between the grant and the resume
608
+ * finds the grant taken, as one after the resume does.
601
609
  */
602
610
  #queued(queue, ms, enter) {
603
611
  return Effect.callback((resume) => {
604
- const { waiter, left } = enter((granted) => resume(Effect.succeed(granted)));
612
+ let grant = () => void 0;
613
+ new Promise((settle) => {
614
+ grant = settle;
615
+ }).then((granted) => resume(Effect.succeed(granted)));
616
+ const { waiter, left } = enter(grant);
605
617
  queue.push(waiter);
606
618
  if (!("room" in waiter) && waiter.grower !== void 0) this.#wakeRooms();
607
619
  return Effect.sync(() => {
@@ -28,9 +28,10 @@ var PastMost = class extends Data.TaggedError("PastMost") {};
28
28
  const plan = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
29
29
  const { inputs, limits, bounds = upkeepRuns } = input;
30
30
  const total = inputs.reduce((sum, each) => sum + each.objects, 0);
31
+ const maxEntries = total + input.rows.length;
31
32
  const packs = [];
32
33
  const spent = [];
33
- let pack = openPack(input.readers());
34
+ let pack = openPack(input.readers(), maxEntries);
34
35
  let spend = packStart;
35
36
  let opened = input.from ?? {
36
37
  kind: "commit",
@@ -73,7 +74,7 @@ const plan = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
73
74
  bytes: spend.bytes
74
75
  });
75
76
  spent.push(spend);
76
- pack = openPack(input.readers());
77
+ pack = openPack(input.readers(), maxEntries);
77
78
  spend = packStart;
78
79
  opened = {
79
80
  ...at,
@@ -129,8 +129,14 @@ const MergeRow = Schema.Struct({
129
129
  /** The packs the plan has cut so far, in write order, at most `mergePacksMost`. */
130
130
  planned: Schema.Array(PlannedPack).check(Schema.isMaxLength(mergePacksMost)),
131
131
  /** The packs written so far, in write order. */
132
- written: Schema.Array(WrittenPack).check(Schema.isMaxLength(mergePacksMost))
132
+ written: Schema.Array(WrittenPack).check(Schema.isMaxLength(mergePacksMost)),
133
+ /**
134
+ * A prune merge's: the number of the pass's classes object its keep was read from. A later try
135
+ * reads that keep again for its remap only from the object of this number (#2196).
136
+ */
137
+ classes: Schema.optional(Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)))
133
138
  }).check(Schema.makeFilter((row) => {
139
+ if (row.classes !== void 0 && row.owner !== "prune") return "only a prune merge's keep comes from a classes object";
134
140
  if ((row.pass === "plan" || row.pass === "write") !== (row.cursor !== void 0)) return "only its plan and write passes have a cursor";
135
141
  if (row.pass === "plan" ? row.written.length > 0 : row.planned.length === 0) return "it writes a pack before its plan is done";
136
142
  const left = row.planned.length - row.written.length;