@ref0/git 0.3.0 → 0.6.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 (631) hide show
  1. package/dist/_virtual/_rolldown/runtime.mjs +12 -0
  2. package/dist/access/private-refs.d.mts +12 -9
  3. package/dist/access/private-refs.mjs +70 -48
  4. package/dist/auth/access-jwt.mjs +7 -7
  5. package/dist/auth/auth.d.mts +41 -0
  6. package/dist/auth/auth.mjs +39 -0
  7. package/dist/auth/authorize.mjs +65 -83
  8. package/dist/auth/bridge.mjs +30 -0
  9. package/dist/auth/fences.d.mts +22 -2
  10. package/dist/auth/fences.mjs +3 -3
  11. package/dist/auth/grants.d.mts +25 -0
  12. package/dist/auth/grants.mjs +29 -34
  13. package/dist/auth/helpers.mjs +4 -4
  14. package/dist/auth/host-function.d.mts +9 -2
  15. package/dist/auth/host-function.mjs +35 -8
  16. package/dist/auth/identify.d.mts +7 -2
  17. package/dist/auth/identify.mjs +9 -11
  18. package/dist/auth/namespaces.d.mts +3 -0
  19. package/dist/auth/policy.d.mts +57 -0
  20. package/dist/auth/policy.mjs +56 -0
  21. package/dist/auth/token-rows.mjs +6 -6
  22. package/dist/auth/token-text.mjs +16 -4
  23. package/dist/auth/tokens.d.mts +3 -0
  24. package/dist/auth/tokens.mjs +63 -24
  25. package/dist/auth.d.mts +2 -1
  26. package/dist/auth.mjs +2 -1
  27. package/dist/client/answer.mjs +49 -11
  28. package/dist/client/client.d.mts +2 -2
  29. package/dist/client/client.mjs +3 -3
  30. package/dist/client/git-http.d.mts +6 -0
  31. package/dist/client/git-http.mjs +23 -36
  32. package/dist/client/helper-node.d.mts +12 -0
  33. package/dist/client/helper-node.mjs +108 -5
  34. package/dist/client/local.mjs +96 -99
  35. package/dist/client/negotiate.mjs +10 -8
  36. package/dist/client/push-upload.d.mts +14 -0
  37. package/dist/client/push-upload.mjs +12 -12
  38. package/dist/client/remote-helper.mjs +22 -20
  39. package/dist/client/remote.mjs +28 -22
  40. package/dist/client/run-remote-helper.d.mts +40 -16
  41. package/dist/client/run-remote-helper.mjs +147 -154
  42. package/dist/client/scrub.d.mts +8 -2
  43. package/dist/client/scrub.mjs +76 -4
  44. package/dist/client/slice-push.d.mts +77 -0
  45. package/dist/client/slice-push.mjs +169 -0
  46. package/dist/client/slice-report.mjs +188 -0
  47. package/dist/client/slices.d.mts +44 -0
  48. package/dist/client/slices.mjs +131 -0
  49. package/dist/client/transport.d.mts +1 -0
  50. package/dist/client/transport.mjs +30 -26
  51. package/dist/contracts/access.d.mts +41 -10
  52. package/dist/contracts/actors.d.mts +28 -10
  53. package/dist/contracts/actors.mjs +17 -0
  54. package/dist/contracts/authorize.d.mts +81 -0
  55. package/dist/contracts/authorize.mjs +25 -0
  56. package/dist/contracts/blobs.d.mts +48 -15
  57. package/dist/contracts/blobs.mjs +30 -0
  58. package/dist/contracts/calls-spent.d.mts +1 -0
  59. package/dist/contracts/calls-spent.mjs +58 -18
  60. package/dist/contracts/client.d.mts +14 -16
  61. package/dist/contracts/commits.d.mts +558 -76
  62. package/dist/contracts/commits.mjs +147 -0
  63. package/dist/contracts/engine.d.mts +91 -55
  64. package/dist/contracts/engine.mjs +103 -0
  65. package/dist/contracts/events.d.mts +1410 -206
  66. package/dist/contracts/events.mjs +496 -0
  67. package/dist/contracts/files.d.mts +295 -50
  68. package/dist/contracts/files.mjs +100 -0
  69. package/dist/contracts/forks.d.mts +306 -25
  70. package/dist/contracts/forks.mjs +39 -0
  71. package/dist/contracts/git.d.mts +172 -0
  72. package/dist/contracts/git.mjs +23 -0
  73. package/dist/contracts/grants.d.mts +7 -2
  74. package/dist/contracts/ids.d.mts +23 -8
  75. package/dist/contracts/ids.mjs +40 -5
  76. package/dist/contracts/lfs.d.mts +12 -4
  77. package/dist/contracts/merges.d.mts +68 -16
  78. package/dist/contracts/merges.mjs +27 -0
  79. package/dist/contracts/namespaces.d.mts +14 -0
  80. package/dist/contracts/object-values.d.mts +96 -0
  81. package/dist/contracts/object-values.mjs +104 -0
  82. package/dist/contracts/objects.d.mts +329 -88
  83. package/dist/contracts/operations.d.mts +24 -16
  84. package/dist/contracts/promises.d.mts +10 -11
  85. package/dist/contracts/push-uploads.d.mts +40 -25
  86. package/dist/contracts/push-uploads.mjs +54 -0
  87. package/dist/contracts/queue.d.mts +454 -141
  88. package/dist/contracts/queue.mjs +197 -0
  89. package/dist/contracts/refs.d.mts +248 -45
  90. package/dist/contracts/refs.mjs +117 -0
  91. package/dist/contracts/repo-records.d.mts +34 -0
  92. package/dist/contracts/repo-records.mjs +18 -0
  93. package/dist/contracts/repos.d.mts +411 -58
  94. package/dist/contracts/repos.mjs +136 -0
  95. package/dist/contracts/result.d.mts +339 -69
  96. package/dist/contracts/result.mjs +355 -5
  97. package/dist/contracts/rules.d.mts +60 -48
  98. package/dist/contracts/rules.mjs +9 -0
  99. package/dist/contracts/server.d.mts +124 -51
  100. package/dist/contracts/services.d.mts +15 -24
  101. package/dist/contracts/services.mjs +5 -9
  102. package/dist/contracts/signin.d.mts +64 -31
  103. package/dist/contracts/signin.mjs +18 -0
  104. package/dist/contracts/store.d.mts +45 -5
  105. package/dist/contracts/store.mjs +31 -0
  106. package/dist/contracts/sync.d.mts +81 -46
  107. package/dist/contracts/sync.mjs +41 -2
  108. package/dist/contracts/tags.d.mts +204 -22
  109. package/dist/contracts/tags.mjs +51 -1
  110. package/dist/contracts/tokens.d.mts +32 -7
  111. package/dist/contracts/tokens.mjs +31 -1
  112. package/dist/contracts/topics.d.mts +123 -67
  113. package/dist/contracts/topics.mjs +109 -0
  114. package/dist/contracts/trees.d.mts +132 -52
  115. package/dist/contracts/trees.mjs +105 -0
  116. package/dist/contracts/work.d.mts +128 -21
  117. package/dist/contracts/work.mjs +69 -0
  118. package/dist/core/access.d.mts +25 -14
  119. package/dist/core/access.mjs +93 -108
  120. package/dist/core/ancestry.mjs +86 -18
  121. package/dist/core/call-names.d.mts +3 -1
  122. package/dist/core/call-names.mjs +1 -0
  123. package/dist/core/call-services.mjs +73 -0
  124. package/dist/core/changes.d.mts +31 -0
  125. package/dist/core/changes.mjs +5 -0
  126. package/dist/core/claim-rows.d.mts +4 -0
  127. package/dist/core/claim-rows.mjs +53 -0
  128. package/dist/core/clock.mjs +3 -3
  129. package/dist/core/events/deliver.d.mts +12 -0
  130. package/dist/core/events/deliver.mjs +454 -146
  131. package/dist/core/events/seen.mjs +138 -0
  132. package/dist/core/forks.mjs +435 -161
  133. package/dist/core/hooks/order.d.mts +9 -0
  134. package/dist/core/hooks/order.mjs +25 -0
  135. package/dist/core/hooks/post-receive.mjs +33 -29
  136. package/dist/core/hooks/pre-receive.d.mts +8 -1
  137. package/dist/core/hooks/pre-receive.mjs +8 -6
  138. package/dist/core/imports.mjs +212 -0
  139. package/dist/core/index-job.mjs +152 -53
  140. package/dist/core/merge-parts.d.mts +30 -0
  141. package/dist/core/merge-parts.mjs +31 -0
  142. package/dist/core/names.mjs +4 -16
  143. package/dist/core/namespaces.d.mts +2 -0
  144. package/dist/core/objects/blobs.mjs +4 -4
  145. package/dist/core/objects/commit-writes.mjs +19 -17
  146. package/dist/core/objects/commits.mjs +12 -12
  147. package/dist/core/objects/files.mjs +10 -11
  148. package/dist/core/objects/lines.mjs +15 -32
  149. package/dist/core/objects/merges.mjs +4 -4
  150. package/dist/core/objects/objects-layer.d.mts +21 -0
  151. package/dist/core/objects/objects-layer.mjs +47 -0
  152. package/dist/core/objects/objects-namespace.d.mts +6 -0
  153. package/dist/core/objects/objects-namespace.mjs +13 -0
  154. package/dist/core/objects/objects.d.mts +49 -0
  155. package/dist/core/objects/objects.mjs +18 -0
  156. package/dist/core/objects/peel.mjs +3 -3
  157. package/dist/core/objects/reading.mjs +135 -40
  158. package/dist/core/objects/tags.mjs +7 -7
  159. package/dist/core/objects/tree-edits.mjs +40 -27
  160. package/dist/core/objects/trees.mjs +23 -18
  161. package/dist/core/objects/writing.mjs +43 -44
  162. package/dist/core/own-writes.mjs +3 -3
  163. package/dist/core/parts.d.mts +131 -0
  164. package/dist/core/parts.mjs +59 -0
  165. package/dist/core/promise.mjs +13 -9
  166. package/dist/core/publish.mjs +27 -17
  167. package/dist/core/purge.d.mts +8 -0
  168. package/dist/core/purge.mjs +237 -0
  169. package/dist/core/push-decide.mjs +116 -29
  170. package/dist/core/push.mjs +352 -171
  171. package/dist/core/receipts.d.mts +4 -3
  172. package/dist/core/receipts.mjs +20 -12
  173. package/dist/core/ref-conflicts.mjs +70 -4
  174. package/dist/core/ref-index-job.mjs +176 -0
  175. package/dist/core/ref-index.d.mts +26 -0
  176. package/dist/core/ref-index.mjs +156 -0
  177. package/dist/core/ref-view.mjs +171 -0
  178. package/dist/core/refs.mjs +318 -98
  179. package/dist/core/repack.d.mts +11 -0
  180. package/dist/core/repack.mjs +264 -136
  181. package/dist/core/repo-info.mjs +99 -0
  182. package/dist/core/repos.mjs +114 -80
  183. package/dist/core/rules/changes.mjs +48 -20
  184. package/dist/core/rules/check.mjs +36 -28
  185. package/dist/core/rules/commit-changes.d.mts +13 -0
  186. package/dist/core/rules/commit-changes.mjs +100 -91
  187. package/dist/core/rules/context.d.mts +67 -8
  188. package/dist/core/rules/context.mjs +88 -51
  189. package/dist/core/rules/facts.mjs +1 -1
  190. package/dist/core/rules/fetch.mjs +24 -26
  191. package/dist/core/rules/files.d.mts +13 -0
  192. package/dist/core/rules/files.mjs +27 -28
  193. package/dist/core/rules/namespace.d.mts +2 -0
  194. package/dist/core/rules/patterns.mjs +29 -5
  195. package/dist/core/rules/protect.d.mts +12 -6
  196. package/dist/core/rules/protect.mjs +22 -20
  197. package/dist/core/rules/rules-layer.d.mts +17 -0
  198. package/dist/core/rules/rules-layer.mjs +26 -0
  199. package/dist/core/rules/rules.d.mts +8 -0
  200. package/dist/core/rules/rules.mjs +16 -0
  201. package/dist/core/rules/service.mjs +18 -0
  202. package/dist/core/seam.d.mts +60 -10
  203. package/dist/core/seam.mjs +25 -15
  204. package/dist/core/still-takes.mjs +75 -0
  205. package/dist/core/tokens.mjs +29 -23
  206. package/dist/core/view.d.mts +106 -6
  207. package/dist/core/view.mjs +215 -114
  208. package/dist/core/work.mjs +40 -14
  209. package/dist/effect.d.mts +3 -4
  210. package/dist/effect.mjs +2 -3
  211. package/dist/engine/allotted-xdiff.d.mts +1 -0
  212. package/dist/engine/allotted-xdiff.mjs +1 -1
  213. package/dist/engine/attributes.mjs +1 -1
  214. package/dist/engine/combined.d.mts +18 -0
  215. package/dist/engine/combined.mjs +39 -44
  216. package/dist/engine/commits.mjs +5 -4
  217. package/dist/engine/content.d.mts +3 -2
  218. package/dist/engine/content.mjs +2 -2
  219. package/dist/engine/failures.d.mts +2 -2
  220. package/dist/engine/failures.mjs +2 -9
  221. package/dist/engine/merge-base-walk.d.mts +3 -2
  222. package/dist/engine/merge-base-walk.mjs +1 -1
  223. package/dist/engine/merge-bases.mjs +3 -2
  224. package/dist/engine/merge.mjs +568 -566
  225. package/dist/engine/parts.d.mts +3 -2
  226. package/dist/engine/parts.mjs +40 -7
  227. package/dist/engine/reads.d.mts +1 -0
  228. package/dist/engine/reads.mjs +5 -5
  229. package/dist/engine/walk.mjs +23 -24
  230. package/dist/engine/xdiff.d.mts +2 -33
  231. package/dist/engine/xdiff.mjs +6 -3
  232. package/dist/event-streams/event-streams.d.mts +25 -0
  233. package/dist/event-streams/event-streams.mjs +22 -0
  234. package/dist/event-streams/namespace.d.mts +2 -0
  235. package/dist/event-streams/stream.d.mts +42 -0
  236. package/dist/{core/events → event-streams}/stream.mjs +106 -49
  237. package/dist/extend.d.mts +5 -2
  238. package/dist/http/answers.mjs +8 -4
  239. package/dist/http/bodies.mjs +84 -56
  240. package/dist/http/core-parts.mjs +222 -68
  241. package/dist/http/handler.d.mts +2 -0
  242. package/dist/http/handler.mjs +19 -13
  243. package/dist/http/node.d.mts +2 -23
  244. package/dist/http/node.mjs +10 -6
  245. package/dist/http/parts.d.mts +13 -0
  246. package/dist/http/push-uploads.d.mts +17 -0
  247. package/dist/http/push-uploads.mjs +94 -87
  248. package/dist/http/receive-pack.mjs +165 -29
  249. package/dist/http/upload-pack.mjs +106 -81
  250. package/dist/index.d.mts +52 -28
  251. package/dist/index.mjs +31 -7
  252. package/dist/lfs/base.d.mts +32 -0
  253. package/dist/lfs/base.mjs +8 -0
  254. package/dist/lfs/calls.mjs +21 -12
  255. package/dist/lfs/layer.d.mts +27 -0
  256. package/dist/lfs/layer.mjs +64 -0
  257. package/dist/lfs/locks.mjs +36 -46
  258. package/dist/lfs/namespace.d.mts +2 -0
  259. package/dist/lfs/objects.d.mts +26 -0
  260. package/dist/lfs/objects.mjs +83 -94
  261. package/dist/lfs/pointers.mjs +13 -11
  262. package/dist/lfs/public.d.mts +5 -0
  263. package/dist/lfs/public.mjs +8 -0
  264. package/dist/lfs/purge.mjs +44 -0
  265. package/dist/lfs/rows.mjs +30 -18
  266. package/dist/lfs/service.d.mts +14 -0
  267. package/dist/lfs/service.mjs +26 -28
  268. package/dist/lfs/upkeep.mjs +39 -54
  269. package/dist/lfs/wire.mjs +80 -38
  270. package/dist/merges/merges.d.mts +20 -0
  271. package/dist/merges/merges.mjs +32 -0
  272. package/dist/merges/namespace.d.mts +2 -0
  273. package/dist/merges/public.d.mts +6 -0
  274. package/dist/merges/public.mjs +10 -0
  275. package/dist/node.d.mts +3 -3
  276. package/dist/node.mjs +1 -3
  277. package/dist/protocol/bytes/buffers.d.mts +9 -3
  278. package/dist/protocol/bytes/buffers.mjs +11 -5
  279. package/dist/protocol/bytes/deflate.d.mts +7 -5
  280. package/dist/protocol/bytes/deflate.mjs +59 -23
  281. package/dist/protocol/bytes/inflate.d.mts +4 -3
  282. package/dist/protocol/bytes/inflate.mjs +61 -26
  283. package/dist/protocol/bytes/reader.mjs +61 -0
  284. package/dist/protocol/bytes/sha1-hasher.d.mts +3 -1
  285. package/dist/protocol/bytes/sha1-hasher.mjs +13 -3
  286. package/dist/protocol/bytes/sha1.d.mts +1 -1
  287. package/dist/protocol/bytes/sha1.mjs +5 -5
  288. package/dist/protocol/bytes/streams.mjs +16 -6
  289. package/dist/protocol/diff/patch.d.mts +4 -0
  290. package/dist/protocol/diff/patch.mjs +1 -1
  291. package/dist/protocol/diff/paths.mjs +1 -1
  292. package/dist/protocol/diff/read.d.mts +1 -1
  293. package/dist/protocol/diff/read.mjs +102 -90
  294. package/dist/protocol/framing/pkt-line.d.mts +1 -0
  295. package/dist/protocol/framing/pkt-line.mjs +40 -6
  296. package/dist/protocol/objects/checked-blobs.d.mts +1 -0
  297. package/dist/protocol/objects/fsck.mjs +7 -1
  298. package/dist/protocol/objects/held.mjs +5 -11
  299. package/dist/protocol/objects/ident.mjs +1 -1
  300. package/dist/protocol/objects/object-rules.mjs +15 -7
  301. package/dist/protocol/objects/object.d.mts +6 -2
  302. package/dist/protocol/objects/object.mjs +5 -2
  303. package/dist/protocol/objects/tag.d.mts +3 -1
  304. package/dist/protocol/objects/tag.mjs +27 -1
  305. package/dist/protocol/objects/tree.mjs +1 -1
  306. package/dist/protocol/packs/delta.d.mts +1 -1
  307. package/dist/protocol/packs/delta.mjs +2 -2
  308. package/dist/protocol/packs/graph.mjs +55 -56
  309. package/dist/protocol/packs/idx.d.mts +4 -2
  310. package/dist/protocol/packs/idx.mjs +156 -63
  311. package/dist/protocol/packs/indexer.d.mts +22 -4
  312. package/dist/protocol/packs/indexer.mjs +14 -35
  313. package/dist/protocol/packs/parts.mjs +5 -5
  314. package/dist/protocol/packs/pos.mjs +12 -5
  315. package/dist/protocol/packs/reader.d.mts +19 -12
  316. package/dist/protocol/packs/reader.mjs +252 -25
  317. package/dist/protocol/packs/rev.d.mts +1 -1
  318. package/dist/protocol/packs/rev.mjs +42 -24
  319. package/dist/protocol/packs/types-file.mjs +85 -0
  320. package/dist/protocol/packs/write-error.d.mts +1 -1
  321. package/dist/protocol/packs/write-error.mjs +2 -2
  322. package/dist/protocol/packs/writer.d.mts +40 -15
  323. package/dist/protocol/packs/writer.mjs +142 -49
  324. package/dist/protocol/wire/advertisement.d.mts +34 -15
  325. package/dist/protocol/wire/advertisement.mjs +135 -35
  326. package/dist/protocol/wire/fetch.d.mts +57 -19
  327. package/dist/protocol/wire/fetch.mjs +57 -26
  328. package/dist/protocol/wire/json.mjs +25 -0
  329. package/dist/protocol/wire/lines.d.mts +22 -0
  330. package/dist/protocol/wire/lines.mjs +51 -26
  331. package/dist/protocol/wire/push-limits.d.mts +6 -0
  332. package/dist/protocol/wire/push-limits.mjs +88 -0
  333. package/dist/protocol/wire/push-uploads.mjs +3 -28
  334. package/dist/protocol/wire/receive-pack.d.mts +30 -14
  335. package/dist/protocol/wire/receive-pack.mjs +29 -2
  336. package/dist/protocol/wire/report-status.d.mts +30 -11
  337. package/dist/protocol/wire/report-status.mjs +21 -2
  338. package/dist/protocol/wire/v2.d.mts +45 -29
  339. package/dist/protocol/wire/v2.mjs +95 -18
  340. package/dist/protocol.d.mts +4 -3
  341. package/dist/protocol.mjs +7 -6
  342. package/dist/queue/advance.mjs +240 -148
  343. package/dist/queue/callers.mjs +12 -9
  344. package/dist/queue/calls.mjs +315 -157
  345. package/dist/queue/commit.mjs +86 -35
  346. package/dist/queue/host.d.mts +39 -12
  347. package/dist/queue/host.mjs +36 -38
  348. package/dist/queue/lanes.mjs +1 -1
  349. package/dist/queue/layer.d.mts +16 -0
  350. package/dist/queue/layer.mjs +60 -0
  351. package/dist/queue/limits.mjs +43 -2
  352. package/dist/queue/namespace.d.mts +2 -0
  353. package/dist/queue/pages.mjs +1 -1
  354. package/dist/queue/public.d.mts +6 -0
  355. package/dist/queue/public.mjs +21 -0
  356. package/dist/queue/push-option.mjs +49 -30
  357. package/dist/queue/rows.mjs +38 -21
  358. package/dist/queue/schedule.mjs +22 -22
  359. package/dist/queue/search.mjs +8 -7
  360. package/dist/queue/state.mjs +68 -18
  361. package/dist/queue/steps.mjs +16 -7
  362. package/dist/queue/trim.mjs +284 -0
  363. package/dist/remote-helper.d.mts +5 -2
  364. package/dist/remote-helper.mjs +5 -2
  365. package/dist/rest/api.d.mts +1 -1
  366. package/dist/rest/blobs.d.mts +799 -32
  367. package/dist/rest/blobs.mjs +4 -4
  368. package/dist/rest/caller.d.mts +4163 -36
  369. package/dist/rest/caller.mjs +2 -2
  370. package/dist/rest/client.mjs +80 -70
  371. package/dist/rest/commits.d.mts +3261 -190
  372. package/dist/rest/commits.mjs +18 -64
  373. package/dist/rest/errors.d.mts +2082 -22
  374. package/dist/rest/errors.mjs +46 -89
  375. package/dist/rest/events.d.mts +394 -11
  376. package/dist/rest/events.mjs +13 -9
  377. package/dist/rest/files.d.mts +1265 -114
  378. package/dist/rest/files.mjs +11 -42
  379. package/dist/rest/forks.d.mts +2045 -102
  380. package/dist/rest/forks.mjs +10 -13
  381. package/dist/rest/handler.d.mts +3 -0
  382. package/dist/rest/handler.mjs +35 -19
  383. package/dist/rest/handlers.mjs +53 -60
  384. package/dist/rest/layer.d.mts +14 -0
  385. package/dist/rest/layer.mjs +52 -0
  386. package/dist/rest/listen.d.mts +5 -8
  387. package/dist/rest/listen.mjs +23 -29
  388. package/dist/rest/me.d.mts +393 -10
  389. package/dist/rest/me.mjs +2 -2
  390. package/dist/rest/merges.d.mts +399 -16
  391. package/dist/rest/merges.mjs +3 -17
  392. package/dist/rest/namespace.d.mts +2 -0
  393. package/dist/rest/paths.mjs +1 -0
  394. package/dist/rest/queue.d.mts +5658 -283
  395. package/dist/rest/queue.mjs +15 -130
  396. package/dist/rest/refs.d.mts +2869 -142
  397. package/dist/rest/refs.mjs +19 -39
  398. package/dist/rest/repos.d.mts +2421 -93
  399. package/dist/rest/repos.mjs +10 -33
  400. package/dist/rest/tags.d.mts +1220 -69
  401. package/dist/rest/tags.mjs +6 -34
  402. package/dist/rest/tokens.d.mts +2358 -55
  403. package/dist/rest/tokens.mjs +7 -4
  404. package/dist/rest/topics.d.mts +2053 -106
  405. package/dist/rest/topics.mjs +23 -71
  406. package/dist/rest/trees.d.mts +1616 -81
  407. package/dist/rest/trees.mjs +16 -57
  408. package/dist/rest/wire.d.mts +404 -0
  409. package/dist/rest/wire.mjs +32 -46
  410. package/dist/rest/work.d.mts +1204 -63
  411. package/dist/rest/work.mjs +7 -51
  412. package/dist/rest.d.mts +3 -3
  413. package/dist/server/edge-node.d.mts +20 -0
  414. package/dist/server/edge-node.mjs +20 -0
  415. package/dist/server/edge.d.mts +10 -0
  416. package/dist/server/edge.mjs +23 -0
  417. package/dist/server/extension.d.mts +6 -2
  418. package/dist/server/extension.mjs +54 -30
  419. package/dist/server/git-layer.d.mts +34 -0
  420. package/dist/server/git-layer.mjs +118 -0
  421. package/dist/server/git-namespace.d.mts +7 -0
  422. package/dist/server/git-namespace.mjs +18 -0
  423. package/dist/server/lifecycle.d.mts +1 -2
  424. package/dist/server/lifecycle.mjs +8 -15
  425. package/dist/server/namespaces.d.mts +2 -0
  426. package/dist/server/registry.d.mts +12 -0
  427. package/dist/server/registry.mjs +218 -0
  428. package/dist/server/route-match.mjs +88 -0
  429. package/dist/server/routes.d.mts +12 -8
  430. package/dist/server/routes.mjs +27 -18
  431. package/dist/server/server.d.mts +22 -0
  432. package/dist/server/server.mjs +335 -210
  433. package/dist/server/uploads.d.mts +14 -0
  434. package/dist/server/uploads.mjs +15 -0
  435. package/dist/signin/codes.mjs +9 -6
  436. package/dist/signin/context.d.mts +1 -0
  437. package/dist/signin/context.mjs +4 -4
  438. package/dist/signin/device.mjs +8 -8
  439. package/dist/signin/forms.mjs +11 -29
  440. package/dist/signin/grants.d.mts +4 -2
  441. package/dist/signin/grants.mjs +20 -19
  442. package/dist/signin/route.mjs +2 -2
  443. package/dist/signin/web.mjs +7 -7
  444. package/dist/signin/wire.mjs +6 -6
  445. package/dist/storage/budget.mjs +51 -18
  446. package/dist/storage/calls.d.mts +28 -11
  447. package/dist/storage/calls.mjs +354 -117
  448. package/dist/storage/clean-up.mjs +121 -46
  449. package/dist/storage/counted-bucket.mjs +115 -0
  450. package/dist/storage/fetch.d.mts +2 -0
  451. package/dist/storage/fetch.mjs +243 -100
  452. package/dist/storage/fsck.mjs +56 -7
  453. package/dist/storage/held-types.d.mts +7 -0
  454. package/dist/storage/held-types.mjs +263 -0
  455. package/dist/storage/host-bucket.mjs +43 -0
  456. package/dist/storage/id-mix.d.mts +1 -0
  457. package/dist/storage/id-mix.mjs +55 -0
  458. package/dist/storage/index-bitmaps.d.mts +2 -1
  459. package/dist/storage/index-bitmaps.mjs +233 -101
  460. package/dist/storage/index-build.d.mts +6 -2
  461. package/dist/storage/index-build.mjs +650 -164
  462. package/dist/storage/index-fetch.d.mts +3 -1
  463. package/dist/storage/index-fetch.mjs +297 -195
  464. package/dist/storage/index-files.mjs +25 -27
  465. package/dist/storage/index-graph.d.mts +2 -1
  466. package/dist/storage/index-graph.mjs +127 -91
  467. package/dist/storage/index-layers.d.mts +11 -0
  468. package/dist/storage/index-layers.mjs +258 -78
  469. package/dist/storage/index-reach.mjs +181 -75
  470. package/dist/storage/index-remap.mjs +74 -32
  471. package/dist/storage/index-shallow.mjs +311 -0
  472. package/dist/storage/index-visible.mjs +168 -0
  473. package/dist/storage/layout.d.mts +1 -0
  474. package/dist/storage/layout.mjs +44 -8
  475. package/dist/storage/lfs-pointers.d.mts +3 -1
  476. package/dist/storage/lfs-pointers.mjs +25 -9
  477. package/dist/storage/link-join.d.mts +4 -0
  478. package/dist/storage/link-join.mjs +50 -12
  479. package/dist/storage/links.mjs +89 -4
  480. package/dist/storage/listed-ids.mjs +10 -0
  481. package/dist/storage/loose.d.mts +11 -4
  482. package/dist/storage/loose.mjs +102 -69
  483. package/dist/storage/memory-budget.d.mts +5 -0
  484. package/dist/storage/memory-budget.mjs +530 -102
  485. package/dist/storage/merge-choose.mjs +258 -0
  486. package/dist/storage/merge-cut.mjs +47 -0
  487. package/dist/storage/merge-fence.mjs +89 -0
  488. package/dist/storage/merge-index.mjs +347 -0
  489. package/dist/storage/merge-most.mjs +202 -0
  490. package/dist/storage/merge-plan.mjs +171 -0
  491. package/dist/storage/merge-row.mjs +258 -0
  492. package/dist/storage/merge-stream.mjs +497 -0
  493. package/dist/storage/merge-walk.mjs +199 -0
  494. package/dist/storage/merge-write.mjs +129 -0
  495. package/dist/storage/merge.d.mts +10 -0
  496. package/dist/storage/merge.mjs +82 -306
  497. package/dist/storage/object-rows.d.mts +4 -2
  498. package/dist/storage/object-rows.mjs +101 -17
  499. package/dist/storage/pack-order.d.mts +1 -1
  500. package/dist/storage/pack-order.mjs +69 -54
  501. package/dist/storage/pack-ranges.d.mts +1 -1
  502. package/dist/storage/pack-ranges.mjs +396 -60
  503. package/dist/storage/pack-reads.d.mts +6 -2
  504. package/dist/storage/pack-reads.mjs +598 -126
  505. package/dist/storage/pack-receive.d.mts +5 -0
  506. package/dist/storage/pack-receive.mjs +820 -237
  507. package/dist/storage/packs-memory.d.mts +25 -0
  508. package/dist/storage/packs-memory.mjs +49 -0
  509. package/dist/storage/packs.d.mts +7 -5
  510. package/dist/storage/packs.mjs +554 -213
  511. package/dist/storage/placed-reads.mjs +205 -0
  512. package/dist/storage/prune-keep.mjs +164 -0
  513. package/dist/storage/prune-walk.mjs +578 -0
  514. package/dist/storage/prune.mjs +739 -332
  515. package/dist/storage/push-allotment.mjs +3 -3
  516. package/dist/storage/push-uploads.mjs +31 -26
  517. package/dist/storage/pushed-commits.mjs +8 -9
  518. package/dist/storage/quarantine.d.mts +10 -0
  519. package/dist/storage/quarantine.mjs +71 -29
  520. package/dist/storage/range-cache.mjs +71 -0
  521. package/dist/storage/raw-ids.mjs +20 -1
  522. package/dist/storage/ready.d.mts +4 -2
  523. package/dist/storage/ready.mjs +109 -48
  524. package/dist/storage/receive-admission.mjs +67 -0
  525. package/dist/storage/receive-bounds.d.mts +1 -0
  526. package/dist/storage/receive-bounds.mjs +202 -0
  527. package/dist/storage/receive-files.mjs +248 -0
  528. package/dist/storage/receive-links.mjs +281 -244
  529. package/dist/storage/receive-state.d.mts +9 -0
  530. package/dist/storage/receive-state.mjs +150 -0
  531. package/dist/storage/receive-steps.mjs +344 -0
  532. package/dist/storage/receive-sweep.mjs +160 -0
  533. package/dist/storage/receive-table.d.mts +3 -0
  534. package/dist/storage/receive-table.mjs +197 -0
  535. package/dist/storage/repack-backlog.mjs +70 -0
  536. package/dist/storage/repack-contained.mjs +269 -0
  537. package/dist/storage/repack-job.d.mts +3 -0
  538. package/dist/storage/repack-job.mjs +27 -17
  539. package/dist/storage/repack.d.mts +4 -4
  540. package/dist/storage/repack.mjs +156 -77
  541. package/dist/storage/roots.mjs +23 -7
  542. package/dist/storage/rows.d.mts +4 -2
  543. package/dist/storage/rows.mjs +81 -9
  544. package/dist/storage/runs.d.mts +8 -0
  545. package/dist/storage/runs.mjs +731 -0
  546. package/dist/storage/send-list.d.mts +2 -1
  547. package/dist/storage/send-list.mjs +261 -76
  548. package/dist/storage/shallow.d.mts +3 -2
  549. package/dist/storage/shallow.mjs +7 -7
  550. package/dist/storage/single-flight.mjs +47 -0
  551. package/dist/storage/stream-whole.mjs +121 -54
  552. package/dist/storage/swap-walk.mjs +188 -0
  553. package/dist/storage/unpack.mjs +52 -23
  554. package/dist/storage/visible.mjs +58 -39
  555. package/dist/storage/walk.d.mts +2 -0
  556. package/dist/storage/walk.mjs +20 -7
  557. package/dist/storage/wants.mjs +185 -33
  558. package/dist/storage/written-bases.mjs +172 -0
  559. package/dist/store/call-count.d.mts +69 -4
  560. package/dist/store/call-count.mjs +193 -51
  561. package/dist/store/catalogue.d.mts +17 -3
  562. package/dist/store/catalogue.mjs +135 -48
  563. package/dist/store/crossing.mjs +2 -4
  564. package/dist/store/cursor-seal.d.mts +12 -1
  565. package/dist/store/cursor-seal.mjs +7 -6
  566. package/dist/store/errors.d.mts +2 -2
  567. package/dist/store/errors.mjs +112 -24
  568. package/dist/store/git-store.mjs +21 -2
  569. package/dist/store/job-try.mjs +26 -0
  570. package/dist/store/list-job.mjs +23 -17
  571. package/dist/store/outbox.d.mts +15 -5
  572. package/dist/store/outbox.mjs +143 -39
  573. package/dist/store/promises.d.mts +8 -2
  574. package/dist/store/promises.mjs +129 -85
  575. package/dist/store/queue-jobs.mjs +34 -13
  576. package/dist/store/records.d.mts +64 -1
  577. package/dist/store/records.mjs +101 -32
  578. package/dist/store/ref-rows.d.mts +18 -2
  579. package/dist/store/ref-rows.mjs +62 -5
  580. package/dist/store/repo-record.mjs +11 -9
  581. package/dist/store/reservations.mjs +9 -8
  582. package/dist/store/scopes.mjs +13 -11
  583. package/dist/store/settle.mjs +1 -1
  584. package/dist/store/topic-jobs.mjs +4 -4
  585. package/dist/sync/bound.d.mts +5 -3
  586. package/dist/sync/bound.mjs +32 -3
  587. package/dist/sync/github.mjs +7 -7
  588. package/dist/sync/import.d.mts +2 -0
  589. package/dist/sync/import.mjs +46 -50
  590. package/dist/sync/jobs.mjs +15 -23
  591. package/dist/sync/mirror.d.mts +6 -2
  592. package/dist/sync/mirror.mjs +122 -45
  593. package/dist/sync/publish.d.mts +1 -0
  594. package/dist/sync/publish.mjs +22 -19
  595. package/dist/sync/step.mjs +443 -71
  596. package/dist/sync/tries.mjs +50 -32
  597. package/dist/sync.d.mts +3 -3
  598. package/dist/sync.mjs +2 -2
  599. package/dist/topics/advance.mjs +103 -86
  600. package/dist/topics/calls.mjs +97 -67
  601. package/dist/topics/directory.mjs +31 -11
  602. package/dist/topics/host.d.mts +0 -1
  603. package/dist/topics/host.mjs +2 -12
  604. package/dist/topics/members.mjs +30 -24
  605. package/dist/topics/rows.mjs +10 -9
  606. package/dist/topics/topic.mjs +20 -9
  607. package/package.json +8 -15
  608. package/dist/auth/authorize.d.mts +0 -5
  609. package/dist/contracts/objects.mjs +0 -54
  610. package/dist/core/events/stream.d.mts +0 -19
  611. package/dist/core/rules/define.d.mts +0 -5
  612. package/dist/core/rules/define.mjs +0 -13
  613. package/dist/core/rules/fetch.d.mts +0 -5
  614. package/dist/core/sight.mjs +0 -99
  615. package/dist/engine/engine.d.mts +0 -25
  616. package/dist/engine/engine.mjs +0 -49
  617. package/dist/engine/xdiff/NOTICE.md +0 -63
  618. package/dist/engine/xdiff/compiled.d.mts +0 -7
  619. package/dist/engine/xdiff/compiled.mjs +0 -9
  620. package/dist/engine/xdiff/embedded.mjs +0 -4
  621. package/dist/engine/xdiff/node.d.mts +0 -7
  622. package/dist/engine/xdiff/node.mjs +0 -10
  623. package/dist/engine/xdiff/upstream/LGPL-2.1 +0 -511
  624. package/dist/engine/xdiff/xdiff.wasm +0 -0
  625. package/dist/engine.d.mts +0 -3
  626. package/dist/engine.mjs +0 -3
  627. package/dist/lfs/repo.mjs +0 -42
  628. package/dist/storage/distinct-ids.mjs +0 -39
  629. package/dist/storage/held-memo.mjs +0 -188
  630. package/dist/storage/index-remap.d.mts +0 -8
  631. package/dist/sync/records.mjs +0 -73
@@ -1,7 +1,10 @@
1
- import { gitError } from "../store/errors.mjs";
1
+ import { gitError } from "../contracts/result.mjs";
2
+ import { RequestHolding } from "../store/call-count.mjs";
2
3
  import { pushFloorsOf, readerFloors, readerMost } from "./budget.mjs";
3
4
  import { packIndexerLimits } from "./pack-reads.mjs";
4
5
  import { ReceivedPointers, lfsPointersMost, pageEntries } from "./lfs-pointers.mjs";
6
+ import { receiveRoomAdmitted } from "./receive-admission.mjs";
7
+ import { ReceiveRoom } from "./runs.mjs";
5
8
  import { runnerIn } from "../store/crossing.mjs";
6
9
  import * as Effect from "effect/Effect";
7
10
  import * as Option from "effect/Option";
@@ -16,7 +19,7 @@ const headStuckMs = pushWaitMs / 2;
16
19
  */
17
20
  const growWaitMs = 5e3;
18
21
  /** The refusal a push gets when no room came within its wait, or its grow's. */
19
- const pushBusy = gitError("UNAVAILABLE", "The server is busy with other pushes", {
22
+ const pushBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "The server is busy with other pushes", {
20
23
  hint: "Push again in a minute",
21
24
  context: { reason: "busy" }
22
25
  });
@@ -24,23 +27,59 @@ const pushBusy = gitError("UNAVAILABLE", "The server is busy with other pushes",
24
27
  * The refusal a push gets when what it takes at once is past the whole budget, which no wait
25
28
  * would make room for.
26
29
  */
27
- const pushTooLarge = gitError("RESOURCE_EXHAUSTED", "This push takes more at once than fits in the server's memory", {
30
+ const pushTooLarge = /* @__PURE__ */ gitError("RESOURCE_EXHAUSTED", "This push takes more at once than fits in the server's memory", {
28
31
  hint: "Push fewer commits at a time",
29
32
  context: { reason: "too-large" }
30
33
  });
31
34
  /**
35
+ * A push's refusal when one entry needs more outside the indexer's cache than its isolate could
36
+ * ever give it beside the push: the entry's `need` and the `left` it could have beside the push's
37
+ * other objects, so a caller sees that a push of fewer objects leaves that entry more room.
38
+ */
39
+ const pushEntryTooLarge = (objects) => (need, left) => {
40
+ const others = objects - 1;
41
+ const beside = others > 0 ? ` beside this push's other ${others.toLocaleString("en-US")} ${others === 1 ? "object" : "objects"}` : "";
42
+ return gitError("RESOURCE_EXHAUSTED", `An object in this push needs ${need.toLocaleString("en-US")} bytes of the server's memory at once, and ${Math.max(0, left).toLocaleString("en-US")} are left${beside}`, {
43
+ hint: "Push fewer commits at a time",
44
+ context: { reason: "too-large" }
45
+ });
46
+ };
47
+ /**
48
+ * A push's refusal when the repo's pack indexes its reads charge, beside what it holds of its
49
+ * own, pass what the server's memory could ever give it: the bytes of each, and that `most`, so a
50
+ * caller sees the repo's part, which a push of fewer commits leaves as it is.
51
+ */
52
+ const pushIndexTooLarge = (index, own, most) => {
53
+ const bytes = (n) => n.toLocaleString("en-US");
54
+ return gitError("RESOURCE_EXHAUSTED", `This push needs ${bytes(index + own)} bytes of the server's memory at once, past the ${bytes(most)} it could have: ${bytes(index)} for the repo's pack indexes it reads, beside ${bytes(own)} of its own`, {
55
+ hint: "The repo's pack indexes count toward it, and push fewer commits at a time to leave them more",
56
+ context: {
57
+ reason: "too-large",
58
+ indexBytes: index,
59
+ pushBytes: own,
60
+ most
61
+ }
62
+ });
63
+ };
64
+ /**
32
65
  * A fetch's refusal when no room came within its wait, for its plan or its objects: Git shows a
33
66
  * fetch's message alone, so the message says what to do.
34
67
  */
35
- const fetchBusy = gitError("UNAVAILABLE", "The server is busy; fetch again in a minute", {
68
+ const fetchBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "The server is busy; fetch again in a minute", {
36
69
  hint: "Try again in a minute",
37
70
  context: { reason: "busy" }
38
71
  });
39
72
  /** A reader's, a walk's or a diff's refusal when no room came within its wait. */
40
- const readBusy = gitError("UNAVAILABLE", "The server is busy: try again in a minute", {
73
+ const readBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "The server is busy: try again in a minute", {
41
74
  hint: "Try again in a minute",
42
75
  context: { reason: "busy" }
43
76
  });
77
+ /**
78
+ * Maintenance's refusal when what one of its steps holds at once is past all it may hold, the
79
+ * budget less the read reserve, which no wait would make room for. Past only what's free while others hold the rest, the step waits
80
+ * as `readBusy` and comes back later (Q879's split, as Q888 asks of maintenance).
81
+ */
82
+ const upkeepTooLarge = /* @__PURE__ */ gitError("RESOURCE_EXHAUSTED", "This repack step takes more at once than fits in the server's memory", { context: { reason: "too-large" } });
44
83
  /** A cache's room within an operation's allotment, or the server's for its index cache. */
45
84
  var Room = class {
46
85
  #budget;
@@ -51,10 +90,19 @@ var Room = class {
51
90
  /** What a shrink asks the cache to evict to. */
52
91
  #evict = () => void 0;
53
92
  closed = false;
54
- constructor(budget, floor, most) {
93
+ /** The allotment it's within: none for the index cache's. */
94
+ owner;
95
+ /** Whether `growWithin` waits, refused with its allotment's busy. */
96
+ #waits;
97
+ /** Whether it's an index cache's room, which shrinks first and takes only what's free. */
98
+ index;
99
+ constructor(budget, floor, most, owner, waits = false, index = false) {
55
100
  this.#budget = budget;
56
101
  this.floor = floor;
57
102
  this.most = Math.max(floor, most);
103
+ this.owner = owner;
104
+ this.#waits = waits;
105
+ this.index = index;
58
106
  }
59
107
  get bytes() {
60
108
  return this.floor + this.extra;
@@ -63,6 +111,17 @@ var Room = class {
63
111
  if (this.closed || this.bytes + bytes > this.most) return false;
64
112
  return this.#budget.growRoom(this, bytes);
65
113
  }
114
+ /**
115
+ * `grow`, waiting for the room when it's refused, for a block its cache let go and reads again:
116
+ * `true` once grown, or its allotment's busy past `growWaitMs`. `false` at once for a room that
117
+ * never waits, is closed or would pass its most, or whose own allotment, rooms and all, leaves
118
+ * too little of the budget for it: no other operation's end would make that room.
119
+ */
120
+ growWithin(bytes) {
121
+ const owner = this.owner;
122
+ if (owner === void 0 || !this.#waits || this.closed || this.bytes + bytes > this.most || owner.held + bytes > this.#budget.total) return Effect.succeed(false);
123
+ return this.#budget.growWithin(this, bytes, owner);
124
+ }
66
125
  watch(evict) {
67
126
  this.#evict = evict;
68
127
  }
@@ -71,6 +130,7 @@ var Room = class {
71
130
  const freed = this.extra;
72
131
  if (freed === 0) return 0;
73
132
  this.extra = 0;
133
+ if (this.index) this.#budget.unwatchIndex(this);
74
134
  this.#evict(this.floor);
75
135
  return freed;
76
136
  }
@@ -86,18 +146,21 @@ var MemoryAllotment = class MemoryAllotment {
86
146
  push;
87
147
  /** Its operation's refusal when a grow finds no room within its wait. */
88
148
  busy;
149
+ /** The request whose `allot` this is: its grows let that request's kept reaches go first. */
150
+ owner;
89
151
  #bytes;
90
152
  #admitted;
91
153
  #rooms = /* @__PURE__ */ new Set();
92
154
  #released = false;
93
- constructor(budget, bytes, push, busy, admitted = push ? bytes : 0) {
155
+ constructor(budget, bytes, push, busy, admitted = push ? bytes : 0, owner) {
94
156
  this.#budget = budget;
95
157
  this.#bytes = bytes;
96
158
  this.#admitted = admitted;
97
159
  this.push = push;
98
160
  this.busy = busy;
161
+ this.owner = owner;
99
162
  }
100
- /** What a push's admission counts of it: its must-have and floors, or what it kept of them. */
163
+ /** What a push's admission counts of it: its must-have, floors and grows, or what it kept. */
101
164
  get admitted() {
102
165
  return this.#admitted;
103
166
  }
@@ -105,13 +168,27 @@ var MemoryAllotment = class MemoryAllotment {
105
168
  get bytes() {
106
169
  return this.#bytes;
107
170
  }
171
+ /** What it holds of the budget: its bytes and its rooms' growth. */
172
+ get held() {
173
+ let held = this.#bytes;
174
+ for (const room of this.#rooms) held += room.extra;
175
+ return held;
176
+ }
108
177
  get released() {
109
178
  return this.#released;
110
179
  }
111
180
  /**
181
+ * What it can still grow by, were nothing else allotted: its budget's total less what it holds,
182
+ * a push's less the reserve too. A grow past it is refused at once, with its `tooLarge` when
183
+ * given, since no wait makes room.
184
+ */
185
+ get growable() {
186
+ return this.#budget.mostOf(this.push) - this.#bytes;
187
+ }
188
+ /**
112
189
  * Grows it by `bytes`, at once when they fit once caches shrink, or within `growWaitMs`; then
113
- * its `busy` refuses it. Bytes that couldn't fit the budget alone are refused at once, with
114
- * `tooLarge` when given.
190
+ * its `busy` refuses it. Bytes that couldn't fit the budget alone, a push's beside the reserve,
191
+ * are refused at once, with `tooLarge` when given.
115
192
  */
116
193
  grow(bytes, tooLarge) {
117
194
  return this.#budget.grow(this, bytes, this.busy, tooLarge);
@@ -120,12 +197,15 @@ var MemoryAllotment = class MemoryAllotment {
120
197
  shrink(bytes) {
121
198
  if (this.#released) return;
122
199
  const given = Math.min(bytes, this.#bytes);
200
+ const admitted = this.push ? Math.min(given, this.#admitted) : 0;
123
201
  this.#bytes -= given;
124
- this.#budget.returned(given, 0);
202
+ this.#admitted -= admitted;
203
+ this.#budget.returned(given, admitted);
125
204
  }
126
- /** Adds `bytes` granted by the budget. */
205
+ /** Adds `bytes` granted by the budget: a push's are admitted, as its grows count with pushes. */
127
206
  added(bytes) {
128
207
  this.#bytes += bytes;
208
+ if (this.push) this.#admitted += bytes;
129
209
  }
130
210
  /**
131
211
  * Grows it by `bytes` only when they fit at once, with no wait: whether they did. A walk's
@@ -149,10 +229,12 @@ var MemoryAllotment = class MemoryAllotment {
149
229
  }
150
230
  /**
151
231
  * A cache's room: `floor` within this allotment, already counted in it, and up to `most` when the
152
- * budget has room to spare. It shrinks to its floor when another allotment needs the room.
232
+ * budget has room to spare. It shrinks to its floor when another allotment needs the room. With
233
+ * `waits`, its `growWithin` waits for room, refused with this allotment's busy, for a caller that
234
+ * retries that busy.
153
235
  */
154
- room(floor, most) {
155
- const room = new Room(this.#budget, floor, most);
236
+ room(floor, most, waits = false) {
237
+ const room = new Room(this.#budget, floor, most, this, waits);
156
238
  if (this.#released) room.closed = true;
157
239
  else {
158
240
  this.#rooms.add(room);
@@ -160,6 +242,18 @@ var MemoryAllotment = class MemoryAllotment {
160
242
  }
161
243
  return room;
162
244
  }
245
+ /**
246
+ * Ends one of its rooms before it ends: what the room grew past its floor goes back, and its
247
+ * floor stays counted in this allotment until a shrink gives it back.
248
+ */
249
+ endRoom(room) {
250
+ if (!(room instanceof Room) || !this.#rooms.delete(room)) return;
251
+ const extra = room.extra;
252
+ room.extra = 0;
253
+ room.closed = true;
254
+ this.#budget.unwatchRoom(room);
255
+ this.#budget.returned(extra, 0);
256
+ }
163
257
  /** Ends it with its bytes handed to another allotment, as a grow's wait does: nothing goes back. */
164
258
  adopted() {
165
259
  this.#released = true;
@@ -184,10 +278,11 @@ var MemoryAllotment = class MemoryAllotment {
184
278
  * from, so together they never take more than `total`. A push is admitted with its must-have and
185
279
  * floors when they fit beside every admitted push within `total` less `reserve`, first-fit and
186
280
  * oldest first, and none passes a push that has waited `headStuckMs`; it waits `pushWaitMs` at
187
- * most. A fetch, a walk or a diff is allotted at once, ahead of waiting pushes but never past a
188
- * stuck one, or waits `growWaitMs`. Caches are allotted rooms between a floor and a most, and each
189
- * shrinks to its floor, the index cache's first, whenever an allotment asks for more than is free.
190
- * It runs on one thread, so each step is synchronous: the only awaits are the waits.
281
+ * most. Its grows fit there too, and count with it. A fetch, a walk or a diff is allotted at once,
282
+ * ahead of waiting pushes but never past a stuck one, or waits `growWaitMs`. Caches are allotted
283
+ * rooms between a floor and a most, and each shrinks to its floor, the index cache's first,
284
+ * whenever an allotment asks for more than is free. It runs on one thread, so each step is
285
+ * synchronous: the only awaits are the waits.
191
286
  */
192
287
  var MemoryBudget = class {
193
288
  total;
@@ -195,12 +290,24 @@ var MemoryBudget = class {
195
290
  #allotted = 0;
196
291
  #admitted = 0;
197
292
  #rooms = /* @__PURE__ */ new Set();
293
+ /** The reaches requests keep, oldest first. */
294
+ #kept = /* @__PURE__ */ new Set();
198
295
  #pushes = [];
199
296
  #reads = [];
297
+ /**
298
+ * Upkeep's allotments, marked in `#allotOf`: they count with pushes, so `push` can't tell them
299
+ * apart. Their grows yield to pushes', and a refused grow's log line names them.
300
+ */
301
+ #upkeeps = /* @__PURE__ */ new WeakSet();
200
302
  /** Whether a wake runs, and whether one was asked for inside it. */
201
303
  #waking = false;
202
304
  #wakeAgain = false;
203
- #index;
305
+ /**
306
+ * The index caches' rooms holding bytes, oldest first: one for each `open()` this budget serves.
307
+ * A room joins when it first grows and leaves when it shrinks, so a server dropped with its
308
+ * cache empty leaves nothing here.
309
+ */
310
+ #indexes = /* @__PURE__ */ new Set();
204
311
  /** The clock of the last operation that asked, so a release's wake reads the same time. */
205
312
  #now = Date.now;
206
313
  constructor(total, reserve) {
@@ -214,6 +321,26 @@ var MemoryBudget = class {
214
321
  return effect();
215
322
  });
216
323
  }
324
+ /**
325
+ * `reach` kept until `unkeep`, or until `#fit` lets it go: `false`, with nothing kept, where its
326
+ * owner's kept reaches, this one's bytes now included, would pass a quarter of the budget. So a
327
+ * request keeps no new reach once its kept reaches pass a quarter, and its kept reaches can grow
328
+ * past that by their answers, all of which give way.
329
+ */
330
+ keep(reach) {
331
+ let owned = reach.allotment.bytes;
332
+ for (const kept of this.#kept) if (kept.owner === reach.owner) owned += kept.allotment.bytes;
333
+ if (owned > this.total / 4) return false;
334
+ this.#kept.add(reach);
335
+ return true;
336
+ }
337
+ unkeep(reach) {
338
+ this.#kept.delete(reach);
339
+ }
340
+ /** A kept reach no ask uses now: what waits may fit by letting it go. */
341
+ reachIdle() {
342
+ this.#wake();
343
+ }
217
344
  /** Every byte allotted, rooms' growth included. */
218
345
  allotted() {
219
346
  return this.#allotted;
@@ -222,12 +349,12 @@ var MemoryBudget = class {
222
349
  admittedBytes() {
223
350
  return this.#admitted;
224
351
  }
225
- /** The index cache's room: the server's own, with no floor, which shrinks first. */
352
+ /**
353
+ * An index cache's room: a server's own, with no floor, which shrinks first. Each `open()` on
354
+ * one budget has its own, and one never takes another's bytes.
355
+ */
226
356
  indexRoom() {
227
- const room = new Room(this, 0, this.total);
228
- this.#index = room;
229
- this.#rooms.add(room);
230
- return room;
357
+ return new Room(this, 0, this.total, void 0, false, true);
231
358
  }
232
359
  watchRoom(room) {
233
360
  this.#rooms.add(room);
@@ -235,12 +362,95 @@ var MemoryBudget = class {
235
362
  unwatchRoom(room) {
236
363
  this.#rooms.delete(room);
237
364
  }
238
- /** A room's growth, granted only from what's free: a cache never shrinks another to grow. */
365
+ /** An index room shrunk to nothing. */
366
+ unwatchIndex(room) {
367
+ this.#indexes.delete(room);
368
+ this.#rooms.delete(room);
369
+ }
370
+ /**
371
+ * A room's growth, from these in order: what's free; then the index caches', which no operation
372
+ * uses, let go only when that makes it fit. Never from a live operation's room or a kept reach:
373
+ * a request's kept reach is rebuilt by its next ask, and an allotment's grow, which rooms and
374
+ * kept reaches yield to, would take the room back, so each would evict what the other just
375
+ * read, back and forth. An index cache's own growth takes only what's free. So a warm isolate's
376
+ * leftover index cache doesn't keep a push's blocks at their floor, reading each block again
377
+ * (#1190). Refused while an operation waits, so the bytes freed go to it. A room refused its
378
+ * growth evicts to its floor.
379
+ */
239
380
  growRoom(room, bytes) {
240
- if (this.#pushes.length > 0 || this.#reads.length > 0 || this.#allotted + bytes > this.total) return false;
381
+ if (this.#pushes.length > 0 || this.#reads.length > 0 || this.#roomFree(room, false) < bytes) return false;
382
+ this.#roomGrows(room, bytes);
383
+ return true;
384
+ }
385
+ /**
386
+ * What `room` can grow by: what's free and, but for an index room, the index caches', and with `parked`, a room wait's,
387
+ * the growth of the rooms of operations parked on a grow too.
388
+ */
389
+ #roomFree(room, parked) {
390
+ let free = this.total - this.#allotted;
391
+ if (!room.index) for (const index of this.#indexes) free += index.extra;
392
+ if (parked) for (const each of this.#parked(room)) free += each.extra;
393
+ return free;
394
+ }
395
+ /**
396
+ * The rooms of operations parked on their allotment's grow, but `room`'s own: a parked operation
397
+ * reads through none of its caches till its grow lands, and then reads again what they let go,
398
+ * as after any shrink (#1197).
399
+ */
400
+ *#parked(room) {
401
+ const parked = /* @__PURE__ */ new Set();
402
+ for (const waiter of this.#reads) if (!("room" in waiter) && waiter.grower !== void 0) parked.add(waiter.grower);
403
+ for (const each of this.#rooms) if (each.owner !== void 0 && each.owner !== room.owner && parked.has(each.owner)) yield each;
404
+ }
405
+ /**
406
+ * `room` grown by `bytes` that `#roomFree` holds: the index caches let go first, oldest first,
407
+ * then parked operations' rooms, one at a time, only while they still need it. An index room
408
+ * takes only what's free.
409
+ */
410
+ #roomGrows(room, bytes) {
411
+ for (const index of room.index ? [] : [...this.#indexes]) {
412
+ if (this.#allotted + bytes <= this.total) break;
413
+ this.#allotted -= index.shrink();
414
+ }
415
+ for (const each of this.#parked(room)) {
416
+ if (this.#allotted + bytes <= this.total) break;
417
+ this.#allotted -= each.shrink();
418
+ }
419
+ if (room.index && bytes > 0) {
420
+ this.#indexes.add(room);
421
+ this.#rooms.add(room);
422
+ }
241
423
  room.extra += bytes;
242
424
  this.#allotted += bytes;
243
- return true;
425
+ }
426
+ /**
427
+ * `Room.growWithin`: `room` grown by `bytes` at once when they fit and no push is stuck, though
428
+ * others wait; else a wait in the reads' queue, in arrival order, `growWaitMs` at most, then
429
+ * `owner`'s busy. It takes what `growRoom` may, and the rooms of operations parked on their allotment's
430
+ * grow, never a running operation's room or a kept reach, and holds nothing while it waits. So
431
+ * an operation that holds what the wait needs finishes as it would with no wait: its allotment's
432
+ * grows don't queue behind it, its own room's wait is granted whenever its bytes fit, and once
433
+ * it parks on a grow that the waiter's admission holds back, its rooms let the waiter land and
434
+ * give that grow its room. A cache that thrashes its floor beside a running operation waits for
435
+ * it to end, and is refused busy rather than reading the same blocks until its calls run out
436
+ * (#1197).
437
+ */
438
+ growWithin(room, bytes, owner) {
439
+ return this.#timed(() => {
440
+ if (this.#stuck(this.#now()) === void 0 && this.#roomFree(room, true) >= bytes) {
441
+ this.#roomGrows(room, bytes);
442
+ return Effect.succeed(true);
443
+ }
444
+ const waited = this.#queued(this.#reads, growWaitMs, (granted) => ({ waiter: {
445
+ room,
446
+ bytes,
447
+ granted
448
+ } }));
449
+ return Effect.flatMap(waited, Option.match({
450
+ onNone: () => Effect.fail(owner.busy),
451
+ onSome: Effect.succeed
452
+ }));
453
+ });
244
454
  }
245
455
  /** Bytes an allotment gave back, and the admitted bytes of a push that ended, then the queue's wake. */
246
456
  returned(bytes, admitted) {
@@ -248,35 +458,79 @@ var MemoryBudget = class {
248
458
  this.#admitted -= admitted;
249
459
  this.#wake();
250
460
  }
251
- /** Frees room for `bytes` by shrinking caches to their floors, the index cache's first. */
252
- #fit(bytes) {
461
+ /**
462
+ * Frees room for `bytes` by shrinking caches to their floors, the index caches' first, then by
463
+ * letting go of kept reaches no ask uses, `asker`'s own first, then the oldest.
464
+ */
465
+ #fit(bytes, asker) {
253
466
  if (this.#allotted + bytes <= this.total) return true;
254
- const order = [...this.#rooms].sort((a, b) => Number(b === this.#index) - Number(a === this.#index));
467
+ const order = [...this.#rooms].sort((a, b) => Number(b.index) - Number(a.index));
255
468
  for (const room of order) {
256
469
  this.#allotted -= room.shrink();
257
470
  if (this.#allotted + bytes <= this.total) return true;
258
471
  }
472
+ const kept = [...this.#kept].sort((a, b) => Number(b.owner === asker) - Number(a.owner === asker));
473
+ for (const reach of kept) {
474
+ if (!reach.idle()) continue;
475
+ this.#kept.delete(reach);
476
+ reach.dropped();
477
+ reach.allotment.release();
478
+ if (this.#allotted + bytes <= this.total) return true;
479
+ }
259
480
  return false;
260
481
  }
482
+ /**
483
+ * The queue's one order between pushes and upkeep (#1300): upkeep's `bytes`, an ask or a grow,
484
+ * yield while the pushes' grows that wait wouldn't all fit beside them, whichever asked first.
485
+ * So a push's grow is let in first, and upkeep's ask, waiting or new, never takes its room.
486
+ */
487
+ #yieldsToPushes(bytes, upkeep) {
488
+ if (!upkeep) return false;
489
+ let waiting = 0;
490
+ for (const waiter of this.#reads) if (!("room" in waiter) && waiter.grower?.push === true && !this.#upkeeps.has(waiter.grower)) waiting += waiter.bytes;
491
+ return waiting > 0 && !this.#fits(bytes + waiting, true);
492
+ }
493
+ /** Whether `waiter` is upkeep's: an ask, which only upkeep makes counted with pushes, or a grow. */
494
+ #upkeepWaits(waiter) {
495
+ if ("room" in waiter || !waiter.push) return false;
496
+ return waiter.grower === void 0 || this.#upkeeps.has(waiter.grower);
497
+ }
261
498
  /** The waiting push at the head when it has waited `headStuckMs`: nothing passes it. */
262
499
  #stuck(now) {
263
500
  const head = this.#pushes[0];
264
501
  return head !== void 0 && now - head.since >= 3e4 ? head : void 0;
265
502
  }
503
+ /** The most an allotment may hold: the whole budget, or a push's, all of it but the reserve. */
504
+ mostOf(push) {
505
+ return push ? this.total - this.reserve : this.total;
506
+ }
266
507
  /** Whether a push's `bytes` fit beside the admitted pushes, the reserve left. */
267
- #admits(bytes) {
268
- return this.#admitted + bytes <= this.total - this.reserve && this.#fit(bytes);
508
+ #admits(bytes, asker) {
509
+ return this.#admitted + bytes <= this.total - this.reserve && this.#fit(bytes, asker);
269
510
  }
270
- #grant(bytes, push, busy = push ? pushBusy : readBusy) {
271
- const allotment = new MemoryAllotment(this, bytes, push, busy);
511
+ /** Whether `bytes` fit now: a push's beside the admitted pushes, a read's once caches shrink. */
512
+ #fits(bytes, push, asker) {
513
+ return push ? this.#admits(bytes, asker) : this.#fit(bytes, asker);
514
+ }
515
+ #grant(bytes, push, busy = push ? pushBusy : readBusy, owner) {
516
+ const allotment = new MemoryAllotment(this, bytes, push, busy, void 0, owner);
272
517
  this.#allotted += bytes;
273
518
  if (push) this.#admitted += bytes;
519
+ this.#wakeRooms();
274
520
  return allotment;
275
521
  }
276
522
  /**
523
+ * Wakes the queue when a room waits: a grant that shrank the caches to fit, each to its floor,
524
+ * may leave more free than it took, which only a room's wait, never letting a cache go, needed.
525
+ */
526
+ #wakeRooms() {
527
+ if (this.#reads.some((waiter) => "room" in waiter)) this.#wake();
528
+ }
529
+ /**
277
530
  * The next waiter the queue's one rule lets in, or none: a stuck head when it fits, and nothing
278
- * past it when it doesn't; else the oldest read that fits; else the oldest push that fits. The
279
- * pushes wait in arrival order, so once the head isn't stuck none behind it is.
531
+ * past it when it doesn't; else the oldest read or grow that fits, a push's grow beside the
532
+ * admitted pushes, upkeep only once it yields to no push's grow; else the oldest push that fits.
533
+ * The pushes wait in arrival order, so once the head isn't stuck none behind it is.
280
534
  */
281
535
  #next(now) {
282
536
  const stuck = this.#stuck(now);
@@ -285,11 +539,11 @@ var MemoryBudget = class {
285
539
  waiter: stuck,
286
540
  push: true
287
541
  } : void 0;
288
- const read = this.#reads.find((waiter) => this.#fit(waiter.bytes));
542
+ const read = this.#reads.find((waiter) => "room" in waiter ? waiter.room.closed || this.#roomFree(waiter.room, true) >= waiter.bytes : this.#fits(waiter.bytes, waiter.push, waiter.asker) && !this.#yieldsToPushes(waiter.bytes, this.#upkeepWaits(waiter)));
289
543
  if (read !== void 0) return {
290
544
  queue: this.#reads,
291
545
  waiter: read,
292
- push: false
546
+ push: "room" in read ? false : read.push
293
547
  };
294
548
  const push = this.#pushes.find((waiter) => this.#admits(waiter.bytes));
295
549
  if (push !== void 0) return {
@@ -320,7 +574,11 @@ var MemoryBudget = class {
320
574
  for (let next = this.#next(now); next !== void 0; next = this.#next(now)) {
321
575
  const { queue, waiter, push } = next;
322
576
  queue.splice(queue.indexOf(waiter), 1);
323
- waiter.admitted(this.#grant(waiter.bytes, push, waiter.busy));
577
+ if ("room" in waiter) {
578
+ const open = !waiter.room.closed;
579
+ if (open) this.#roomGrows(waiter.room, waiter.bytes);
580
+ waiter.granted(open);
581
+ } else waiter.admitted(this.#grant(waiter.bytes, push, waiter.busy, waiter.asker));
324
582
  }
325
583
  } while (this.#wakeAgain);
326
584
  } finally {
@@ -328,39 +586,64 @@ var MemoryBudget = class {
328
586
  }
329
587
  }
330
588
  /**
331
- * Waits in `queue` for an allotment of `bytes`, `ms` at most; `None` past it. A wait interrupted,
589
+ * Waits in `queue` as the waiter `enter` makes, `ms` at most; `None` past it. A wait interrupted,
332
590
  * by its timeout too, leaves the queue and wakes it, since the waiter may have held up others,
333
- * and gives back an allotment granted it that it never took.
591
+ * and runs its `left`.
334
592
  */
335
- #wait(queue, bytes, ms, busy) {
593
+ #queued(queue, ms, enter) {
336
594
  return Effect.callback((resume) => {
337
- let granted;
338
- const waiter = {
339
- bytes,
340
- busy,
341
- since: this.#now(),
342
- admitted: (allotment) => {
343
- granted = allotment;
344
- resume(Effect.succeed(allotment));
345
- }
346
- };
595
+ const { waiter, left } = enter((granted) => resume(Effect.succeed(granted)));
347
596
  queue.push(waiter);
597
+ if (!("room" in waiter) && waiter.grower !== void 0) this.#wakeRooms();
348
598
  return Effect.sync(() => {
349
599
  const at = queue.indexOf(waiter);
350
600
  if (at >= 0) {
351
601
  queue.splice(at, 1);
352
602
  this.#wake();
353
603
  }
354
- granted?.release();
604
+ left?.();
355
605
  });
356
606
  }).pipe(Effect.timeoutOption(ms));
357
607
  }
358
608
  /**
359
- * An allotment released when the scope ends, on every exit. Its wait stays interruptible; once it
360
- * has the allotment, its finalizer is added before anything can interrupt it.
609
+ * Waits in `queue` for an allotment of `bytes`, `ms` at most; `None` past it. A wait interrupted,
610
+ * by its timeout too, gives back an allotment granted it that it never took.
611
+ */
612
+ #wait(queue, push, bytes, ms, busy, own, asker, grower) {
613
+ return this.#queued(queue, ms, (resume) => {
614
+ let granted;
615
+ return {
616
+ waiter: {
617
+ bytes,
618
+ push,
619
+ busy,
620
+ asker,
621
+ grower,
622
+ since: this.#now(),
623
+ admitted: (allotment) => {
624
+ granted = allotment;
625
+ own(allotment);
626
+ resume(allotment);
627
+ }
628
+ },
629
+ left: () => granted?.release()
630
+ };
631
+ });
632
+ }
633
+ /**
634
+ * An allotment released when the scope ends, on every exit. Its finalizer is added first, and
635
+ * `allotment` hands it what it grants in the step that grants it, by `own`, so its wait stays
636
+ * interruptible and no interrupt, after a grant or after a wait, leaves an allotment unowned.
361
637
  */
362
638
  #scoped(allotment) {
363
- return Effect.uninterruptibleMask((restore) => restore(this.#timed(allotment)).pipe(Effect.tap((taken) => Effect.addFinalizer(() => Effect.sync(() => taken.release())))));
639
+ return Effect.uninterruptibleMask((restore) => {
640
+ let taken;
641
+ const own = (granted) => {
642
+ taken = granted;
643
+ return granted;
644
+ };
645
+ return Effect.andThen(Effect.addFinalizer(() => Effect.sync(() => taken?.release())), restore(this.#timed(() => allotment(own))));
646
+ });
364
647
  }
365
648
  /**
366
649
  * A push's admission with `bytes`, its must-have and floors: at once when they fit beside the
@@ -369,10 +652,10 @@ var MemoryBudget = class {
369
652
  * no wait makes room for, `pushTooLarge` at once. Released when the scope ends.
370
653
  */
371
654
  admit(bytes) {
372
- return this.#scoped(() => {
655
+ return this.#scoped((own) => {
373
656
  if (bytes > this.total - this.reserve) return Effect.fail(pushTooLarge);
374
- if (this.#stuck(this.#now()) === void 0 && this.#admits(bytes)) return Effect.succeed(this.#grant(bytes, true));
375
- return this.#wait(this.#pushes, bytes, pushWaitMs).pipe(Effect.flatMap(Option.match({
657
+ if (this.#stuck(this.#now()) === void 0 && this.#admits(bytes)) return Effect.succeed(own(this.#grant(bytes, true)));
658
+ return this.#wait(this.#pushes, true, bytes, pushWaitMs, void 0, own).pipe(Effect.flatMap(Option.match({
376
659
  onNone: () => Effect.fail(pushBusy),
377
660
  onSome: Effect.succeed
378
661
  })));
@@ -384,39 +667,85 @@ var MemoryBudget = class {
384
667
  * Bytes past `total` are refused at once, `tooLarge` or `busy`. Released when the scope ends.
385
668
  */
386
669
  allot(bytes, busy = readBusy, tooLarge) {
387
- return this.#scoped(() => {
388
- if (bytes > this.total) return Effect.fail(tooLarge ?? busy);
389
- if (this.#stuck(this.#now()) === void 0 && this.#fit(bytes)) return Effect.succeed(this.#grant(bytes, false, busy));
390
- return this.#wait(this.#reads, bytes, growWaitMs, busy).pipe(Effect.flatMap(Option.match({
670
+ return Effect.flatMap(Effect.serviceOption(RequestHolding), (hold) => this.#allotOf(bytes, false, busy, tooLarge, Option.getOrUndefined(hold)));
671
+ }
672
+ /**
673
+ * Upkeep's allotment of `bytes`, a maintenance step's or an index build's: upkeep honours the
674
+ * read reserve, as pushes do, so it grows as a push's does, beside the admitted pushes within
675
+ * `total` less `reserve` and counted with them, and a read's floors always fit beside it (Q895).
676
+ * It and each grow wait `growWaitMs` as a read's, then fail `busy`, as `bytes` past all it may
677
+ * hold does at once. Released when the scope ends.
678
+ */
679
+ upkeep(bytes = 0, busy = readBusy) {
680
+ return this.#allotOf(bytes, true, busy);
681
+ }
682
+ /**
683
+ * `allot`'s and `upkeep`'s allotment of `bytes`: at once when they fit, no push is stuck at the
684
+ * head and, for upkeep, no push's grow waits that they'd take the room of; else within
685
+ * `growWaitMs`, then `busy`. With `push`, they fit as a push's grows do.
686
+ * Bytes past what it may ever hold are refused at once, `tooLarge` or `busy`.
687
+ */
688
+ #allotOf(bytes, push, busy, tooLarge, asker) {
689
+ return this.#scoped((own) => {
690
+ if (bytes > this.mostOf(push)) return Effect.fail(tooLarge ?? busy);
691
+ const owned = (allotment) => {
692
+ if (push) this.#upkeeps.add(allotment);
693
+ return own(allotment);
694
+ };
695
+ if (this.#stuck(this.#now()) === void 0 && this.#fits(bytes, push, asker) && !this.#yieldsToPushes(bytes, push)) return Effect.succeed(owned(this.#grant(bytes, push, busy, asker)));
696
+ return this.#wait(this.#reads, push, bytes, growWaitMs, busy, owned, asker).pipe(Effect.flatMap(Option.match({
391
697
  onNone: () => Effect.fail(busy),
392
698
  onSome: Effect.succeed
393
699
  })));
394
700
  });
395
701
  }
396
- /** `MemoryAllotment.tryGrow`: its bytes when they fit at once, caches shrunk, and no push is stuck. */
702
+ /**
703
+ * `MemoryAllotment.tryGrow`: its bytes when they fit at once, caches shrunk, no push is stuck and,
704
+ * for upkeep, no push's grow waits that they'd take the room of. A push's fit beside the admitted pushes, the reserve left, and count with them, so a read's
705
+ * floors always fit beside every push's holdings.
706
+ */
397
707
  tryGrow(allotment, bytes) {
398
708
  if (allotment.released || bytes <= 0) return true;
399
- if (this.#stuck(this.#now()) !== void 0 || !this.#fit(bytes)) return false;
709
+ const fits = this.#fits(bytes, allotment.push, allotment.owner);
710
+ if (this.#stuck(this.#now()) !== void 0 || !fits) return false;
711
+ if (this.#yieldsToPushes(bytes, this.#upkeeps.has(allotment))) return false;
712
+ if (allotment.push) this.#admitted += bytes;
400
713
  this.#allotted += bytes;
401
714
  allotment.added(bytes);
715
+ this.#wakeRooms();
402
716
  return true;
403
717
  }
404
- /** `MemoryAllotment.grow`: its bytes waited for as a read's, then handed to `allotment`. */
718
+ /**
719
+ * `MemoryAllotment.grow`: its bytes waited for as a read's, then handed to `allotment`. A push's
720
+ * past all of the budget but the reserve, which no wait makes room for, are refused at once.
721
+ */
405
722
  grow(allotment, bytes, busy, tooLarge) {
406
723
  return this.#timed(() => {
407
724
  if (allotment.released || bytes <= 0) return Effect.void;
408
- if (allotment.bytes + bytes > this.total) return Effect.fail(tooLarge ?? busy);
725
+ if (allotment.bytes + bytes > this.mostOf(allotment.push)) return Effect.fail(tooLarge ?? busy);
409
726
  if (this.tryGrow(allotment, bytes)) return Effect.void;
410
- return Effect.uninterruptibleMask((restore) => restore(this.#wait(this.#reads, bytes, growWaitMs)).pipe(Effect.flatMap(Option.match({
411
- onNone: () => Effect.fail(busy),
412
- onSome: (granted) => Effect.sync(() => {
413
- granted.adopted();
414
- allotment.added(granted.bytes);
415
- if (allotment.released) this.returned(granted.bytes, 0);
416
- })
417
- }))));
727
+ const adopt = (granted) => {
728
+ granted.adopted();
729
+ allotment.added(granted.bytes);
730
+ if (allotment.released) this.returned(granted.bytes, granted.admitted);
731
+ };
732
+ const { push, owner } = allotment;
733
+ return this.#wait(this.#reads, push, bytes, growWaitMs, void 0, adopt, owner, allotment).pipe(Effect.flatMap(Option.match({
734
+ onNone: () => Effect.andThen(this.#refusedGrow(allotment, bytes), Effect.fail(busy)),
735
+ onSome: () => Effect.void
736
+ })));
418
737
  });
419
738
  }
739
+ /**
740
+ * A grow refused busy, one line in the log with who asked and what was free as its wait ended,
741
+ * so a refusal beside upkeep shows as a pattern (#1300).
742
+ */
743
+ #refusedGrow(allotment, bytes) {
744
+ const kind = this.#upkeeps.has(allotment) ? "upkeep" : allotment.push ? "push" : "read";
745
+ const free = this.total - this.#allotted;
746
+ const beside = this.total - this.reserve - this.#admitted;
747
+ return Effect.logWarning(`The ${kind} allotment's grow of ${bytes} B, holding ${allotment.bytes} B, was refused busy after ${growWaitMs} ms, with ${free} B of the budget's ${this.total} B free and ${beside} B beside the admitted pushes`);
748
+ }
420
749
  };
421
750
  /**
422
751
  * `ObjectReader.allotment` on a reader's `allotment`: at most `most` bytes, `refusal` past it.
@@ -468,19 +797,100 @@ const allottedWithin = (allotment, most, refusal, context) => {
468
797
  /**
469
798
  * A reader's memory on `allotment`: its read cache and blocks as rooms that start at their floors
470
799
  * and grow to their most while there's room, each pack's indexes charged as the allotment's
471
- * growth, and what a resolve holds outside the cache as its high-water, refused past the whole
472
- * budget with `tooLarge` when given.
800
+ * growth, refused at once past what it could have alone with `indexTooLarge` when given, and
801
+ * what a resolve holds outside the cache as its high-water, refused past the whole budget with
802
+ * `tooLarge` when given. Past only what's left beside others, either waits as a grow does. With
803
+ * `waits`, its blocks wait for room for a block read again, refused with the allotment's busy, for
804
+ * a caller that retries it: a push's, which Git retries.
473
805
  */
474
- const readerMemoryOf = (allotment, { floors = readerFloors, most = readerMost, tooLarge } = {}) => ({
475
- cache: allotment.room(floors.cache, most.cache),
476
- blocks: allotment.room(floors.blocks, most.blocks),
477
- index: (bytes) => allotment.grow(bytes),
478
- outside: outsideOn(allotment, tooLarge)
806
+ const readerMemoryOf = (allotment, { floors = readerFloors, most = readerMost, tooLarge, indexTooLarge, waits = false } = {}) => {
807
+ let indexed = 0;
808
+ return {
809
+ cache: allotment.room(floors.cache, most.cache),
810
+ blocks: allotment.room(floors.blocks, most.blocks, waits),
811
+ index: (bytes) => {
812
+ if (indexTooLarge !== void 0 && bytes > allotment.growable) {
813
+ const own = Math.max(0, allotment.bytes - indexed);
814
+ return Effect.fail(indexTooLarge(indexed + bytes, own, allotment.bytes + allotment.growable));
815
+ }
816
+ return Effect.map(allotment.grow(bytes), () => {
817
+ indexed += bytes;
818
+ });
819
+ },
820
+ outside: outsideOn((bytes) => allotment.grow(bytes), tooLarge === void 0 ? void 0 : {
821
+ tooLarge,
822
+ growable: () => allotment.growable
823
+ })
824
+ };
825
+ };
826
+ /**
827
+ * An upkeep step's runs, cut and merged within the upkeep allotment: 4 MiB runs, read back 256 KiB
828
+ * at a time, 32 at once, so s1m's 7 runs of a pass merge without narrowing. A merge's hold counts
829
+ * them: its walk's chosen runs as `cursorHeld` does, its index pass's as `runsHeld` does.
830
+ */
831
+ const upkeepRuns = {
832
+ runBytes: 4194304,
833
+ readBytes: 262144,
834
+ ways: 32
835
+ };
836
+ /**
837
+ * A maintenance reader's or merge's memory on the upkeep `allotment`, which counts nothing for it
838
+ * up front: the reader's floors, and `extra` besides, grown on it before its rooms are made, then
839
+ * each index it charges and what a resolve holds outside the cache. Each grow is refused as
840
+ * `upkeepTooLarge` past all the allotment may hold, and as its busy past its wait; its waits can
841
+ * be interrupted. All of it goes back when its scope ends, so a step's merges, one after another,
842
+ * never add up. Its blocks start at `blocks`, the reader's floor unless set, as a walk holds its
843
+ * 8 so it never rereads a block.
844
+ */
845
+ const upkeepMemoryOf = (allotment, extra = 0, blocks = readerFloors.blocks) => Effect.suspend(() => {
846
+ const floors = readerFloors.cache + blocks + extra;
847
+ let grown = 0;
848
+ const grow = (bytes) => Effect.map(allotment.grow(bytes, upkeepTooLarge), () => {
849
+ grown += bytes;
850
+ });
851
+ return Effect.acquireRelease(Effect.map(allotment.grow(floors, upkeepTooLarge), () => ({
852
+ cache: allotment.room(readerFloors.cache, readerMost.cache),
853
+ blocks: allotment.room(blocks, readerMost.blocks, true),
854
+ index: grow,
855
+ outside: outsideOn(grow)
856
+ })), (memory) => Effect.sync(() => {
857
+ allotment.endRoom(memory.cache);
858
+ allotment.endRoom(memory.blocks);
859
+ allotment.shrink(floors + grown);
860
+ }), { interruptible: true });
479
861
  });
480
862
  /**
863
+ * A push's link join in its receive's `room` on `allotment`: what the join takes reuses what the
864
+ * room's sweeps and table gave back, and grows the allotment only past the most the room held.
865
+ * Growth past what the push could ever have is refused at once as the repo's pack indexes' part,
866
+ * by Q879's split, since no wait would fit it; past what's left beside others, it waits as the
867
+ * room's grow does, then `pushBusy`.
868
+ */
869
+ const joinRoomOf = (allotment, room) => {
870
+ let joined = 0;
871
+ return {
872
+ take: (bytes) => {
873
+ const more = room.growth(bytes);
874
+ if (more > allotment.growable) {
875
+ const index = joined + bytes;
876
+ const most = allotment.bytes + allotment.growable;
877
+ return Effect.fail(pushIndexTooLarge(index, allotment.bytes + more - index, most));
878
+ }
879
+ joined += bytes;
880
+ return room.take(bytes) ?? Effect.void;
881
+ },
882
+ give: (bytes) => {
883
+ joined -= bytes;
884
+ room.give(bytes);
885
+ }
886
+ };
887
+ };
888
+ /**
481
889
  * A push's memory on its admitted `allotment`, which already counts its floors: its blocks from
482
890
  * their floor, a read cache from none, the indexer's base cache from its floor to its limit, and
483
- * its links' memo from its floor to as much as the push was admitted with.
891
+ * its receive's room from what it was admitted with, grown as a push's grow is, its link join
892
+ * within it, and its reads' indexes too: within `growWaitMs`, then `pushBusy`, and `pushTooLarge`
893
+ * past the whole budget.
484
894
  */
485
895
  const pushMemoryOf = (allotment, size) => {
486
896
  const floors = pushFloorsOf(size);
@@ -489,28 +899,36 @@ const pushMemoryOf = (allotment, size) => {
489
899
  cache: 0,
490
900
  blocks: floors.blocks
491
901
  },
492
- tooLarge: pushTooLarge
902
+ tooLarge: pushEntryTooLarge(size.objects),
903
+ indexTooLarge: pushIndexTooLarge,
904
+ waits: true
493
905
  });
906
+ const room = new ReceiveRoom((bytes) => allotment.grow(bytes, pushTooLarge), receiveRoomAdmitted(size.objects), () => allotment.growable);
494
907
  return {
495
908
  reader,
496
909
  cache: allotment.room(floors.cache, packIndexerLimits.cacheBytes),
497
- memo: allotment.room(floors.memo, allotment.bytes),
498
910
  pointers: new AllottedPointers(allotment),
499
- outside: reader.outside
911
+ outside: reader.outside,
912
+ room,
913
+ join: joinRoomOf(allotment, room)
500
914
  };
501
915
  };
502
916
  /**
503
- * What an indexer takes outside its cache, on its allotment: grown to each ask that passes the
504
- * most it grew to, waiting as a grow does, then refused with the allotment's `busy`; past the
505
- * whole budget, at once with `tooLarge` when given. It keeps that high-water until the allotment
506
- * ends, since the next large entry would need it again: a reader's resolves, a push's indexer,
507
- * and an index build's slice.
917
+ * What an indexer takes outside its cache, through `grow`, an allotment's: grown to each ask that
918
+ * passes the most it grew to, waiting and refused as `grow` is, and with `refused`, refused at once
919
+ * past what its `growable` and its high-water leave. It keeps that high-water until the allotment
920
+ * ends, since the next large entry would need it again: a reader's resolves, a push's indexer, and
921
+ * an index build's slice.
508
922
  */
509
- const outsideOn = (allotment, tooLarge) => {
923
+ const outsideOn = (grow, refused) => {
510
924
  let grown = 0;
511
925
  return (bytes) => {
512
926
  if (bytes <= grown) return void 0;
513
- return Effect.map(allotment.grow(bytes - grown, tooLarge), () => {
927
+ if (refused !== void 0) {
928
+ const left = refused.growable() + grown;
929
+ if (bytes > left) return Effect.fail(refused.tooLarge(bytes, left));
930
+ }
931
+ return Effect.map(grow(bytes - grown), () => {
514
932
  grown = Math.max(grown, bytes);
515
933
  });
516
934
  };
@@ -529,13 +947,23 @@ var AllottedPointers = class {
529
947
  }
530
948
  /** Lists the blob as `ReceivedPointers` does, then grows the allotment a page if it opened one. */
531
949
  add(blob, bytes) {
532
- return Effect.flatMap(this.#pointers.add(blob, bytes), () => {
533
- const opened = this.#pages * pageEntries;
534
- if (this.#pointers.count <= opened) return Effect.void;
535
- const page = Math.min(pageEntries, lfsPointersMost - opened) * 52;
536
- return Effect.map(this.#allotment.grow(page), () => {
537
- this.#pages += 1;
538
- });
950
+ return Effect.flatMap(this.#pointers.add(blob, bytes), () => this.#grown(this.#pointers.count));
951
+ }
952
+ /** The allotment grown for the pages of `count` pointers, before they're read into them. */
953
+ carrying(count) {
954
+ return Effect.forEach(Array.from({ length: Math.ceil(count / pageEntries) }), (_, page) => this.#grown(page * pageEntries + 1)).pipe(Effect.asVoid);
955
+ }
956
+ /** Lists a pointer an earlier step found, into a page `carrying` grew the allotment for. */
957
+ carried(record) {
958
+ this.#pointers.carried(record);
959
+ }
960
+ /** The allotment grown a page if `count` pointers open one past the pages it holds. */
961
+ #grown(count) {
962
+ const opened = this.#pages * pageEntries;
963
+ if (count <= opened) return Effect.void;
964
+ const page = Math.min(pageEntries, lfsPointersMost - opened) * 52;
965
+ return Effect.map(this.#allotment.grow(page), () => {
966
+ this.#pages += 1;
539
967
  });
540
968
  }
541
969
  /** The pointers it found, sorted by blob: their `bytes` are what the push keeps past its answer. */
@@ -543,4 +971,4 @@ var AllottedPointers = class {
543
971
  return this.#pointers.finish();
544
972
  }
545
973
  };
546
- export { AllottedPointers, MemoryAllotment, MemoryBudget, allottedWithin, fetchBusy, growWaitMs, headStuckMs, outsideOn, pushBusy, pushMemoryOf, pushTooLarge, pushWaitMs, readBusy, readerMemoryOf };
974
+ export { AllottedPointers, MemoryAllotment, MemoryBudget, allottedWithin, fetchBusy, growWaitMs, headStuckMs, joinRoomOf, outsideOn, pushBusy, pushEntryTooLarge, pushIndexTooLarge, pushMemoryOf, pushTooLarge, pushWaitMs, readBusy, readerMemoryOf, upkeepMemoryOf, upkeepRuns, upkeepTooLarge };