@ref0/git 0.3.0 → 0.4.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 (607) 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 +69 -46
  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 +57 -80
  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 +3 -0
  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 +51 -13
  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 +94 -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 +36 -9
  52. package/dist/contracts/actors.d.mts +28 -10
  53. package/dist/contracts/actors.mjs +17 -0
  54. package/dist/contracts/authorize.d.mts +77 -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 +1382 -205
  66. package/dist/contracts/events.mjs +485 -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 +107 -0
  72. package/dist/contracts/git.mjs +23 -0
  73. package/dist/contracts/grants.d.mts +2 -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 +9 -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 +323 -87
  83. package/dist/contracts/operations.d.mts +24 -16
  84. package/dist/contracts/promises.d.mts +13 -2
  85. package/dist/contracts/push-uploads.d.mts +39 -24
  86. package/dist/contracts/push-uploads.mjs +54 -0
  87. package/dist/contracts/queue.d.mts +444 -139
  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 +335 -69
  96. package/dist/contracts/result.mjs +350 -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 +113 -47
  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 +127 -20
  117. package/dist/contracts/work.mjs +69 -0
  118. package/dist/core/access.d.mts +25 -14
  119. package/dist/core/access.mjs +77 -108
  120. package/dist/core/ancestry.mjs +86 -18
  121. package/dist/core/call-names.mjs +1 -0
  122. package/dist/core/call-services.mjs +73 -0
  123. package/dist/core/changes.d.mts +31 -0
  124. package/dist/core/changes.mjs +5 -0
  125. package/dist/core/clock.mjs +3 -3
  126. package/dist/core/events/deliver.mjs +119 -33
  127. package/dist/core/events/seen.mjs +124 -0
  128. package/dist/core/forks.mjs +371 -159
  129. package/dist/core/hooks/order.d.mts +9 -0
  130. package/dist/core/hooks/order.mjs +25 -0
  131. package/dist/core/hooks/post-receive.mjs +13 -12
  132. package/dist/core/hooks/pre-receive.d.mts +8 -1
  133. package/dist/core/hooks/pre-receive.mjs +8 -6
  134. package/dist/core/imports.mjs +212 -0
  135. package/dist/core/index-job.mjs +131 -38
  136. package/dist/core/merge-parts.d.mts +30 -0
  137. package/dist/core/merge-parts.mjs +31 -0
  138. package/dist/core/names.mjs +4 -16
  139. package/dist/core/namespaces.d.mts +2 -0
  140. package/dist/core/objects/blobs.mjs +4 -4
  141. package/dist/core/objects/commit-writes.mjs +19 -17
  142. package/dist/core/objects/commits.mjs +12 -12
  143. package/dist/core/objects/files.mjs +10 -11
  144. package/dist/core/objects/lines.mjs +15 -32
  145. package/dist/core/objects/merges.mjs +4 -4
  146. package/dist/core/objects/objects-layer.d.mts +21 -0
  147. package/dist/core/objects/objects-layer.mjs +47 -0
  148. package/dist/core/objects/objects-namespace.d.mts +6 -0
  149. package/dist/core/objects/objects-namespace.mjs +13 -0
  150. package/dist/core/objects/objects.d.mts +49 -0
  151. package/dist/core/objects/objects.mjs +18 -0
  152. package/dist/core/objects/peel.mjs +3 -3
  153. package/dist/core/objects/reading.mjs +135 -40
  154. package/dist/core/objects/tags.mjs +7 -7
  155. package/dist/core/objects/tree-edits.mjs +40 -27
  156. package/dist/core/objects/trees.mjs +23 -18
  157. package/dist/core/objects/writing.mjs +43 -44
  158. package/dist/core/own-writes.mjs +3 -3
  159. package/dist/core/parts.d.mts +125 -0
  160. package/dist/core/parts.mjs +59 -0
  161. package/dist/core/promise.mjs +13 -9
  162. package/dist/core/publish.mjs +27 -17
  163. package/dist/core/purge.mjs +242 -0
  164. package/dist/core/push-decide.mjs +93 -28
  165. package/dist/core/push.mjs +300 -156
  166. package/dist/core/receipts.d.mts +4 -3
  167. package/dist/core/receipts.mjs +20 -12
  168. package/dist/core/ref-conflicts.mjs +70 -4
  169. package/dist/core/ref-index-job.mjs +181 -0
  170. package/dist/core/ref-index.d.mts +25 -0
  171. package/dist/core/ref-index.mjs +136 -0
  172. package/dist/core/ref-view.mjs +166 -0
  173. package/dist/core/refs.mjs +313 -95
  174. package/dist/core/repack.d.mts +10 -0
  175. package/dist/core/repack.mjs +261 -81
  176. package/dist/core/repo-info.mjs +99 -0
  177. package/dist/core/repos.mjs +114 -80
  178. package/dist/core/rules/changes.mjs +48 -20
  179. package/dist/core/rules/check.mjs +29 -22
  180. package/dist/core/rules/commit-changes.d.mts +13 -0
  181. package/dist/core/rules/commit-changes.mjs +100 -91
  182. package/dist/core/rules/context.d.mts +67 -8
  183. package/dist/core/rules/context.mjs +88 -51
  184. package/dist/core/rules/facts.mjs +1 -1
  185. package/dist/core/rules/fetch.mjs +24 -26
  186. package/dist/core/rules/files.d.mts +13 -0
  187. package/dist/core/rules/files.mjs +27 -28
  188. package/dist/core/rules/namespace.d.mts +2 -0
  189. package/dist/core/rules/patterns.mjs +29 -5
  190. package/dist/core/rules/protect.d.mts +12 -6
  191. package/dist/core/rules/protect.mjs +22 -20
  192. package/dist/core/rules/rules-layer.d.mts +17 -0
  193. package/dist/core/rules/rules-layer.mjs +26 -0
  194. package/dist/core/rules/rules.d.mts +8 -0
  195. package/dist/core/rules/rules.mjs +16 -0
  196. package/dist/core/rules/service.mjs +18 -0
  197. package/dist/core/seam.d.mts +8 -5
  198. package/dist/core/seam.mjs +19 -15
  199. package/dist/core/tokens.mjs +29 -23
  200. package/dist/core/view.d.mts +105 -6
  201. package/dist/core/view.mjs +211 -109
  202. package/dist/core/work.mjs +40 -14
  203. package/dist/effect.d.mts +3 -4
  204. package/dist/effect.mjs +2 -3
  205. package/dist/engine/allotted-xdiff.d.mts +1 -0
  206. package/dist/engine/allotted-xdiff.mjs +1 -1
  207. package/dist/engine/attributes.mjs +1 -1
  208. package/dist/engine/combined.d.mts +18 -0
  209. package/dist/engine/combined.mjs +39 -44
  210. package/dist/engine/commits.mjs +5 -4
  211. package/dist/engine/content.d.mts +3 -2
  212. package/dist/engine/content.mjs +2 -2
  213. package/dist/engine/failures.d.mts +2 -2
  214. package/dist/engine/failures.mjs +2 -9
  215. package/dist/engine/merge-base-walk.d.mts +3 -2
  216. package/dist/engine/merge-base-walk.mjs +1 -1
  217. package/dist/engine/merge-bases.mjs +3 -2
  218. package/dist/engine/merge.mjs +568 -566
  219. package/dist/engine/parts.d.mts +3 -2
  220. package/dist/engine/parts.mjs +40 -7
  221. package/dist/engine/reads.d.mts +1 -0
  222. package/dist/engine/reads.mjs +5 -5
  223. package/dist/engine/walk.mjs +23 -24
  224. package/dist/engine/xdiff.d.mts +2 -33
  225. package/dist/engine/xdiff.mjs +6 -3
  226. package/dist/event-streams/event-streams.d.mts +25 -0
  227. package/dist/event-streams/event-streams.mjs +22 -0
  228. package/dist/event-streams/namespace.d.mts +2 -0
  229. package/dist/event-streams/stream.d.mts +42 -0
  230. package/dist/{core/events → event-streams}/stream.mjs +106 -49
  231. package/dist/extend.d.mts +4 -2
  232. package/dist/http/answers.mjs +8 -4
  233. package/dist/http/bodies.mjs +84 -56
  234. package/dist/http/core-parts.mjs +206 -60
  235. package/dist/http/handler.d.mts +2 -0
  236. package/dist/http/handler.mjs +17 -11
  237. package/dist/http/node.mjs +10 -6
  238. package/dist/http/parts.d.mts +12 -0
  239. package/dist/http/push-uploads.d.mts +9 -0
  240. package/dist/http/push-uploads.mjs +76 -66
  241. package/dist/http/receive-pack.mjs +162 -28
  242. package/dist/http/upload-pack.mjs +106 -81
  243. package/dist/index.d.mts +48 -28
  244. package/dist/index.mjs +29 -7
  245. package/dist/lfs/calls.mjs +2 -2
  246. package/dist/lfs/locks.mjs +24 -20
  247. package/dist/lfs/objects.d.mts +7 -0
  248. package/dist/lfs/objects.mjs +31 -26
  249. package/dist/lfs/pointers.mjs +7 -7
  250. package/dist/lfs/purge.mjs +50 -0
  251. package/dist/lfs/repo.mjs +5 -5
  252. package/dist/lfs/rows.mjs +8 -8
  253. package/dist/lfs/service.d.mts +9 -0
  254. package/dist/lfs/service.mjs +32 -25
  255. package/dist/lfs/upkeep.mjs +5 -5
  256. package/dist/lfs/wire.mjs +80 -38
  257. package/dist/merges/merges.d.mts +20 -0
  258. package/dist/merges/merges.mjs +32 -0
  259. package/dist/merges/namespace.d.mts +2 -0
  260. package/dist/merges/public.d.mts +6 -0
  261. package/dist/merges/public.mjs +10 -0
  262. package/dist/node.d.mts +1 -2
  263. package/dist/node.mjs +1 -3
  264. package/dist/protocol/bytes/buffers.d.mts +9 -3
  265. package/dist/protocol/bytes/buffers.mjs +11 -5
  266. package/dist/protocol/bytes/deflate.d.mts +7 -5
  267. package/dist/protocol/bytes/deflate.mjs +59 -23
  268. package/dist/protocol/bytes/inflate.d.mts +4 -3
  269. package/dist/protocol/bytes/inflate.mjs +61 -26
  270. package/dist/protocol/bytes/reader.mjs +61 -0
  271. package/dist/protocol/bytes/sha1-hasher.d.mts +3 -1
  272. package/dist/protocol/bytes/sha1-hasher.mjs +13 -3
  273. package/dist/protocol/bytes/sha1.d.mts +1 -1
  274. package/dist/protocol/bytes/sha1.mjs +5 -5
  275. package/dist/protocol/bytes/streams.mjs +16 -6
  276. package/dist/protocol/diff/patch.d.mts +4 -0
  277. package/dist/protocol/diff/patch.mjs +1 -1
  278. package/dist/protocol/diff/paths.mjs +1 -1
  279. package/dist/protocol/diff/read.d.mts +1 -1
  280. package/dist/protocol/diff/read.mjs +102 -90
  281. package/dist/protocol/framing/pkt-line.d.mts +1 -0
  282. package/dist/protocol/framing/pkt-line.mjs +40 -6
  283. package/dist/protocol/objects/checked-blobs.d.mts +1 -0
  284. package/dist/protocol/objects/fsck.mjs +7 -1
  285. package/dist/protocol/objects/held.mjs +5 -11
  286. package/dist/protocol/objects/ident.mjs +1 -1
  287. package/dist/protocol/objects/object-rules.mjs +15 -7
  288. package/dist/protocol/objects/object.d.mts +6 -2
  289. package/dist/protocol/objects/object.mjs +5 -2
  290. package/dist/protocol/objects/tag.d.mts +3 -1
  291. package/dist/protocol/objects/tag.mjs +27 -1
  292. package/dist/protocol/objects/tree.mjs +1 -1
  293. package/dist/protocol/packs/delta.d.mts +1 -1
  294. package/dist/protocol/packs/delta.mjs +2 -2
  295. package/dist/protocol/packs/graph.mjs +55 -56
  296. package/dist/protocol/packs/idx.d.mts +4 -2
  297. package/dist/protocol/packs/idx.mjs +156 -63
  298. package/dist/protocol/packs/indexer.d.mts +22 -4
  299. package/dist/protocol/packs/indexer.mjs +14 -35
  300. package/dist/protocol/packs/parts.mjs +5 -5
  301. package/dist/protocol/packs/pos.mjs +12 -5
  302. package/dist/protocol/packs/reader.d.mts +19 -12
  303. package/dist/protocol/packs/reader.mjs +252 -25
  304. package/dist/protocol/packs/rev.d.mts +1 -1
  305. package/dist/protocol/packs/rev.mjs +42 -24
  306. package/dist/protocol/packs/types-file.mjs +85 -0
  307. package/dist/protocol/packs/write-error.d.mts +1 -1
  308. package/dist/protocol/packs/write-error.mjs +2 -2
  309. package/dist/protocol/packs/writer.d.mts +40 -15
  310. package/dist/protocol/packs/writer.mjs +142 -49
  311. package/dist/protocol/wire/advertisement.d.mts +39 -14
  312. package/dist/protocol/wire/advertisement.mjs +127 -31
  313. package/dist/protocol/wire/fetch.d.mts +57 -19
  314. package/dist/protocol/wire/fetch.mjs +57 -26
  315. package/dist/protocol/wire/json.mjs +25 -0
  316. package/dist/protocol/wire/lines.d.mts +10 -0
  317. package/dist/protocol/wire/lines.mjs +20 -6
  318. package/dist/protocol/wire/push-limits.d.mts +6 -0
  319. package/dist/protocol/wire/push-limits.mjs +88 -0
  320. package/dist/protocol/wire/push-uploads.mjs +3 -28
  321. package/dist/protocol/wire/receive-pack.d.mts +30 -14
  322. package/dist/protocol/wire/receive-pack.mjs +29 -2
  323. package/dist/protocol/wire/report-status.d.mts +30 -11
  324. package/dist/protocol/wire/report-status.mjs +21 -2
  325. package/dist/protocol/wire/v2.d.mts +56 -29
  326. package/dist/protocol/wire/v2.mjs +91 -16
  327. package/dist/protocol.d.mts +4 -3
  328. package/dist/protocol.mjs +7 -6
  329. package/dist/queue/advance.mjs +189 -120
  330. package/dist/queue/callers.mjs +12 -9
  331. package/dist/queue/calls.mjs +311 -155
  332. package/dist/queue/commit.mjs +70 -26
  333. package/dist/queue/host.d.mts +39 -12
  334. package/dist/queue/host.mjs +36 -38
  335. package/dist/queue/lanes.mjs +1 -1
  336. package/dist/queue/layer.d.mts +14 -0
  337. package/dist/queue/layer.mjs +55 -0
  338. package/dist/queue/limits.mjs +13 -2
  339. package/dist/queue/namespace.d.mts +2 -0
  340. package/dist/queue/pages.mjs +1 -1
  341. package/dist/queue/public.d.mts +6 -0
  342. package/dist/queue/public.mjs +21 -0
  343. package/dist/queue/push-option.mjs +49 -30
  344. package/dist/queue/rows.mjs +24 -16
  345. package/dist/queue/schedule.mjs +22 -22
  346. package/dist/queue/search.mjs +8 -7
  347. package/dist/queue/state.mjs +49 -13
  348. package/dist/queue/steps.mjs +6 -3
  349. package/dist/remote-helper.d.mts +5 -2
  350. package/dist/remote-helper.mjs +5 -2
  351. package/dist/rest/api.d.mts +1 -1
  352. package/dist/rest/blobs.d.mts +790 -23
  353. package/dist/rest/blobs.mjs +4 -4
  354. package/dist/rest/caller.d.mts +4163 -36
  355. package/dist/rest/caller.mjs +2 -2
  356. package/dist/rest/client.mjs +80 -70
  357. package/dist/rest/commits.d.mts +3315 -244
  358. package/dist/rest/commits.mjs +18 -64
  359. package/dist/rest/errors.d.mts +2082 -22
  360. package/dist/rest/errors.mjs +46 -89
  361. package/dist/rest/events.d.mts +394 -11
  362. package/dist/rest/events.mjs +13 -9
  363. package/dist/rest/files.d.mts +1265 -114
  364. package/dist/rest/files.mjs +11 -42
  365. package/dist/rest/forks.d.mts +2005 -62
  366. package/dist/rest/forks.mjs +10 -13
  367. package/dist/rest/handler.d.mts +3 -0
  368. package/dist/rest/handler.mjs +22 -14
  369. package/dist/rest/handlers.mjs +53 -60
  370. package/dist/rest/listen.d.mts +5 -8
  371. package/dist/rest/listen.mjs +23 -29
  372. package/dist/rest/me.d.mts +393 -10
  373. package/dist/rest/me.mjs +2 -2
  374. package/dist/rest/merges.d.mts +399 -16
  375. package/dist/rest/merges.mjs +3 -17
  376. package/dist/rest/paths.mjs +1 -0
  377. package/dist/rest/queue.d.mts +5615 -240
  378. package/dist/rest/queue.mjs +15 -130
  379. package/dist/rest/refs.d.mts +2859 -132
  380. package/dist/rest/refs.mjs +19 -39
  381. package/dist/rest/repos.d.mts +2421 -93
  382. package/dist/rest/repos.mjs +10 -33
  383. package/dist/rest/tags.d.mts +1205 -54
  384. package/dist/rest/tags.mjs +6 -34
  385. package/dist/rest/tokens.d.mts +2369 -66
  386. package/dist/rest/tokens.mjs +7 -4
  387. package/dist/rest/topics.d.mts +2060 -113
  388. package/dist/rest/topics.mjs +23 -71
  389. package/dist/rest/trees.d.mts +1610 -75
  390. package/dist/rest/trees.mjs +16 -57
  391. package/dist/rest/wire.d.mts +402 -0
  392. package/dist/rest/wire.mjs +32 -46
  393. package/dist/rest/work.d.mts +1204 -63
  394. package/dist/rest/work.mjs +7 -51
  395. package/dist/rest.d.mts +3 -3
  396. package/dist/server/extension.d.mts +6 -2
  397. package/dist/server/extension.mjs +54 -30
  398. package/dist/server/git-layer.d.mts +23 -0
  399. package/dist/server/git-layer.mjs +107 -0
  400. package/dist/server/git-namespace.d.mts +6 -0
  401. package/dist/server/git-namespace.mjs +15 -0
  402. package/dist/server/lifecycle.d.mts +1 -2
  403. package/dist/server/lifecycle.mjs +8 -15
  404. package/dist/server/namespaces.d.mts +2 -0
  405. package/dist/server/registry.d.mts +9 -0
  406. package/dist/server/registry.mjs +167 -0
  407. package/dist/server/route-match.mjs +88 -0
  408. package/dist/server/routes.d.mts +12 -8
  409. package/dist/server/routes.mjs +27 -18
  410. package/dist/server/server.d.mts +19 -0
  411. package/dist/server/server.mjs +281 -198
  412. package/dist/signin/codes.mjs +9 -6
  413. package/dist/signin/context.d.mts +1 -0
  414. package/dist/signin/context.mjs +4 -4
  415. package/dist/signin/device.mjs +8 -8
  416. package/dist/signin/forms.mjs +11 -29
  417. package/dist/signin/grants.d.mts +4 -2
  418. package/dist/signin/grants.mjs +20 -19
  419. package/dist/signin/route.mjs +2 -2
  420. package/dist/signin/web.mjs +7 -7
  421. package/dist/signin/wire.mjs +6 -6
  422. package/dist/storage/budget.mjs +51 -18
  423. package/dist/storage/calls.d.mts +22 -4
  424. package/dist/storage/calls.mjs +347 -110
  425. package/dist/storage/clean-up.mjs +80 -35
  426. package/dist/storage/counted-bucket.mjs +115 -0
  427. package/dist/storage/fetch.d.mts +2 -0
  428. package/dist/storage/fetch.mjs +243 -100
  429. package/dist/storage/fsck.mjs +56 -7
  430. package/dist/storage/held-types.d.mts +7 -0
  431. package/dist/storage/held-types.mjs +263 -0
  432. package/dist/storage/host-bucket.mjs +28 -0
  433. package/dist/storage/id-mix.d.mts +1 -0
  434. package/dist/storage/id-mix.mjs +55 -0
  435. package/dist/storage/index-bitmaps.d.mts +2 -1
  436. package/dist/storage/index-bitmaps.mjs +233 -101
  437. package/dist/storage/index-build.d.mts +7 -3
  438. package/dist/storage/index-build.mjs +650 -164
  439. package/dist/storage/index-fetch.d.mts +3 -1
  440. package/dist/storage/index-fetch.mjs +297 -195
  441. package/dist/storage/index-files.mjs +25 -27
  442. package/dist/storage/index-graph.d.mts +2 -1
  443. package/dist/storage/index-graph.mjs +127 -91
  444. package/dist/storage/index-layers.d.mts +11 -0
  445. package/dist/storage/index-layers.mjs +258 -78
  446. package/dist/storage/index-reach.mjs +181 -75
  447. package/dist/storage/index-remap.mjs +74 -32
  448. package/dist/storage/index-shallow.mjs +311 -0
  449. package/dist/storage/index-visible.mjs +168 -0
  450. package/dist/storage/layout.d.mts +1 -0
  451. package/dist/storage/layout.mjs +39 -8
  452. package/dist/storage/lfs-pointers.d.mts +3 -1
  453. package/dist/storage/lfs-pointers.mjs +25 -9
  454. package/dist/storage/link-join.d.mts +4 -0
  455. package/dist/storage/link-join.mjs +50 -12
  456. package/dist/storage/links.mjs +89 -4
  457. package/dist/storage/listed-ids.mjs +10 -0
  458. package/dist/storage/loose.d.mts +11 -4
  459. package/dist/storage/loose.mjs +102 -69
  460. package/dist/storage/memory-budget.d.mts +5 -0
  461. package/dist/storage/memory-budget.mjs +530 -102
  462. package/dist/storage/merge-choose.mjs +258 -0
  463. package/dist/storage/merge-cut.mjs +47 -0
  464. package/dist/storage/merge-fence.mjs +89 -0
  465. package/dist/storage/merge-index.mjs +347 -0
  466. package/dist/storage/merge-most.mjs +202 -0
  467. package/dist/storage/merge-plan.mjs +171 -0
  468. package/dist/storage/merge-row.mjs +258 -0
  469. package/dist/storage/merge-stream.mjs +497 -0
  470. package/dist/storage/merge-walk.mjs +199 -0
  471. package/dist/storage/merge-write.mjs +129 -0
  472. package/dist/storage/merge.d.mts +10 -0
  473. package/dist/storage/merge.mjs +82 -306
  474. package/dist/storage/object-rows.d.mts +4 -2
  475. package/dist/storage/object-rows.mjs +101 -17
  476. package/dist/storage/pack-order.d.mts +1 -1
  477. package/dist/storage/pack-order.mjs +69 -54
  478. package/dist/storage/pack-ranges.d.mts +1 -1
  479. package/dist/storage/pack-ranges.mjs +396 -60
  480. package/dist/storage/pack-reads.d.mts +6 -2
  481. package/dist/storage/pack-reads.mjs +598 -126
  482. package/dist/storage/pack-receive.d.mts +5 -0
  483. package/dist/storage/pack-receive.mjs +820 -237
  484. package/dist/storage/packs-memory.d.mts +25 -0
  485. package/dist/storage/packs-memory.mjs +49 -0
  486. package/dist/storage/packs.d.mts +7 -5
  487. package/dist/storage/packs.mjs +554 -213
  488. package/dist/storage/placed-reads.mjs +205 -0
  489. package/dist/storage/promise-calls.mjs +29 -0
  490. package/dist/storage/prune-keep.mjs +164 -0
  491. package/dist/storage/prune-walk.mjs +578 -0
  492. package/dist/storage/prune.mjs +739 -332
  493. package/dist/storage/push-allotment.mjs +3 -3
  494. package/dist/storage/push-uploads.mjs +22 -13
  495. package/dist/storage/pushed-commits.mjs +8 -9
  496. package/dist/storage/quarantine.d.mts +10 -0
  497. package/dist/storage/quarantine.mjs +28 -25
  498. package/dist/storage/range-cache.mjs +71 -0
  499. package/dist/storage/raw-ids.mjs +20 -1
  500. package/dist/storage/ready.d.mts +4 -2
  501. package/dist/storage/ready.mjs +109 -48
  502. package/dist/storage/receive-admission.mjs +67 -0
  503. package/dist/storage/receive-bounds.d.mts +1 -0
  504. package/dist/storage/receive-bounds.mjs +202 -0
  505. package/dist/storage/receive-files.mjs +248 -0
  506. package/dist/storage/receive-links.mjs +281 -244
  507. package/dist/storage/receive-state.d.mts +9 -0
  508. package/dist/storage/receive-state.mjs +150 -0
  509. package/dist/storage/receive-steps.mjs +344 -0
  510. package/dist/storage/receive-sweep.mjs +160 -0
  511. package/dist/storage/receive-table.d.mts +3 -0
  512. package/dist/storage/receive-table.mjs +197 -0
  513. package/dist/storage/repack-backlog.mjs +70 -0
  514. package/dist/storage/repack-contained.mjs +269 -0
  515. package/dist/storage/repack-job.d.mts +3 -0
  516. package/dist/storage/repack-job.mjs +24 -7
  517. package/dist/storage/repack.d.mts +4 -4
  518. package/dist/storage/repack.mjs +156 -77
  519. package/dist/storage/roots.mjs +23 -7
  520. package/dist/storage/rows.d.mts +4 -2
  521. package/dist/storage/rows.mjs +40 -7
  522. package/dist/storage/runs.d.mts +8 -0
  523. package/dist/storage/runs.mjs +731 -0
  524. package/dist/storage/send-list.d.mts +2 -1
  525. package/dist/storage/send-list.mjs +261 -76
  526. package/dist/storage/shallow.d.mts +3 -2
  527. package/dist/storage/shallow.mjs +7 -7
  528. package/dist/storage/single-flight.mjs +47 -0
  529. package/dist/storage/stream-whole.mjs +121 -54
  530. package/dist/storage/swap-walk.mjs +188 -0
  531. package/dist/storage/unpack.mjs +52 -23
  532. package/dist/storage/visible.mjs +58 -39
  533. package/dist/storage/walk.d.mts +2 -0
  534. package/dist/storage/walk.mjs +20 -7
  535. package/dist/storage/wants.mjs +185 -33
  536. package/dist/storage/written-bases.mjs +172 -0
  537. package/dist/store/call-count.d.mts +69 -4
  538. package/dist/store/call-count.mjs +193 -51
  539. package/dist/store/catalogue.d.mts +17 -3
  540. package/dist/store/catalogue.mjs +135 -48
  541. package/dist/store/crossing.mjs +2 -4
  542. package/dist/store/cursor-seal.d.mts +12 -1
  543. package/dist/store/cursor-seal.mjs +7 -6
  544. package/dist/store/errors.d.mts +2 -2
  545. package/dist/store/errors.mjs +112 -24
  546. package/dist/store/git-store.mjs +21 -2
  547. package/dist/store/list-job.mjs +5 -5
  548. package/dist/store/outbox.d.mts +15 -5
  549. package/dist/store/outbox.mjs +106 -28
  550. package/dist/store/promises.d.mts +3 -2
  551. package/dist/store/promises.mjs +94 -35
  552. package/dist/store/queue-jobs.mjs +12 -12
  553. package/dist/store/records.d.mts +64 -1
  554. package/dist/store/records.mjs +101 -32
  555. package/dist/store/ref-rows.d.mts +18 -2
  556. package/dist/store/ref-rows.mjs +62 -5
  557. package/dist/store/repo-record.mjs +11 -9
  558. package/dist/store/reservations.mjs +9 -8
  559. package/dist/store/scopes.mjs +13 -1
  560. package/dist/store/settle.mjs +1 -1
  561. package/dist/store/topic-jobs.mjs +4 -4
  562. package/dist/sync/bound.d.mts +5 -3
  563. package/dist/sync/bound.mjs +32 -3
  564. package/dist/sync/github.mjs +7 -7
  565. package/dist/sync/import.d.mts +2 -0
  566. package/dist/sync/import.mjs +46 -50
  567. package/dist/sync/jobs.mjs +15 -23
  568. package/dist/sync/mirror.d.mts +5 -1
  569. package/dist/sync/mirror.mjs +121 -44
  570. package/dist/sync/publish.d.mts +1 -0
  571. package/dist/sync/publish.mjs +10 -12
  572. package/dist/sync/step.mjs +439 -71
  573. package/dist/sync/tries.mjs +50 -32
  574. package/dist/sync.d.mts +3 -3
  575. package/dist/sync.mjs +2 -2
  576. package/dist/topics/advance.mjs +103 -86
  577. package/dist/topics/calls.mjs +97 -67
  578. package/dist/topics/directory.mjs +31 -11
  579. package/dist/topics/host.d.mts +0 -1
  580. package/dist/topics/host.mjs +2 -12
  581. package/dist/topics/members.mjs +30 -24
  582. package/dist/topics/rows.mjs +10 -9
  583. package/dist/topics/topic.mjs +20 -9
  584. package/package.json +8 -15
  585. package/dist/auth/authorize.d.mts +0 -5
  586. package/dist/contracts/objects.mjs +0 -54
  587. package/dist/core/events/stream.d.mts +0 -19
  588. package/dist/core/rules/define.d.mts +0 -5
  589. package/dist/core/rules/define.mjs +0 -13
  590. package/dist/core/rules/fetch.d.mts +0 -5
  591. package/dist/core/sight.mjs +0 -99
  592. package/dist/engine/engine.d.mts +0 -25
  593. package/dist/engine/engine.mjs +0 -49
  594. package/dist/engine/xdiff/NOTICE.md +0 -63
  595. package/dist/engine/xdiff/compiled.d.mts +0 -7
  596. package/dist/engine/xdiff/compiled.mjs +0 -9
  597. package/dist/engine/xdiff/embedded.mjs +0 -4
  598. package/dist/engine/xdiff/node.d.mts +0 -7
  599. package/dist/engine/xdiff/node.mjs +0 -10
  600. package/dist/engine/xdiff/upstream/LGPL-2.1 +0 -511
  601. package/dist/engine/xdiff/xdiff.wasm +0 -0
  602. package/dist/engine.d.mts +0 -3
  603. package/dist/engine.mjs +0 -3
  604. package/dist/storage/distinct-ids.mjs +0 -39
  605. package/dist/storage/held-memo.mjs +0 -188
  606. package/dist/storage/index-remap.d.mts +0 -8
  607. package/dist/sync/records.mjs +0 -73
@@ -1,32 +1,42 @@
1
+ import { gitError } from "../contracts/result.mjs";
1
2
  import { BufferMeter } from "../protocol/bytes/buffers.mjs";
2
- import { nativeSha1Hasher } from "../protocol/bytes/sha1-hasher.mjs";
3
+ import { nativeSha1Hasher, sha1Now } from "../protocol/bytes/sha1-hasher.mjs";
4
+ import { hexOf } from "../protocol/bytes/hex.mjs";
3
5
  import { fsckObject } from "../protocol/objects/fsck.mjs";
4
- import { isObjectType } from "../protocol/objects/object.mjs";
6
+ import { lfsPointerOfBlob } from "../protocol/objects/lfs-pointer.mjs";
7
+ import { isObjectType, objectHeader } from "../protocol/objects/object.mjs";
5
8
  import { DeltaError } from "../protocol/packs/delta.mjs";
6
- import { writeCommitGraph } from "../protocol/packs/graph.mjs";
7
9
  import { IndexerCache, PackIndexer } from "../protocol/packs/indexer.mjs";
8
10
  import { stepEffect } from "../protocol/packs/step.mjs";
9
- import { boundedSource, readPack } from "../protocol/packs/reader.mjs";
10
- import { writePackIndex } from "../protocol/packs/rev.mjs";
11
- import { gitError } from "../store/errors.mjs";
11
+ import { boundedSource, readPackFrom } from "../protocol/packs/reader.mjs";
12
+ import { catchSpent, ownSpentOf } from "../contracts/calls-spent.mjs";
13
+ import { bestEffort } from "../store/errors.mjs";
14
+ import { CallBudget, requestCount, spentBudget } from "../store/call-count.mjs";
12
15
  import { newChangeId } from "../store/scopes.mjs";
13
- import { bucketPut } from "./calls.mjs";
14
- import { startPut } from "./merge.mjs";
15
- import { checkedFilesRefused, checkedOverflow, fsckRefusal, receiveChecked } from "./fsck.mjs";
16
+ import { bucketPut, bucketReading, bucketStream } from "./calls.mjs";
17
+ import { packPutOptions, startPut } from "./merge.mjs";
18
+ import { repoTypes } from "./held-types.mjs";
19
+ import { checkedFilesRefused, checkedOverflow, checkedRecords, fsckRefusal, receiveChecked } from "./fsck.mjs";
16
20
  import { packFiles } from "./layout.mjs";
17
- import { ReceivedPointers } from "./lfs-pointers.mjs";
18
- import { linkReader } from "./links.mjs";
21
+ import { ReceivedPointers, pointersRecords } from "./lfs-pointers.mjs";
22
+ import { boundaryNotInPack, linkReader, segmentCut, segmentTooLarge, tagTargetMissing, wrongType } from "./links.mjs";
23
+ import { receiveWriters } from "./receive-admission.mjs";
19
24
  import { receiveLinkLimits, receiveLinks } from "./receive-links.mjs";
20
- import { rootsOf } from "./roots.mjs";
25
+ import { foundWrongly, receivedFiles } from "./receive-files.mjs";
26
+ import { joinFoundMost, mergeCallsOf, receiveCallsAfter, receiveCheckRunBytes, receiveDeferredSpillBytes, receiveSweepHeldBytes, receiveTableMost } from "./receive-bounds.mjs";
27
+ import { dropRuns, joinedRuns, mergedCursor, runWriter, stepRunKind, steppedWriter } from "./runs.mjs";
28
+ import { checkRow, checkRowAt, sweepHeld, sweepRowAt, sweepRows } from "./receive-sweep.mjs";
29
+ import { pushPackTooLarge, pushUploadMost } from "./push-uploads.mjs";
30
+ import { chainUnitsOf, receiveTable, receiveTableBytes } from "./receive-table.mjs";
31
+ import { rootsCollected } from "./roots.mjs";
21
32
  import { packFileBytes, packIndexerLimits, packObjectBytes, packReader } from "./pack-reads.mjs";
22
33
  import { dropRefused, openQuarantine, stillOpen } from "./quarantine.mjs";
23
- import { malformedPack, readFailure } from "./unpack.mjs";
34
+ import { malformedPack, ofsRefused, readFailure } from "./unpack.mjs";
35
+ import { oidBytes } from "../protocol/packs/idx.mjs";
24
36
  import * as Effect from "effect/Effect";
25
37
  import * as Result from "effect/Result";
26
38
  import * as Data from "effect/Data";
27
39
  // src/storage/pack-receive.ts
28
- /** The most objects one pack may carry into `packs()` storage: its index is built in memory. */
29
- const receiveObjectsMost = 1e5;
30
40
  /**
31
41
  * How large the reader lets an entry be: a whole one to `packFileBytes`, kept only if it's a blob.
32
42
  * Anything else, and any delta, is resolved whole, within `packObjectBytes`.
@@ -48,20 +58,93 @@ var Deferred = class extends Data.TaggedError("Deferred") {};
48
58
  const deferral = new Deferred();
49
59
  const deferring = Effect.fail(deferral);
50
60
  const isDeferred = (error) => error === deferral;
51
- /** The refusal of a push whose header counts past `receiveObjectsMost`. */
52
- const tooMany = (count) => gitError("RESOURCE_EXHAUSTED", `push has ${count.toLocaleString("en-US")} objects; this server takes ${receiveObjectsMost.toLocaleString("en-US")} per push`, {
61
+ /**
62
+ * An object's ID, its header and bytes hashed one after the other: `objectId` joins them first,
63
+ * which copies a tree of 16 MiB, checked once its pack is stored, beside the tree itself.
64
+ */
65
+ const idOf = (type, bytes) => hexOf(sha1Now([objectHeader(type, bytes.byteLength), bytes]));
66
+ /**
67
+ * The refusal of a push of `count` objects past the `most` a receive takes: `receiveTableMost`,
68
+ * or fewer in the memory a server runs in.
69
+ */
70
+ const tooMany = (count, most) => gitError("RESOURCE_EXHAUSTED", `push has ${count.toLocaleString("en-US")} objects; this server takes ${most.toLocaleString("en-US")} per push`, {
53
71
  hint: "Push fewer commits at a time",
54
72
  context: {
55
73
  reason: "too-large",
56
74
  total: count
57
75
  }
58
76
  });
59
- const ofsRefused = gitError("INVALID_ARGUMENT", "The pack has an OFS_DELTA entry", {
60
- hint: "This server takes REF_DELTA only, as its capabilities say: push with a client that doesn't send ofs-delta",
61
- context: { reason: "ofs-delta" }
77
+ /**
78
+ * The refusal of a push whose link join passed its share of the push's calls: what its count had
79
+ * left as the join began, less what its receive makes once joined. Its cause isn't the request's
80
+ * spent count, so no edge answers it again as one.
81
+ */
82
+ const joinTooLarge = ({ bound, most }) => gitError("RESOURCE_EXHAUSTED", `A push's links are checked against the repo's packs within the calls its receive has left: ${most} ${bound === "bucket" ? "bucket calls" : "subrequests"}`, {
83
+ hint: "Push fewer commits at a time, or wait a few minutes for this repo's pack merges to catch up",
84
+ hostHint: "Let git.repack run, or raise callLimits",
85
+ context: { reason: "too-large" }
86
+ });
87
+ /**
88
+ * The join's share of `counted`'s calls: what it has left of each kind as the join begins, less
89
+ * `after`, the bucket calls the receive makes once joined, and `receiveStoreCallsAfter`; or
90
+ * `undefined` for a push with no bound, as on Node, whose join makes what it needs. Left less than
91
+ * that of either kind, the receive can't finish whatever the join makes, so the push is refused
92
+ * `joinTooLarge` before it, with a share of 0: a join of no calls never spends a budget.
93
+ */
94
+ const joinBudgetOf = (counted, after) => Effect.gen(function* () {
95
+ const most = counted?.most;
96
+ if (counted === void 0 || most === void 0) return void 0;
97
+ const made = counted.made();
98
+ const bucket = most.bucket - made.bucket - after;
99
+ const subrequests = most.subrequests - made.subrequests - after - 1;
100
+ if (bucket < 0) return yield* Effect.fail(joinTooLarge({
101
+ bound: "bucket",
102
+ most: 0
103
+ }));
104
+ if (subrequests < 0) return yield* Effect.fail(joinTooLarge({
105
+ bound: "subrequests",
106
+ most: 0
107
+ }));
108
+ return yield* CallBudget.make({
109
+ bucket,
110
+ subrequests
111
+ });
62
112
  });
113
+ /**
114
+ * `join` within `budget`, which stops at it on purpose: its own spent call, when that's all that
115
+ * failed the join, is refused by name, `joinTooLarge`. Any other cause, the push's own count's
116
+ * among it, goes on whole, for its edge to answer.
117
+ */
118
+ const withinJoin = (budget, join) => {
119
+ if (budget === void 0) return join;
120
+ return catchSpent(Effect.provideService(join, CallBudget, budget), (_, cause) => {
121
+ const spent = ownSpentOf(cause, (each) => spentBudget(each) === budget);
122
+ return spent === void 0 ? Effect.failCause(cause) : Effect.fail(joinTooLarge(spent));
123
+ });
124
+ };
63
125
  const deepHint = "Repack with a lower pack.depth, such as `git repack -adf --depth=50`, then push again";
64
126
  /**
127
+ * The refusal of a pack with an entry still deferred after `receiveSweepsMost` sweeps: a push of
128
+ * fewer commits holds fewer bases to wait on.
129
+ */
130
+ const tooManySweeps = /* @__PURE__ */ gitError("RESOURCE_EXHAUSTED", `The pack's deltas need more than 2 passes to resolve`, {
131
+ hint: "Push fewer commits at a time",
132
+ context: { reason: "too-large" }
133
+ });
134
+ /** The refusal of a push whose deferred entries and holds put past `receiveDeferredSpillBytes` in a sweep. */
135
+ const deferredTooLarge = () => gitError("RESOURCE_EXHAUSTED", `This push's deltas need more than ${receiveDeferredSpillBytes.toLocaleString("en-US")} bytes of rows to wait for their bases`, {
136
+ hint: "Push fewer commits at a time",
137
+ context: { reason: "too-large" }
138
+ });
139
+ /**
140
+ * The refusal of a push whose checks after the sweeps would read its pack past the `left` calls its
141
+ * count leaves them, beside `receiveCallsAfter`.
142
+ */
143
+ const checksTooLarge = (left) => gitError("RESOURCE_EXHAUSTED", `This push's large trees and commits need more than the ${left.toLocaleString("en-US")} calls it has left to check`, {
144
+ hint: "Push fewer commits at a time",
145
+ context: { reason: "too-large" }
146
+ });
147
+ /**
65
148
  * A delta that receive resolved, from the bases it kept, but a read with nothing cached won't: one
66
149
  * more than `chainReads` entries from a whole object, or past `deltaBytes` of instructions.
67
150
  */
@@ -73,11 +156,13 @@ const tooDeep = (offset, links) => gitError("RESOURCE_EXHAUSTED", `The delta at
73
156
  const wholeHint = "Set `git config core.bigFileThreshold 16m`, run `git repack -adf`, then push again, or track the file with Git LFS";
74
157
  /**
75
158
  * A delta whose base or result is past `packObjectBytes`: Git sends one for a file it holds as a
76
- * delta, so its hint has Git hold files that size whole.
159
+ * delta, so its hint has Git hold files that size whole. Its reason is its own, not
160
+ * `object-too-large`: the same file sent whole is taken, so a pack that names its base outside it
161
+ * fails where one holding the file alone lands.
77
162
  */
78
163
  const deltaTooLarge = (offset) => gitError("RESOURCE_EXHAUSTED", `The delta at ${offset} is of an object past the ${packObjectBytes.toLocaleString("en-US")} bytes this server resolves`, {
79
164
  hint: wholeHint,
80
- context: { reason: "object-too-large" }
165
+ context: { reason: "delta-too-large" }
81
166
  });
82
167
  /** A whole object past `packObjectBytes` that isn't a file. */
83
168
  const wholeTooLarge = (offset, kind) => gitError("RESOURCE_EXHAUSTED", `The ${kind} at ${offset} is past the ${packObjectBytes.toLocaleString("en-US")} bytes this server reads whole`, { context: { reason: "object-too-large" } });
@@ -95,10 +180,11 @@ const unindexable = (offset, why) => {
95
180
  /**
96
181
  * The pack's bytes on their way to the bucket as they're read, through `startPut`, the last
97
182
  * `flushBytes` held back until the reader says where the pack ended, so a transport's flush is
98
- * never stored. A pack whose body says how long it can be puts with that as its `atMost`, so the
99
- * bucket holds a part no larger, as the push's admission counted it.
183
+ * never stored. A pack whose exact length is known puts with `size` so the bucket can send it in
184
+ * one request holding no part within its `multipart.wholeMost`; one whose body only bounds it
185
+ * puts with `atMost`, so the bucket holds a part no larger.
100
186
  */
101
- const startUpload = (bucket, key, atMost) => Effect.map(startPut(bucket, key, atMost === void 0 ? void 0 : { atMost }), (put) => {
187
+ const startUpload = (bucket, key, input) => Effect.map(startPut(bucket, key, packPutOptions(input)), (put) => {
102
188
  let held = /* @__PURE__ */ new Uint8Array(0);
103
189
  let sent = 0;
104
190
  const write = (bytes) => Effect.tap(put.write(bytes), Effect.sync(() => {
@@ -127,50 +213,23 @@ const startUpload = (bucket, key, atMost) => Effect.map(startPut(bucket, key, at
127
213
  };
128
214
  });
129
215
  /**
130
- * The type of each of `oids` the repo holds, none read whole that a header can say: a stored
131
- * pack's entry by its header, and a delta's by its base's, each level of bases one more batch. A
132
- * row, or an entry whose header won't say, is read whole, all in one batch. `loaded` keeps the
133
- * packs' indexes the entries are found by, as `has` says.
134
- */
135
- const heldTypes = Effect.fnUntraced(function* (reader, oids, loaded) {
136
- const types = /* @__PURE__ */ new Map();
137
- const whole = /* @__PURE__ */ new Map();
138
- let asked = new Map(oids.map((oid) => [oid, [oid]]));
139
- const gather = (into, at, waiting) => {
140
- const list = into.get(at);
141
- if (list === void 0) into.set(at, waiting);
142
- else for (const each of waiting) list.push(each);
143
- };
144
- for (let level = 0; asked.size > 0; level += 1) {
145
- const entries = level < packIndexerLimits.chainReads ? yield* reader.stored.find([...asked.keys()], loaded) : /* @__PURE__ */ new Map();
146
- const next = /* @__PURE__ */ new Map();
147
- for (const [oid, waiting] of asked) {
148
- const holds = entries.get(oid)?.holds;
149
- if (holds === void 0) gather(whole, oid, waiting);
150
- else if (holds.kind === "delta") gather(next, holds.base, waiting);
151
- else for (const each of waiting) types.set(each, holds.type);
152
- }
153
- asked = next;
154
- }
155
- yield* reader.each([...whole.keys()], (object) => Effect.sync(() => {
156
- for (const each of whole.get(object.oid) ?? []) types.set(each, object.type);
157
- }));
158
- return types;
159
- });
160
- /**
161
216
  * A push's pack into the bucket under a new `quarantine` row and marker, indexed as it streams:
162
217
  * each entry resolved and hashed by the pack indexer, OFS_DELTA refused, every object but a blob
163
218
  * checked as Git's fsck checks it and parsed for what it names, the `.gitmodules` and
164
219
  * `.gitattributes` its trees name checked, and everything named outside the pack held by the repo,
165
220
  * but a shallow client's commit's parents, refused as `shallowRoot` when the repo lacks them. Each
166
- * object named, the pack's or the repo's, is of the type its link says, as `heldTypes` reads the
221
+ * object named, the pack's or the repo's, is of the type its link says, as `repoTypes` reads the
167
222
  * repo's. A delta whose base the indexer no longer holds is indexed again once the pack is stored.
168
- * Its `.idx`, `.rev`, `.pos` and `.graph` go after it, then its row is read again, as `stillOpen` says.
169
- * A refused pack's marker, files and row are deleted before the refusal, as `dropRefused` says.
223
+ * Its `.idx`, `.rev`, `.pos`, `.graph` and `.types` go after it, then its row is read again, as
224
+ * `stillOpen` says. A refused pack's runs, then its marker, files and row, are deleted before the
225
+ * refusal, as `dropRefused` says. Runs it can't delete keep the row, so clean-up ends them at its
226
+ * `removeAt`.
170
227
  */
171
- const receivePack = Effect.fnUntraced(function* (input) {
228
+ const receivePack = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
172
229
  const { store, bucket, listed, at, prune, receive } = input;
173
- if (receive.objects > 1e5) return yield* Effect.fail(tooMany(receive.objects));
230
+ if (receive.objects > receiveTableMost) return yield* Effect.fail(tooMany(receive.objects, receiveTableMost));
231
+ const past = segmentTooLarge(receive);
232
+ if (past !== void 0) return yield* Effect.fail(past);
174
233
  const opened = yield* openQuarantine({
175
234
  store,
176
235
  bucket,
@@ -178,16 +237,70 @@ const receivePack = Effect.fnUntraced(function* (input) {
178
237
  at,
179
238
  prune
180
239
  });
181
- return yield* storePack(input, opened).pipe(Effect.onError(() => dropRefused({
240
+ const stored = yield* storeOrDrop(input, opened);
241
+ return "paused" in stored ? yield* Effect.die(/* @__PURE__ */ new Error("a whole receive paused")) : stored;
242
+ });
243
+ /** `storePack` with a refused pack's runs, marker, files and row deleted. */
244
+ const storeOrDrop = (input, opened) => {
245
+ const { store, bucket, indexes, listed } = input;
246
+ return Effect.scoped(storePack(input, opened)).pipe(Effect.onError(() => bestEffort(Effect.andThen(dropRuns(bucket, opened.pack), dropRefused({
182
247
  store,
183
248
  bucket,
249
+ indexes,
184
250
  repo: listed.repo,
185
251
  pack: opened.pack
186
- })));
252
+ })))));
253
+ };
254
+ /**
255
+ * A step of `receivePack` under the quarantine `opened` for the run: the staged pack read on from
256
+ * where the step before it paused, to its end, as `receivePack` stores it, or to where it pauses.
257
+ * A step that fails deletes nothing: its record names its keys, and the run's end or the sweep
258
+ * deletes them, so a try after it goes on from the last commit.
259
+ */
260
+ const storeStep = (input, opened, step) => Effect.scoped(storePack(input, opened, step));
261
+ /** A staged pack's hash, its trailer as staging checked it: each step reads only some of it. */
262
+ const stagedHash = (checksum) => ({
263
+ write: () => Effect.void,
264
+ digest: Effect.sync(() => oidBytes(checksum))
265
+ });
266
+ /** The deferred and checks runs a joining step carries: none, as the sweeps and checks took them. */
267
+ const spentRuns = {
268
+ deferred: joinedRuns("deferred", 12, []),
269
+ checks: joinedRuns("checks", 4, [])
270
+ };
271
+ /**
272
+ * A step's put of a file, or, when a try whose result was lost had put it already, the same bytes
273
+ * found there, read back a piece at a time against `bytes` so a replay holds no copy. A file there
274
+ * with other bytes is still refused `ALREADY_EXISTS`.
275
+ */
276
+ const putAgain = (bucket, key, bytes, put) => put.pipe(Effect.catchIf((error) => error.code === "ALREADY_EXISTS", (error) => Effect.flatMap(sameFile(bucket, key, bytes), (same) => same ? Effect.void : Effect.fail(error))));
277
+ /** Whether the file at `key` holds exactly `bytes`. */
278
+ const sameFile = (bucket, key, bytes) => bucketReading(bucket, key, void 0, async (body) => {
279
+ if (body === void 0) return false;
280
+ const reader = body.getReader();
281
+ let at = 0;
282
+ for (let piece = await reader.read(); !piece.done; piece = await reader.read()) {
283
+ const { value } = piece;
284
+ if (at + value.byteLength > bytes.byteLength || value.some((byte, index) => byte !== bytes[at + index])) {
285
+ await reader.cancel();
286
+ return false;
287
+ }
288
+ at += value.byteLength;
289
+ }
290
+ return at === bytes.byteLength;
187
291
  });
188
292
  /** The pack's bytes and files under its opened row, as `receivePack` says. */
189
- const storePack = Effect.fnUntraced(function* (input, opened) {
293
+ const storePack = /* @__PURE__ */ Effect.fnUntraced(function* (input, opened, step) {
190
294
  const { store, bucket, indexes, listed, receive, memory } = input;
295
+ const carried = step?.carried;
296
+ const joining = carried?.state.joining;
297
+ const stepOf = (step, carry) => ({
298
+ step: step.step,
299
+ attempt: step.attempt,
300
+ ...carry !== void 0 && { carried: carry }
301
+ });
302
+ const { room } = memory;
303
+ const writers = receiveWriters(receive.objects, receive.needs?.length ?? 0);
191
304
  const files = packFiles(opened.pack);
192
305
  const reading = {
193
306
  store,
@@ -198,106 +311,242 @@ const storePack = Effect.fnUntraced(function* (input, opened) {
198
311
  };
199
312
  if (input.visible !== void 0) reading.visible = input.visible;
200
313
  const reader = packReader(reading);
201
- const upload = yield* startUpload(bucket, files.pack, receive.atMost);
202
- let stored;
203
- const offsets = /* @__PURE__ */ new Map();
204
- const objects = [];
205
- const deferred = [];
206
- const unchecked = [];
314
+ const counted = yield* requestCount;
315
+ const upload = step === void 0 ? yield* startUpload(bucket, files.pack, receive) : void 0;
316
+ const recordOf = (oid) => {
317
+ const slot = state.table?.find(oid);
318
+ return slot === void 0 || state.table?.awaitedAt(slot) !== void 0 ? void 0 : slot;
319
+ };
320
+ const received = receivedFiles(bucket, opened.pack, {
321
+ objects: receive.objects,
322
+ needs: receive.needs?.length ?? 0,
323
+ room,
324
+ ...step && { step: stepOf(step, carried?.state.received) }
325
+ });
326
+ const deferredWriting = {
327
+ first: writers.deferred.first,
328
+ room,
329
+ spill: {
330
+ most: receiveDeferredSpillBytes,
331
+ tooLarge: deferredTooLarge
332
+ }
333
+ };
334
+ const state = {
335
+ stored: void 0,
336
+ table: void 0,
337
+ filled: [],
338
+ deferred: steppedWriter(bucket, opened.pack, "deferred", 12, deferredWriting, step && {
339
+ ...step,
340
+ ...carried && { before: carried.state.deferred }
341
+ }),
342
+ deferrals: carried?.state.deferrals ?? 0,
343
+ walked: carried?.state.walked,
344
+ checksMost: void 0,
345
+ sweepAt: void 0,
346
+ held: void 0,
347
+ tagged: new Map(carried?.state.tagged),
348
+ beyond: new Set(carried?.state.beyond),
349
+ linkedPacks: new Set(carried?.state.linkedPacks),
350
+ linkedRows: new Set(carried?.state.linkedRows),
351
+ count: carried?.state.count ?? 0,
352
+ parents: new Set(carried?.state.parents),
353
+ large: new Map(carried?.state.large),
354
+ cut: segmentCut(receive.cutMost, carried?.state.cut)
355
+ };
356
+ if (carried !== void 0) {
357
+ yield* room.take(receiveTableBytes(carried.state.count)) ?? Effect.void;
358
+ state.table = carried.table;
359
+ }
360
+ const rows = sweepRows();
361
+ const checks = steppedWriter(bucket, opened.pack, "checks", 4, {
362
+ bytes: receiveCheckRunBytes,
363
+ first: writers.checks.first,
364
+ room
365
+ }, step && {
366
+ ...step,
367
+ ...carried && { before: carried.state.checks }
368
+ });
207
369
  const shallow = new Set(receive.shallow);
208
370
  const partial = receive.partial === true;
209
- const loaded = /* @__PURE__ */ new Map();
210
- const linkedPacks = /* @__PURE__ */ new Set();
211
- const linkedRows = /* @__PURE__ */ new Set();
212
- const links = receiveLinks({
213
- has: (oids) => Effect.map(reader.heldIn(oids, loaded), (there) => {
214
- for (const [oid, pack] of there) if (pack === void 0) linkedRows.add(oid);
215
- else linkedPacks.add(pack);
216
- return new Set(there.keys());
217
- }),
218
- typesOf: (oids) => heldTypes(reader, oids, loaded)
219
- }, receiveLinkLimits, memory.memo);
220
- let count = 0;
221
- const open = () => count - objects.length;
222
- const parents = /* @__PURE__ */ new Set();
223
- const types = /* @__PURE__ */ new Map();
224
- const checked = receiveChecked();
225
- const commits = [];
226
- const chains = /* @__PURE__ */ new Map();
227
- const deltaSizes = /* @__PURE__ */ new Map();
228
- const large = /* @__PURE__ */ new Map();
371
+ const boundary = new Set(joining === void 0 ? receive.boundary : []);
372
+ yield* room.take(boundary.size * 120) ?? Effect.void;
373
+ const named = !partial && new Set(receive.boundary).size === 0;
374
+ const typesHeld = repoTypes({
375
+ ...reading,
376
+ memory: memory.join,
377
+ reader
378
+ });
379
+ const linkedTypes = (there) => {
380
+ const types = /* @__PURE__ */ new Map();
381
+ for (const [oid, { pack, type }] of there) {
382
+ if (pack === void 0) state.linkedRows.add(oid);
383
+ else state.linkedPacks.add(pack);
384
+ types.set(oid, type);
385
+ }
386
+ return types;
387
+ };
388
+ const links = receiveLinks(bucket, opened.pack, {
389
+ held: (oids) => Effect.map(typesHeld.held(oids), linkedTypes),
390
+ beyond: (oids) => Effect.map(typesHeld.beyond(oids), linkedTypes)
391
+ }, receiveLinkLimits, {
392
+ first: writers.links.first,
393
+ room
394
+ }, step && stepOf(step, carried?.state.links));
395
+ const checked = carried?.checked ?? receiveChecked();
229
396
  const pointers = memory.pointers;
230
397
  const indexer = new PackIndexer({
231
- entryAt: (offset, before) => stored === void 0 ? deferring : reader.blocks.entryAt(stored, offset, before),
398
+ entryAt: (offset, before) => {
399
+ if (state.stored === void 0 || state.sweepAt !== void 0 && offset !== state.sweepAt) return deferring;
400
+ const most = state.checksMost;
401
+ return most !== void 0 && counted !== void 0 && !reader.blocks.keeps(state.stored, offset) && counted.made().bucket >= most.made ? Effect.fail(checksTooLarge(most.left)) : reader.blocks.entryAt(state.stored, offset, before);
402
+ },
232
403
  offsetOf: (oid) => {
233
- const found = offsets.get(oid);
234
- if (found !== void 0) return found;
235
- return stored === void 0 && deferred.length > 0 ? deferring : void 0;
404
+ const slot = recordOf(oid);
405
+ if (slot !== void 0) return state.table?.offsetAt(slot);
406
+ return state.deferrals > 0 && (state.stored === void 0 || state.sweepAt !== void 0) ? deferring : void 0;
236
407
  },
237
- allot: memory.outside
408
+ allot: memory.outside,
409
+ held: (offset) => state.held?.get(offset)
238
410
  }, packIndexerLimits, new IndexerCache(memory.cache));
239
411
  const malformedDelta = (error) => malformedPack(error.message);
240
412
  /**
241
- * An object's fsck, its links, and a commit's parents for the `.graph`: every object but a
242
- * blob's. A tree's `.gitmodules` and `.gitattributes` go in `checked`.
413
+ * The pack's own object `oid`, as the table finds it by its hash: its slot, with a found row so
414
+ * the merge checks it is that ID's, `linked` when a link names it, or `undefined` when the pack
415
+ * brought none by that hash.
243
416
  */
244
- const check = Effect.fnUntraced(function* (oid, type, offset) {
245
- const resolved = yield* stepEffect(indexer.resolve(offset));
246
- if (resolved.kind === "unindexable") return yield* Effect.fail(unindexable(offset, resolved.why));
247
- const { bytes } = resolved.object;
417
+ const ownSlot = (oid, linked = false) => {
418
+ const slot = recordOf(oid);
419
+ if (slot === void 0 || state.table === void 0) return void 0;
420
+ const noted = received.found(oid, state.table.offsetAt(slot), linked);
421
+ return noted === void 0 ? slot : Effect.as(noted, slot);
422
+ };
423
+ /**
424
+ * Whether the record at `slot` is `oid`'s: its object resolved and named again. A refusal that
425
+ * rests on the table's answer is made only once this says so; else the push is refused
426
+ * `foundWrongly`, as the merge of its found rows would refuse it. An object the indexer can't
427
+ * resolve whole, or not yet, is taken as the table says.
428
+ */
429
+ const isOwn = Effect.fnUntraced(function* (oid, slot) {
430
+ if (state.table === void 0) return false;
431
+ const resolved = yield* stepEffect(indexer.resolve(state.table.offsetAt(slot))).pipe(Effect.catchIf(isDeferred, () => Effect.succeed(void 0)), Effect.catchIf((error) => error instanceof DeltaError, (error) => Effect.fail(malformedDelta(error))));
432
+ if (resolved === void 0 || resolved.kind === "unindexable") return true;
433
+ const { kind, bytes } = resolved.object;
434
+ return idOf(kind, bytes) === oid;
435
+ });
436
+ const ownTypeAt = (oid, slot, said) => {
437
+ if (slot === void 0 || state.table === void 0) return void 0;
438
+ const type = state.table.typeAt(slot);
439
+ if (said === void 0 || type === said) return type;
440
+ return Effect.flatMap(isOwn(oid, slot), (own) => own ? Effect.succeed(type) : Effect.fail(foundWrongly));
441
+ };
442
+ /**
443
+ * The type of the pack's own object `oid`, found as `ownSlot` finds it. One that isn't `said`,
444
+ * the type a link gives it, is checked to be `oid`'s before a refusal rests on it.
445
+ */
446
+ const ownType = (oid, said) => {
447
+ const slot = ownSlot(oid, said !== void 0);
448
+ return Effect.isEffect(slot) ? Effect.flatMap(slot, (at) => stepEffect(ownTypeAt(oid, at, said))) : ownTypeAt(oid, slot, said);
449
+ };
450
+ /**
451
+ * A delta's refusal as its instructions don't fit its base: `foundWrongly` when the base the table
452
+ * found isn't the one it names, so a hash matched wrongly is never taken for a malformed pack.
453
+ */
454
+ const deltaRefused = Effect.fnUntraced(function* (ended, error) {
455
+ const slot = ended.base?.kind === "oid" ? recordOf(ended.base.oid) : void 0;
456
+ if (ended.base?.kind === "oid" && slot !== void 0 && !(yield* isOwn(ended.base.oid, slot))) return yield* Effect.fail(foundWrongly);
457
+ return yield* Effect.fail(error);
458
+ });
459
+ const checkBytesFrom = (oid, type, next, shallowCommit, boundaryCommit, graphed, from) => {
460
+ for (let at = from;; at += 1) {
461
+ const read = next();
462
+ if (Result.isFailure(read)) return Effect.fail(read.failure);
463
+ const link = read.success;
464
+ if (link === void 0) break;
465
+ if (type === "commit" && at > 0) graphed.push(link.oid);
466
+ if (shallowCommit && at > 0) state.parents.add(link.oid);
467
+ else if (boundaryCommit && at > 0) {
468
+ const past = state.cut.add(oid, link.oid);
469
+ if (past !== void 0) return Effect.fail(past);
470
+ if (state.beyond.has(link.oid)) continue;
471
+ state.beyond.add(link.oid);
472
+ const taken = room.take(120);
473
+ if (taken !== void 0) return Effect.flatMap(taken, () => stepEffect(checkBytesFrom(oid, type, next, shallowCommit, boundaryCommit, graphed, at + 1)));
474
+ } else if (!partial || type === "tag") {
475
+ if (partial) state.tagged.set(link.oid, oid);
476
+ const put = links.link(link);
477
+ if (put !== void 0) return Effect.flatMap(put, () => stepEffect(checkBytesFrom(oid, type, next, shallowCommit, boundaryCommit, graphed, at + 1)));
478
+ }
479
+ }
480
+ if (type === "commit") {
481
+ const committed = received.commit(oid, graphed);
482
+ if (committed !== Effect.void) return committed;
483
+ }
484
+ };
485
+ /**
486
+ * An object's fsck, its links, and a commit's parents for the `.graph`, from its `bytes`: every
487
+ * object but a blob's. A tree's `.gitmodules` and `.gitattributes` go in `checked`.
488
+ */
489
+ const checkBytes = (oid, type, bytes) => {
248
490
  const fault = fsckObject({
249
491
  oid,
250
492
  type,
251
493
  bytes
252
494
  }, checked);
253
- if (fault !== void 0) return yield* Effect.fail(fsckRefusal(oid, fault));
495
+ if (fault !== void 0) return Effect.fail(fsckRefusal(oid, fault));
254
496
  const overflow = checkedOverflow(checked);
255
- if (overflow !== void 0) return yield* Effect.fail(overflow);
497
+ if (overflow !== void 0) return Effect.fail(overflow);
256
498
  const shallowCommit = type === "commit" && shallow.has(oid);
499
+ const boundaryCommit = type === "commit" && boundary.has(oid);
257
500
  const graphed = [];
258
501
  const next = linkReader({
259
502
  oid,
260
503
  type,
261
504
  bytes
262
505
  });
263
- for (let at = 0;; at += 1) {
264
- const read = next();
265
- if (Result.isFailure(read)) return yield* Effect.fail(read.failure);
266
- const link = read.success;
267
- if (link === void 0) break;
268
- if (type === "commit" && at > 0) graphed.push(link.oid);
269
- if (shallowCommit && at > 0) parents.add(link.oid);
270
- else if (!partial) {
271
- const asked = links.link(link, types.get(link.oid), open());
272
- if (asked !== void 0) yield* asked;
273
- }
274
- }
275
- if (type === "commit") commits.push({
276
- oid,
277
- parents: graphed
278
- });
506
+ return checkBytesFrom(oid, type, next, shallowCommit, boundaryCommit, graphed, 0);
507
+ };
508
+ const checkResolved = (oid, type, offset, resolved) => resolved.kind === "unindexable" ? Effect.fail(unindexable(offset, resolved.why)) : checkBytes(oid, type, resolved.object.bytes);
509
+ /** The object at `offset`, `oid` of `type`, checked as `checkBytes` says, or deferred for sweeps. */
510
+ const check = (oid, type, offset) => {
511
+ const resolved = indexer.resolve(offset);
512
+ if (Effect.isEffect(resolved)) return resolved.pipe(Effect.flatMap((done) => stepEffect(checkResolved(oid, type, offset, done))), Effect.catchIf(isDeferred, () => checks.add(checkRow(offset, type)) ?? Effect.void));
513
+ return checkResolved(oid, type, offset, resolved);
514
+ };
515
+ /** A check that waited for the sweeps: the object at `offset`, its ID hashed again from its bytes. */
516
+ const checkAt = Effect.fnUntraced(function* (offset, type) {
517
+ const resolved = yield* stepEffect(indexer.resolve(offset));
518
+ if (resolved.kind === "unindexable") return yield* Effect.fail(unindexable(offset, resolved.why));
519
+ const { bytes } = resolved.object;
520
+ const checkedBytes = checkBytes(idOf(type, bytes), type, bytes);
521
+ if (checkedBytes !== void 0) yield* checkedBytes;
279
522
  });
523
+ const readPointerResolved = (oid, offset, resolved) => {
524
+ if (resolved.kind === "unindexable") return Effect.fail(unindexable(offset, resolved.why));
525
+ if (lfsPointerOfBlob(resolved.object.bytes) === void 0) return void 0;
526
+ return pointers.add(oid, resolved.object.bytes);
527
+ };
280
528
  /**
281
529
  * Lists a small blob as a pointer if it reads as one. Its bytes are in the indexer's cache: an
282
530
  * object within a quarter of its 32 MiB is remembered as its entry ends, which this follows.
283
531
  */
284
- const readPointer = Effect.fnUntraced(function* (oid, offset) {
285
- const resolved = yield* stepEffect(indexer.resolve(offset)).pipe(Effect.catchIf(isDeferred, () => Effect.die(/* @__PURE__ */ new Error("a pointer's blob left the indexer's cache as it settled"))));
286
- if (resolved.kind === "unindexable") return yield* Effect.fail(unindexable(offset, resolved.why));
287
- yield* pointers.add(oid, resolved.object.bytes);
288
- });
289
- /** A delta's chain: its base's, one longer. Its base is before it, so it's settled already. */
290
- const chainOf = (offset, base) => {
291
- const size = deltaSizes.get(offset);
292
- if (size === void 0) throw new Error("a delta settled with no size");
293
- deltaSizes.delete(offset);
294
- const below = chains.get(base) ?? {
295
- links: 0,
296
- bytes: 0
297
- };
532
+ const readPointer = (oid, offset) => {
533
+ const resolved = indexer.resolve(offset);
534
+ if (Effect.isEffect(resolved)) return resolved.pipe(Effect.catchIf(isDeferred, () => Effect.die(/* @__PURE__ */ new Error("a pointer's blob left the indexer's cache as it settled"))), Effect.flatMap((done) => stepEffect(readPointerResolved(oid, offset, done))));
535
+ return readPointerResolved(oid, offset, resolved);
536
+ };
537
+ /**
538
+ * A delta's chain: its base's, one longer, its instructions counted in `chainUnitBytes` rounded
539
+ * up, and its base's slot. Its base is before it, so it's settled already.
540
+ */
541
+ const chainOf = (records, base, size) => {
542
+ const slot = recordOf(base);
543
+ if (slot === void 0) throw new Error("a delta settled on a base the table lacks");
544
+ const below = records.chainAt(slot);
545
+ const units = below.units + chainUnitsOf(size);
298
546
  return {
299
547
  links: below.links + 1,
300
- bytes: below.bytes + size
548
+ units,
549
+ base: slot
301
550
  };
302
551
  };
303
552
  /**
@@ -305,59 +554,115 @@ const storePack = Effect.fnUntraced(function* (input, opened) {
305
554
  * listed as it is, never read whole; anything else refuses the push.
306
555
  */
307
556
  const placed = (indexed, ended) => {
308
- const whole = large.get(indexed.offset);
557
+ const whole = state.large.get(indexed.offset);
309
558
  if (whole === void 0 || indexed.oid === void 0) return Effect.fail(unindexable(indexed.offset, indexed.why));
310
559
  const { kind, size } = whole;
311
560
  if (kind !== "blob") return Effect.fail(wholeTooLarge(indexed.offset, kind));
312
- const object = {
313
- oid: indexed.oid,
314
- offset: indexed.offset,
315
- crc32: ended.crc32
316
- };
317
- return Effect.succeed({
561
+ return {
318
562
  kind: "indexed",
319
- object,
563
+ object: {
564
+ oid: indexed.oid,
565
+ offset: indexed.offset,
566
+ crc32: ended.crc32
567
+ },
320
568
  type: kind,
321
569
  size,
322
570
  base: void 0
571
+ };
572
+ };
573
+ const settleAfterObject = (recorded, indexed, chain, until) => {
574
+ const { object, type } = indexed;
575
+ if (until !== void 0 && state.held !== void 0) state.filled.push({
576
+ offset: object.offset,
577
+ until
323
578
  });
579
+ const slot = recorded.add(object.oid, object.offset, type);
580
+ if (chain !== void 0) recorded.setChain(slot, chain.links, chain.units, chain.base);
581
+ if (type === "blob") return ReceivedPointers.mayHold(indexed.size) ? readPointer(object.oid, object.offset) : void 0;
582
+ return check(object.oid, type, object.offset);
324
583
  };
325
- const settle = Effect.fnUntraced(function* (given, ended) {
326
- const indexed = given.kind === "unindexable" ? yield* placed(given, ended) : given;
584
+ const settleObject = (recorded, indexed, chain, until) => {
327
585
  const { object, type } = indexed;
328
- if (indexed.base !== void 0) {
329
- const chain = chainOf(object.offset, indexed.base);
586
+ const added = received.object(object.oid, object.offset, object.crc32, type);
587
+ return added === void 0 ? settleAfterObject(recorded, indexed, chain, until) : Effect.flatMap(added, () => stepEffect(settleAfterObject(recorded, indexed, chain, until)));
588
+ };
589
+ const settleChecked = (recorded, indexed, chain) => {
590
+ const { object } = indexed;
591
+ const waiting = recorded.find(object.oid);
592
+ const until = waiting === void 0 ? void 0 : recorded.awaitedAt(waiting);
593
+ if (waiting !== void 0 && until === void 0) return Effect.flatMap(isOwn(object.oid, waiting), (own) => own ? Effect.fail(malformedPack(`${object.oid} is listed twice`)) : stepEffect(settleObject(recorded, indexed, chain, until)));
594
+ return settleObject(recorded, indexed, chain, until);
595
+ };
596
+ const settle = (given, ended) => {
597
+ const recorded = state.table;
598
+ if (recorded === void 0) return Effect.die(/* @__PURE__ */ new Error("an entry settled unheaded"));
599
+ const indexed = given.kind === "unindexable" ? placed(given, ended) : given;
600
+ if (Effect.isEffect(indexed)) return indexed;
601
+ const { object } = indexed;
602
+ const base = indexed.base === void 0 || ended.base?.kind !== "oid" ? void 0 : {
603
+ oid: ended.base.oid,
604
+ offset: indexed.base
605
+ };
606
+ const chain = base === void 0 ? void 0 : chainOf(recorded, base.oid, ended.size);
607
+ if (base !== void 0 && chain !== void 0) {
330
608
  const { chainReads, deltaBytes } = packIndexerLimits;
331
- if (chain.links >= chainReads || chain.bytes > deltaBytes) return yield* Effect.fail(tooDeep(object.offset, chain.links));
332
- chains.set(object.offset, chain);
609
+ if (chain.links >= chainReads || chain.units * 4096 > deltaBytes) return Effect.fail(tooDeep(object.offset, chain.links));
610
+ const based = received.found(base.oid, base.offset);
611
+ if (based !== void 0) return Effect.flatMap(based, () => stepEffect(settleChecked(recorded, indexed, chain)));
333
612
  }
334
- objects.push(object);
335
- offsets.set(object.oid, object.offset);
336
- types.set(object.oid, type);
337
- const asked = links.arrived(object.oid, type, open());
338
- if (asked !== void 0) yield* asked;
339
- if (type === "blob") {
340
- if (ReceivedPointers.mayHold(indexed.size)) yield* readPointer(object.oid, object.offset);
341
- return;
613
+ return settleChecked(recorded, indexed, chain);
614
+ };
615
+ /**
616
+ * An entry deferred, as it streamed or in a sweep: its row for the next sweep, and a hold on each
617
+ * base of its chain the table has, from its base down to a whole object. Its base is held until
618
+ * the entry, and each base below until the one it makes: once that's held, it isn't needed.
619
+ */
620
+ const deferEntry = Effect.fnUntraced(function* (ended) {
621
+ state.deferrals += 1;
622
+ const put = state.deferred.add(rows.deferred(ended.offset, ended.compressed, ended.crc32));
623
+ if (put !== void 0) yield* put;
624
+ const records = state.table;
625
+ const base = ended.base?.kind === "oid" ? ended.base.oid : void 0;
626
+ let slot = base === void 0 ? void 0 : recordOf(base);
627
+ if (records !== void 0 && base !== void 0 && slot === void 0) return records.awaited(base, ended.offset) ? void 0 : yield* Effect.fail(unindexable(ended.offset, "base not before"));
628
+ const sibling = slot !== void 0 && slot === state.walked;
629
+ state.walked = slot;
630
+ for (let link = 0, until = ended.offset; records !== void 0 && slot !== void 0; link += 1) {
631
+ if (link > 63) return yield* Effect.die(/* @__PURE__ */ new Error("a chain past its most links"));
632
+ const offset = records.offsetAt(slot);
633
+ const holding = state.deferred.add(rows.hold(offset, until));
634
+ if (holding !== void 0) yield* holding;
635
+ if (sibling) break;
636
+ const chain = records.chainAt(slot);
637
+ slot = chain.links === 0 ? void 0 : chain.base;
638
+ until = offset;
342
639
  }
343
- yield* check(object.oid, type, object.offset).pipe(Effect.catchIf(isDeferred, () => {
344
- unchecked.push({
345
- oid: object.oid,
346
- type,
347
- offset: object.offset
348
- });
349
- return Effect.void;
350
- }));
351
640
  });
641
+ /** An entry's end, as it streamed or in a sweep: settled, deferred, or its delta refused. */
642
+ const entryEnded = (ended) => {
643
+ const indexed = indexer.entryEnd(ended);
644
+ if (Effect.isEffect(indexed)) return indexed.pipe(Effect.matchEffect({
645
+ onFailure: (error) => {
646
+ if (error instanceof DeltaError) return deltaRefused(ended, error);
647
+ return isDeferred(error) ? deferEntry(ended) : Effect.fail(error);
648
+ },
649
+ onSuccess: (done) => stepEffect(settle(done, ended))
650
+ }));
651
+ return settle(indexed, ended);
652
+ };
352
653
  const sink = {
353
654
  begin: (header) => {
354
- count = header.count;
355
- return count > 1e5 ? Effect.fail(tooMany(count)) : Effect.void;
655
+ state.count = header.count;
656
+ if (state.count > receiveTableMost) return Effect.fail(tooMany(state.count, receiveTableMost));
657
+ const sizing = room.take(receiveTableBytes(state.count)) ?? Effect.void;
658
+ return Effect.map(sizing, () => {
659
+ state.table = receiveTable(state.count);
660
+ });
356
661
  },
357
662
  entry: (entry) => {
358
663
  if (entry.kind === "ofs") return Effect.fail(ofsRefused);
359
- if (entry.kind === "ref") deltaSizes.set(entry.offset, entry.size);
360
- if (isObjectType(entry.kind) && entry.size > 16777216) large.set(entry.offset, {
664
+ if (entry.offset >= pushUploadMost) return Effect.fail(pushPackTooLarge);
665
+ if (isObjectType(entry.kind) && entry.size > 16777216) state.large.set(entry.offset, {
361
666
  kind: entry.kind,
362
667
  size: entry.size
363
668
  });
@@ -367,83 +672,361 @@ const storePack = Effect.fnUntraced(function* (input, opened) {
367
672
  data: (bytes) => {
368
673
  indexer.data(bytes);
369
674
  },
370
- entryEnd: (ended) => stepEffect(indexer.entryEnd(ended)).pipe(Effect.matchEffect({
371
- onFailure: (error) => {
372
- if (!isDeferred(error)) return Effect.fail(error);
373
- deferred.push(ended);
374
- return Effect.void;
375
- },
376
- onSuccess: (indexed) => settle(indexed, ended)
377
- }))
675
+ entryEnd: (ended) => {
676
+ const done = entryEnded(ended);
677
+ if (step === void 0) return done;
678
+ const pauseAfter = () => ended.index + 1 < state.count && step.pause(ended.index + 1, ended.offset + ended.compressed) ? "pause" : void 0;
679
+ return done === void 0 ? pauseAfter() : Effect.map(done, pauseAfter);
680
+ }
378
681
  };
682
+ /** At a step's pause, what it carries to the next: each writer's runs put, and what it holds. */
683
+ const carryOut = Effect.fnUntraced(function* (resume, ended) {
684
+ const table = state.table;
685
+ if (table === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("a step paused before its header"));
686
+ const [head, slots] = table.toBytes();
687
+ const found = pointers.finish();
688
+ return { paused: {
689
+ state: {
690
+ resume,
691
+ table: head,
692
+ count: state.count,
693
+ deferrals: state.deferrals,
694
+ ...state.walked !== void 0 && { walked: state.walked },
695
+ deferred: ended === void 0 ? yield* state.deferred.finish : spentRuns.deferred,
696
+ checks: ended === void 0 ? yield* checks.finish : spentRuns.checks,
697
+ received: yield* received.carry,
698
+ links: yield* links.carry,
699
+ cut: state.cut.carry(),
700
+ checked: {
701
+ count: checked.size(),
702
+ overflowed: checked.overflowed()
703
+ },
704
+ pointers: found.count,
705
+ tagged: [...state.tagged],
706
+ beyond: [...state.beyond],
707
+ linkedPacks: [...state.linkedPacks],
708
+ linkedRows: [...state.linkedRows],
709
+ parents: [...state.parents],
710
+ large: [...state.large],
711
+ ...ended && { joining: {
712
+ leftOut: ended.leftOut,
713
+ otherRuns: ended.otherRuns
714
+ } }
715
+ },
716
+ table: slots,
717
+ pointers: pointersRecords(found),
718
+ checked: checkedRecords(checked)
719
+ } };
720
+ });
379
721
  const meter = new BufferMeter(readerBytes);
380
- const body = boundedSource(receive.pack, /* @__PURE__ */ new Uint8Array(0), meter);
381
- const teed = { read: body.read.pipe(Effect.mapError(readFailure), Effect.tap((piece) => piece === void 0 ? Effect.void : upload.send(piece))) };
382
- const read = yield* Effect.gen(function* () {
383
- const read = yield* readPack(teed, nativeSha1Hasher(), sink, receiveLimits, meter).pipe(Effect.mapError((error) => error instanceof DeltaError ? malformedDelta(error) : readFailure(error)), Effect.ensuring(body.cancel));
384
- yield* upload.finish(read.bytes);
722
+ const resume = carried?.state.resume;
723
+ const staged = step === void 0 || joining !== void 0 ? void 0 : yield* bucketStream(bucket, files.pack, {
724
+ offset: resume?.offset ?? 0,
725
+ length: step.staged.bytes - (resume?.offset ?? 0)
726
+ });
727
+ if (step !== void 0 && joining === void 0 && staged === void 0) return yield* Effect.fail(gitError("FAILED_PRECONDITION", `A receive's staged pack has no bytes at ${files.pack}`, {
728
+ hint: "Clean-up ended its quarantine: stage the segment again",
729
+ context: { reason: "stage-gone" }
730
+ }));
731
+ const body = boundedSource(staged ?? receive.pack, /* @__PURE__ */ new Uint8Array(0), meter);
732
+ const teed = { read: body.read.pipe(Effect.mapError(readFailure), Effect.tap((piece) => piece === void 0 || upload === void 0 ? Effect.void : upload.send(piece))) };
733
+ const hasher = step === void 0 ? nativeSha1Hasher() : stagedHash(step.staged.checksum);
734
+ const indexed = Effect.gen(function* () {
735
+ const read = yield* readPackFrom(teed, hasher, sink, receiveLimits, meter, resume).pipe(Effect.mapError((error) => error instanceof DeltaError ? malformedDelta(error) : readFailure(error)), Effect.ensuring(body.cancel));
736
+ if (upload !== void 0 && !("paused" in read)) yield* upload.finish(read.bytes);
385
737
  return read;
386
- }).pipe(Effect.onError(() => upload.abort));
387
- const pack = {
388
- id: opened.pack,
389
- bytes: read.bytes
390
- };
391
- stored = pack;
392
- yield* Effect.gen(function* () {
393
- for (const ended of deferred) {
394
- const entry = yield* reader.blocks.entryAt(pack, ended.offset, (each) => memory.outside(each.size));
395
- if (entry === "too big") return yield* Effect.fail(unindexable(ended.offset, "too big"));
396
- yield* stepEffect(indexer.entry(entry.entry));
738
+ }).pipe(Effect.onError(() => upload?.abort ?? Effect.void));
739
+ /**
740
+ * What follows the body's last byte in the step that read it: the sweeps, the checks, the
741
+ * boundary and cut, and the needs linked. It hands on what the join needs, to `joinEnd` at once
742
+ * in one invocation, or in the carry to the joining step.
743
+ */
744
+ const bodyEnd = Effect.fnUntraced(function* (read) {
745
+ const pack = {
746
+ id: opened.pack,
747
+ bytes: read.bytes
748
+ };
749
+ state.stored = pack;
750
+ /** A deferred entry read again in a sweep: its header, its data, then its end as it streamed. */
751
+ const sweepEntry = Effect.fnUntraced(function* (row) {
752
+ const entry = yield* reader.blocks.entryAt(pack, row.offset, (each) => memory.outside(each.size));
753
+ if (entry === "too big") return yield* Effect.fail(unindexable(row.offset, "too big"));
754
+ const ended = {
755
+ ...entry.entry,
756
+ compressed: row.compressed,
757
+ crc32: row.crc32
758
+ };
759
+ const entered = indexer.entry(entry.entry);
760
+ if (entered !== void 0) yield* entered;
397
761
  indexer.data(entry.data);
398
- yield* settle(yield* stepEffect(indexer.entryEnd(ended)), ended);
762
+ const entryDone = entryEnded(ended);
763
+ if (entryDone !== void 0) yield* entryDone;
764
+ const awaiting = state.filled.pop();
765
+ if (awaiting === void 0 || state.held === void 0) return;
766
+ const held = holdBase(state.held, {
767
+ kind: "hold",
768
+ offset: awaiting.offset,
769
+ until: awaiting.until
770
+ });
771
+ if (held !== void 0) yield* held;
772
+ });
773
+ /**
774
+ * A base held as a sweep passes it, until the entry `row` names: resolved from the bases held
775
+ * before it, or not held when it can't be or doesn't fit, so the entries that need it wait.
776
+ */
777
+ const holdBase = (holding, row) => {
778
+ const before = holding.get(row.offset);
779
+ if (before !== void 0) {
780
+ holding.hold(row.offset, before, row.until);
781
+ return;
782
+ }
783
+ const resolved = indexer.resolve(row.offset);
784
+ if (Effect.isEffect(resolved)) return resolved.pipe(Effect.catchIf(isDeferred, () => Effect.succeed(void 0)), Effect.map((done) => {
785
+ holding.passed(row.offset + 1);
786
+ if (done?.kind === "resolved") holding.hold(row.offset, done.object, row.until);
787
+ }));
788
+ holding.passed(row.offset + 1);
789
+ if (resolved.kind === "resolved") holding.hold(row.offset, resolved.object, row.until);
790
+ };
791
+ const checksMostOf = (others) => {
792
+ const most = counted?.most?.bucket;
793
+ if (counted === void 0 || most === void 0) return void 0;
794
+ const linked = links.written();
795
+ const made = counted.made().bucket;
796
+ const after = receiveCallsAfter({
797
+ ...received.written(),
798
+ links: linked,
799
+ foundMore: joinFoundMost(linked, received.counts.objects) + checked.size() + state.parents.size + boundary.size + state.beyond.size,
800
+ others,
801
+ counts: received.counts
802
+ }, bucket.multipart, bucket.deleteBatch);
803
+ const left = Math.max(0, most - made - after);
804
+ return {
805
+ made: made + left,
806
+ left
807
+ };
808
+ };
809
+ let runs = yield* state.deferred.finish;
810
+ let spilledDeferred = runs.keys.length > 0;
811
+ let otherRuns = runs.keys.length;
812
+ const swept = { sweeps: 0 };
813
+ yield* Effect.gen(function* () {
814
+ while (runs.rows > 0) {
815
+ if (swept.sweeps === 2) return yield* Effect.fail(tooManySweeps);
816
+ swept.sweeps += 1;
817
+ const passed = state.deferred;
818
+ const kind = `deferred-${swept.sweeps}`;
819
+ state.deferred = runWriter(bucket, opened.pack, step === void 0 ? kind : stepRunKind(kind, step.step, step.attempt), 12, deferredWriting);
820
+ state.deferrals = 0;
821
+ state.walked = void 0;
822
+ yield* room.take(16777216) ?? Effect.void;
823
+ const holding = sweepHeld(receiveSweepHeldBytes);
824
+ state.held = holding;
825
+ const next = yield* mergedCursor(bucket, opened.pack, runs, void 0, room);
826
+ otherRuns += mergeCallsOf(runs.lengths, runs.width, 16, bucket.multipart).runs;
827
+ let hold;
828
+ for (;;) {
829
+ const stepped = next();
830
+ const at = Effect.isEffect(stepped) ? yield* stepped : stepped;
831
+ if (at === void 0) break;
832
+ const row = sweepRowAt(at.bytes, at.at);
833
+ if (row.kind === "hold" && row.offset === hold?.offset) {
834
+ hold = row;
835
+ continue;
836
+ }
837
+ if (hold !== void 0) {
838
+ const held = holdBase(holding, hold);
839
+ if (held !== void 0) yield* held;
840
+ }
841
+ hold = void 0;
842
+ holding.passed(row.offset);
843
+ state.sweepAt = row.offset;
844
+ if (row.kind === "hold") hold = row;
845
+ else yield* sweepEntry(row);
846
+ }
847
+ if (hold !== void 0) {
848
+ const held = holdBase(holding, hold);
849
+ if (held !== void 0) yield* held;
850
+ }
851
+ room.give(receiveSweepHeldBytes);
852
+ passed.release();
853
+ runs = yield* state.deferred.finish;
854
+ spilledDeferred ||= runs.keys.length > 0;
855
+ otherRuns += runs.keys.length;
856
+ }
857
+ state.sweepAt = void 0;
858
+ state.held = void 0;
859
+ const waited = yield* checks.finish;
860
+ spilledDeferred ||= waited.keys.length > 0;
861
+ otherRuns += waited.keys.length + mergeCallsOf(waited.lengths, waited.width, 16, bucket.multipart).runs;
862
+ state.checksMost = checksMostOf(otherRuns);
863
+ const nextCheck = yield* mergedCursor(bucket, opened.pack, waited, void 0, room);
864
+ for (;;) {
865
+ const stepped = nextCheck();
866
+ const at = Effect.isEffect(stepped) ? yield* stepped : stepped;
867
+ if (at === void 0) break;
868
+ const row = checkRowAt(at.bytes, at.at);
869
+ yield* checkAt(row.offset, row.type);
870
+ }
871
+ checks.release();
872
+ const pushed = Effect.fnUntraced(function* (oid) {
873
+ const slot = yield* stepEffect(ownSlot(oid));
874
+ if (slot === void 0 || state.table === void 0) return void 0;
875
+ const offset = state.table.offsetAt(slot);
876
+ const resolved = yield* stepEffect(indexer.resolve(offset));
877
+ if (resolved.kind === "unindexable") return yield* Effect.fail(state.large.has(offset) ? checkedTooLarge(offset) : unindexable(offset, resolved.why));
878
+ const { kind, bytes } = resolved.object;
879
+ if (idOf(kind, bytes) !== oid) return yield* Effect.fail(foundWrongly);
880
+ return {
881
+ oid,
882
+ type: kind,
883
+ bytes
884
+ };
885
+ });
886
+ yield* checkedFilesRefused(checked, pushed, reader.held);
887
+ }).pipe(Effect.catchIf(isDeferred, () => Effect.die(/* @__PURE__ */ new Error("a stored pack deferred an entry"))), Effect.catchIf((error) => error instanceof DeltaError, (error) => Effect.fail(malformedDelta(error))));
888
+ for (const oid of boundary) {
889
+ const checkedType = ownType(oid, "commit");
890
+ if ((Effect.isEffect(checkedType) ? yield* checkedType : checkedType) !== "commit") return yield* Effect.fail(boundaryNotInPack(oid));
399
891
  }
400
- for (const each of unchecked) yield* check(each.oid, each.type, each.offset);
401
- const pushed = (oid) => {
402
- const offset = offsets.get(oid);
403
- if (offset === void 0) return Effect.succeed(void 0);
404
- return stepEffect(indexer.resolve(offset)).pipe(Effect.flatMap((resolved) => resolved.kind === "unindexable" ? Effect.fail(large.has(offset) ? checkedTooLarge(offset) : unindexable(offset, resolved.why)) : Effect.succeed({
892
+ const brought = /* @__PURE__ */ new Set();
893
+ for (const oid of state.beyond) {
894
+ const checkedType = ownType(oid, "commit");
895
+ const type = Effect.isEffect(checkedType) ? yield* checkedType : checkedType;
896
+ if (type !== void 0 && type !== "commit") return yield* Effect.fail(wrongType({
405
897
  oid,
406
- type: resolved.object.kind,
407
- bytes: resolved.object.bytes
408
- })));
898
+ type: "commit"
899
+ }, type));
900
+ if (type !== void 0) brought.add(oid);
901
+ }
902
+ const leftOut = state.cut.leftOut((oid) => brought.has(oid));
903
+ brought.clear();
904
+ for (const oid of receive.needs ?? []) {
905
+ const put = links.link({
906
+ oid,
907
+ type: "commit"
908
+ });
909
+ if (put !== void 0) yield* put;
910
+ }
911
+ room.give((boundary.size + state.beyond.size) * 120);
912
+ boundary.clear();
913
+ state.beyond.clear();
914
+ return {
915
+ leftOut,
916
+ otherRuns,
917
+ spilled: spilledDeferred
409
918
  };
410
- yield* checkedFilesRefused(checked, pushed, reader.held);
411
- }).pipe(Effect.catchIf(isDeferred, () => Effect.die(/* @__PURE__ */ new Error("a stored pack deferred an entry"))), Effect.catchIf((error) => error instanceof DeltaError, (error) => Effect.fail(malformedDelta(error))));
412
- if (!partial) yield* links.finish(parents, (oid) => types.get(oid));
413
- const written = yield* writePackIndex(objects, read.checksum).pipe(Effect.mapError((error) => malformedPack(error.message)));
414
- const graph = writeCommitGraph(commits);
415
- const putFile = (key, bytes) => bucketPut(bucket, (retrying) => bucket.put(key, new Blob([new Uint8Array(bytes)]).stream(), {
416
- size: bytes.byteLength,
417
- retrying
418
- }));
419
- yield* putFile(files.idx, written.index);
420
- yield* putFile(files.rev, written.reverse);
421
- yield* putFile(files.pos, written.positions);
422
- yield* putFile(files.graph, graph);
423
- yield* stillOpen({
424
- store,
425
- bucket,
426
- repo: listed.repo,
427
- pack: opened.pack
428
919
  });
429
- const quarantine = {
430
- id: newChangeId(),
431
- quarantine: opened.quarantine,
432
- change: { add: [{
920
+ /**
921
+ * The join, then the index files, from where `bodyEnd` left the receive: in a step of its own
922
+ * at a fresh invocation's count, as the join's share of the calls needs (#1179). A step's files
923
+ * are put as a replay of it puts them again, so a joining step whose result was lost ends again.
924
+ */
925
+ const joinEnd = Effect.fnUntraced(function* (read, ended) {
926
+ const { leftOut, otherRuns } = ended;
927
+ state.stored = {
433
928
  id: opened.pack,
434
- objects: objects.length,
435
929
  bytes: read.bytes
436
- }] },
437
- bytes: read.bytes,
438
- objects: objects.length,
439
- lfsPointers: pointers.finish()
440
- };
441
- const roots = partial ? void 0 : rootsOf(offsets.keys(), links.named);
442
- if (roots !== void 0) quarantine.roots = roots;
443
- if (!partial && linkedRows.size <= 64) quarantine.linked = {
444
- packs: [...linkedPacks],
445
- rows: [...linkedRows]
446
- };
447
- return quarantine;
930
+ };
931
+ const parentTypes = /* @__PURE__ */ new Map();
932
+ if (!partial) for (const oid of state.parents) {
933
+ const checkedType = ownType(oid);
934
+ const type = Effect.isEffect(checkedType) ? yield* checkedType : checkedType;
935
+ if (type !== void 0) parentTypes.set(oid, type);
936
+ }
937
+ const linked = links.written();
938
+ const after = receiveCallsAfter({
939
+ ...received.written(),
940
+ links: linked,
941
+ foundMore: joinFoundMost(linked, received.counts.objects),
942
+ others: otherRuns,
943
+ counts: received.counts
944
+ }, bucket.multipart, bucket.deleteBatch);
945
+ const joinBudget = yield* joinBudgetOf(counted, after);
946
+ let joinFound = 0;
947
+ const joinedType = (oid, said) => {
948
+ if (recordOf(oid) !== void 0) joinFound += 1;
949
+ if (joinFound > received.counts.objects) return Effect.fail(foundWrongly);
950
+ return ownType(oid, said);
951
+ };
952
+ yield* withinJoin(joinBudget, links.finish(joinedType, partial ? /* @__PURE__ */ new Set() : state.parents, (oid) => parentTypes.get(oid), partial ? (target) => tagTargetMissing(target, state.tagged.get(target)) : void 0));
953
+ typesHeld.release();
954
+ state.table = void 0;
955
+ room.give(receiveTableBytes(state.count));
956
+ const roots = named ? rootsCollected(() => false) : void 0;
957
+ const written = yield* received.indexFiles(read.checksum, roots === void 0 ? void 0 : (bytes, at, named) => {
958
+ if (!named) roots.add(hexOf(bytes.subarray(at, at + 20)));
959
+ }).pipe(Effect.catchTag("PackIndexError", (error) => Effect.fail(malformedPack(error.message))));
960
+ const graph = yield* received.graph;
961
+ const putFile = (key, bytes) => {
962
+ const put = bucketPut(bucket, key, bytes);
963
+ return step === void 0 ? put : putAgain(bucket, key, bytes, put);
964
+ };
965
+ yield* putFile(files.idx, written.index);
966
+ yield* putFile(files.rev, written.reverse);
967
+ yield* putFile(files.pos, written.positions);
968
+ yield* putFile(files.graph, graph);
969
+ yield* putFile(files.types, written.types);
970
+ if (step === void 0 && (received.spilled() || ended.spilled || links.spilled())) yield* dropRuns(bucket, opened.pack);
971
+ yield* stillOpen({
972
+ store,
973
+ bucket,
974
+ repo: listed.repo,
975
+ pack: opened.pack
976
+ });
977
+ memory.written?.({
978
+ id: opened.pack,
979
+ objects: received.counts.objects,
980
+ bytes: read.bytes,
981
+ graphBytes: graph.byteLength
982
+ }, {
983
+ index: written.index,
984
+ reverse: written.reverse,
985
+ checksum: read.checksum
986
+ });
987
+ const quarantine = {
988
+ id: newChangeId(),
989
+ quarantine: opened.quarantine,
990
+ change: { add: [{
991
+ id: opened.pack,
992
+ objects: received.counts.objects,
993
+ bytes: read.bytes,
994
+ graphBytes: graph.byteLength
995
+ }] },
996
+ bytes: read.bytes,
997
+ objects: received.counts.objects,
998
+ lfsPointers: pointers.finish()
999
+ };
1000
+ const rooted = roots?.roots();
1001
+ if (rooted !== void 0) quarantine.roots = rooted;
1002
+ if (leftOut.length > 0) quarantine.cut = leftOut;
1003
+ if (named && state.linkedRows.size <= 64) quarantine.linked = {
1004
+ packs: [...state.linkedPacks],
1005
+ rows: [...state.linkedRows]
1006
+ };
1007
+ return quarantine;
1008
+ });
1009
+ if (joining !== void 0 && carried !== void 0 && step !== void 0) {
1010
+ const { resume } = carried.state;
1011
+ return yield* joinEnd({
1012
+ ...resume,
1013
+ bytes: resume.offset,
1014
+ flushed: true,
1015
+ checksum: step.staged.checksum
1016
+ }, {
1017
+ ...joining,
1018
+ spilled: false
1019
+ });
1020
+ }
1021
+ const read = yield* indexed;
1022
+ if ("paused" in read) return yield* carryOut(read.paused);
1023
+ const ended = yield* bodyEnd(read);
1024
+ if (step !== void 0) return yield* carryOut({
1025
+ version: read.version,
1026
+ count: read.count,
1027
+ index: read.count,
1028
+ offset: read.bytes
1029
+ }, ended);
1030
+ return yield* joinEnd(read, ended);
448
1031
  });
449
- export { receiveObjectsMost, receivePack, tooMany };
1032
+ export { receivePack, storeStep, tooMany };