@ref0/git 0.12.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (436) hide show
  1. package/dist/access/private-refs.mjs +3 -3
  2. package/dist/auth/access-jwt.mjs +2 -2
  3. package/dist/auth/auth.d.mts +2 -2
  4. package/dist/auth/auth.mjs +3 -6
  5. package/dist/auth/authorize.mjs +4 -20
  6. package/dist/auth/fences.d.mts +1 -2
  7. package/dist/auth/fences.mjs +3 -3
  8. package/dist/auth/grants.mjs +4 -4
  9. package/dist/auth/helpers.mjs +3 -11
  10. package/dist/auth/host-function.mjs +18 -1
  11. package/dist/auth/host-services.mjs +11 -0
  12. package/dist/auth/identify.d.mts +1 -1
  13. package/dist/auth/identify.mjs +3 -3
  14. package/dist/auth/policy.d.mts +27 -7
  15. package/dist/auth/policy.mjs +8 -4
  16. package/dist/auth/token-cleanup.mjs +67 -0
  17. package/dist/auth/token-rows.mjs +1 -1
  18. package/dist/auth/token-text.mjs +9 -1
  19. package/dist/auth/tokens-base.d.mts +35 -0
  20. package/dist/auth/tokens-base.mjs +13 -0
  21. package/dist/auth/tokens-layer.d.mts +2 -28
  22. package/dist/auth/tokens-layer.mjs +6 -12
  23. package/dist/auth/tokens-public.d.mts +3 -3
  24. package/dist/auth/tokens.d.mts +7 -17
  25. package/dist/auth/tokens.mjs +9 -87
  26. package/dist/auth.d.mts +1 -4
  27. package/dist/auth.mjs +1 -3
  28. package/dist/client/answer.mjs +21 -42
  29. package/dist/client/client.d.mts +2 -4
  30. package/dist/client/git-http.mjs +35 -11
  31. package/dist/client/local.mjs +14 -13
  32. package/dist/client/push-upload.mjs +39 -12
  33. package/dist/client/remote.mjs +95 -31
  34. package/dist/client/run-remote-helper.d.mts +1 -0
  35. package/dist/client/run-remote-helper.mjs +58 -24
  36. package/dist/client/slice-push.d.mts +1 -1
  37. package/dist/client/transport.mjs +105 -46
  38. package/dist/contracts/access.d.mts +8 -8
  39. package/dist/contracts/actors.d.mts +2 -34
  40. package/dist/contracts/blobs.d.mts +57 -10
  41. package/dist/contracts/blobs.mjs +16 -2
  42. package/dist/contracts/call-allowance.d.mts +13 -0
  43. package/dist/contracts/call-allowance.mjs +44 -0
  44. package/dist/contracts/calls-spent.mjs +8 -3
  45. package/dist/contracts/client.d.mts +23 -19
  46. package/dist/contracts/commits.d.mts +34 -26
  47. package/dist/contracts/commits.mjs +9 -1
  48. package/dist/contracts/engine.d.mts +6 -1
  49. package/dist/contracts/engine.mjs +10 -1
  50. package/dist/contracts/files.d.mts +12 -12
  51. package/dist/contracts/forks.d.mts +27 -17
  52. package/dist/contracts/git-events.d.mts +29 -1
  53. package/dist/contracts/git-hooks.d.mts +1 -1
  54. package/dist/contracts/git.d.mts +39 -7
  55. package/dist/contracts/git.mjs +3 -2
  56. package/dist/contracts/grants.d.mts +24 -4
  57. package/dist/contracts/handlers.d.mts +1 -1
  58. package/dist/contracts/lfs.d.mts +28 -9
  59. package/dist/contracts/merges.d.mts +3 -2
  60. package/dist/contracts/objects.d.mts +103 -35
  61. package/dist/contracts/operations.d.mts +3 -0
  62. package/dist/contracts/operations.mjs +12 -2
  63. package/dist/contracts/push-uploads.d.mts +44 -5
  64. package/dist/contracts/push-uploads.mjs +7 -3
  65. package/dist/contracts/queue.d.mts +40 -12
  66. package/dist/contracts/queue.mjs +3 -4
  67. package/dist/contracts/refs.d.mts +50 -25
  68. package/dist/contracts/remote.d.mts +6 -7
  69. package/dist/contracts/remote.mjs +5 -4
  70. package/dist/contracts/repo-records.d.mts +1 -0
  71. package/dist/contracts/repos.d.mts +106 -127
  72. package/dist/contracts/repos.mjs +33 -4
  73. package/dist/contracts/result.d.mts +49 -25
  74. package/dist/contracts/result.mjs +52 -11
  75. package/dist/contracts/rules.d.mts +22 -22
  76. package/dist/contracts/server.d.mts +37 -111
  77. package/dist/contracts/services.d.mts +1 -1
  78. package/dist/contracts/signin.d.mts +1 -1
  79. package/dist/contracts/store.d.mts +6 -5
  80. package/dist/contracts/sync.d.mts +90 -26
  81. package/dist/contracts/sync.mjs +45 -11
  82. package/dist/contracts/tags.d.mts +10 -10
  83. package/dist/contracts/time.d.mts +3 -0
  84. package/dist/contracts/{promises.mjs → time.mjs} +1 -1
  85. package/dist/contracts/tokens.d.mts +15 -22
  86. package/dist/contracts/tokens.mjs +3 -3
  87. package/dist/contracts/topics.d.mts +1 -6
  88. package/dist/contracts/trees.d.mts +12 -12
  89. package/dist/contracts/work.d.mts +87 -12
  90. package/dist/contracts/work.mjs +8 -1
  91. package/dist/core/access.d.mts +1 -2
  92. package/dist/core/access.mjs +46 -13
  93. package/dist/core/ancestry.d.mts +10 -0
  94. package/dist/core/ancestry.mjs +6 -6
  95. package/dist/core/asked.mjs +43 -5
  96. package/dist/core/call-names.mjs +7 -1
  97. package/dist/core/call-services.mjs +13 -4
  98. package/dist/core/events/deliver.d.mts +1 -2
  99. package/dist/core/events/deliver.mjs +48 -33
  100. package/dist/core/events/retired.mjs +119 -0
  101. package/dist/core/forks.mjs +931 -435
  102. package/dist/core/hooks/groups.mjs +1 -1
  103. package/dist/core/imports.mjs +159 -15
  104. package/dist/core/index-job.mjs +128 -37
  105. package/dist/core/index-lost.d.mts +1 -2
  106. package/dist/core/index-lost.mjs +2 -2
  107. package/dist/core/job-view.mjs +8 -9
  108. package/dist/core/loose-tally.mjs +1 -1
  109. package/dist/core/mirror-rows.mjs +19 -4
  110. package/dist/core/objects/blobs.mjs +129 -3
  111. package/dist/core/objects/commits.mjs +16 -6
  112. package/dist/core/objects/lines.mjs +2 -2
  113. package/dist/core/objects/merges.mjs +4 -1
  114. package/dist/core/objects/objects-layer.d.mts +1 -1
  115. package/dist/core/objects/objects-layer.mjs +3 -3
  116. package/dist/core/objects/reading.mjs +24 -13
  117. package/dist/core/objects/tags.mjs +4 -1
  118. package/dist/core/objects/trees.mjs +2 -2
  119. package/dist/core/objects/writing.mjs +2 -2
  120. package/dist/core/own-writes.mjs +1 -1
  121. package/dist/core/parts.d.mts +10 -6
  122. package/dist/core/parts.mjs +3 -11
  123. package/dist/core/promise.mjs +9 -12
  124. package/dist/core/purge.mjs +316 -42
  125. package/dist/core/push-decide.mjs +3 -1
  126. package/dist/core/push-files.d.mts +12 -0
  127. package/dist/core/push-files.mjs +225 -0
  128. package/dist/core/push-repo.d.mts +8 -0
  129. package/dist/core/push-repo.mjs +56 -0
  130. package/dist/core/push.d.mts +17 -0
  131. package/dist/core/push.mjs +153 -70
  132. package/dist/core/receipts.mjs +34 -13
  133. package/dist/core/ref-index-job.mjs +4 -4
  134. package/dist/core/ref-view.mjs +61 -7
  135. package/dist/core/refs.mjs +18 -13
  136. package/dist/core/registered-rows.mjs +2 -2
  137. package/dist/core/repack.mjs +46 -28
  138. package/dist/core/repo-info.mjs +19 -12
  139. package/dist/core/repos.mjs +50 -22
  140. package/dist/core/rules/commit-changes.d.mts +0 -1
  141. package/dist/core/saved-caller-views.d.mts +7 -2
  142. package/dist/core/saved-caller-views.mjs +2 -2
  143. package/dist/core/saved-callers.d.mts +19 -2
  144. package/dist/core/seam.d.mts +16 -26
  145. package/dist/core/seam.mjs +7 -28
  146. package/dist/core/tokens.mjs +1 -1
  147. package/dist/core/view.d.mts +6 -0
  148. package/dist/core/view.mjs +51 -26
  149. package/dist/core/work.mjs +105 -35
  150. package/dist/effect.d.mts +5 -12
  151. package/dist/effect.mjs +3 -10
  152. package/dist/engine/failures.mjs +2 -1
  153. package/dist/engine/reads.mjs +17 -10
  154. package/dist/engine/walk.mjs +4 -4
  155. package/dist/event-streams/event-streams.d.mts +1 -1
  156. package/dist/event-streams/event-streams.mjs +1 -1
  157. package/dist/event-streams/stream.d.mts +3 -3
  158. package/dist/event-streams/stream.mjs +38 -15
  159. package/dist/extend.d.mts +4 -5
  160. package/dist/extend.mjs +3 -2
  161. package/dist/http/answers.mjs +12 -7
  162. package/dist/http/core-parts.mjs +129 -64
  163. package/dist/http/handler.mjs +36 -9
  164. package/dist/http/node.d.mts +14 -1
  165. package/dist/http/node.mjs +61 -31
  166. package/dist/http/parts.d.mts +2 -0
  167. package/dist/http/push-upload-job.mjs +507 -0
  168. package/dist/http/push-uploads.d.mts +1 -0
  169. package/dist/http/push-uploads.mjs +142 -69
  170. package/dist/http/upload-pack.mjs +10 -9
  171. package/dist/index.d.mts +27 -28
  172. package/dist/index.mjs +5 -8
  173. package/dist/lfs/answer.mjs +37 -0
  174. package/dist/lfs/base.d.mts +9 -3
  175. package/dist/lfs/base.mjs +27 -2
  176. package/dist/lfs/copy.d.mts +60 -0
  177. package/dist/lfs/copy.mjs +109 -0
  178. package/dist/lfs/layer.d.mts +15 -1
  179. package/dist/lfs/layer.mjs +28 -13
  180. package/dist/lfs/locks.mjs +2 -2
  181. package/dist/lfs/objects.d.mts +7 -0
  182. package/dist/lfs/objects.mjs +152 -55
  183. package/dist/lfs/pointers.mjs +2 -2
  184. package/dist/lfs/rows.d.mts +13 -0
  185. package/dist/lfs/rows.mjs +42 -8
  186. package/dist/lfs/service.d.mts +1 -7
  187. package/dist/lfs/service.mjs +1 -9
  188. package/dist/lfs/upkeep.mjs +48 -14
  189. package/dist/lfs/upload-most.mjs +5 -5
  190. package/dist/lfs/wire.mjs +6 -31
  191. package/dist/merges/merges.mjs +2 -2
  192. package/dist/node.d.mts +3 -3
  193. package/dist/protocol/bytes/buffers.mjs +13 -5
  194. package/dist/protocol/bytes/reader.mjs +6 -1
  195. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  196. package/dist/protocol/bytes/sha256.d.mts +32 -0
  197. package/dist/protocol/bytes/sha256.mjs +105 -49
  198. package/dist/protocol/bytes/streams.mjs +27 -1
  199. package/dist/protocol/diff/read.d.mts +4 -3
  200. package/dist/protocol/diff/read.mjs +8 -3
  201. package/dist/protocol/objects/lfs-pointer.d.mts +14 -2
  202. package/dist/protocol/objects/lfs-pointer.mjs +1 -3
  203. package/dist/protocol/objects/links-raw.mjs +24 -10
  204. package/dist/protocol/objects/tag.d.mts +1 -1
  205. package/dist/protocol/objects/tree.mjs +23 -6
  206. package/dist/protocol/packs/delta.d.mts +6 -3
  207. package/dist/protocol/packs/delta.mjs +96 -32
  208. package/dist/protocol/packs/idx.d.mts +2 -1
  209. package/dist/protocol/packs/idx.mjs +22 -3
  210. package/dist/protocol/packs/parts.d.mts +4 -1
  211. package/dist/protocol/packs/parts.mjs +10 -7
  212. package/dist/protocol/packs/reader.d.mts +5 -0
  213. package/dist/protocol/packs/reader.mjs +3 -2
  214. package/dist/protocol/packs/writer.mjs +26 -8
  215. package/dist/protocol/wire/advertisement.mjs +9 -4
  216. package/dist/protocol/wire/lines.d.mts +4 -2
  217. package/dist/protocol/wire/lines.mjs +11 -5
  218. package/dist/protocol/wire/push-uploads.mjs +13 -1
  219. package/dist/protocol/wire/v2.mjs +2 -2
  220. package/dist/protocol.d.mts +3 -1
  221. package/dist/protocol.mjs +3 -1
  222. package/dist/queue/advance.mjs +22 -25
  223. package/dist/queue/base.d.mts +55 -0
  224. package/dist/queue/base.mjs +44 -0
  225. package/dist/queue/calls.mjs +51 -54
  226. package/dist/queue/commit.mjs +1 -1
  227. package/dist/queue/host.d.mts +2 -22
  228. package/dist/queue/host.mjs +2 -13
  229. package/dist/queue/layer.d.mts +2 -1
  230. package/dist/queue/layer.mjs +11 -4
  231. package/dist/queue/limits.mjs +2 -0
  232. package/dist/queue/push-option.mjs +9 -24
  233. package/dist/queue/schedule.mjs +1 -1
  234. package/dist/queue/state.mjs +2 -10
  235. package/dist/queue/trim.mjs +6 -4
  236. package/dist/rest/blobs.mjs +29 -5
  237. package/dist/rest/caller.d.mts +4 -4231
  238. package/dist/rest/caller.mjs +5 -1
  239. package/dist/rest/client.d.mts +15 -5
  240. package/dist/rest/client.mjs +23 -2
  241. package/dist/rest/events.mjs +1 -2
  242. package/dist/rest/handler.mjs +4 -57
  243. package/dist/rest/handlers.mjs +68 -9
  244. package/dist/rest/layer.d.mts +2 -2
  245. package/dist/rest/layer.mjs +7 -13
  246. package/dist/rest/me.d.mts +3 -428
  247. package/dist/rest/paths.mjs +1 -0
  248. package/dist/rest/work.mjs +8 -0
  249. package/dist/server/check-fetch.mjs +3 -3
  250. package/dist/server/edge-node.d.mts +14 -15
  251. package/dist/server/edge-node.mjs +12 -12
  252. package/dist/server/edge.d.mts +21 -7
  253. package/dist/server/edge.mjs +32 -11
  254. package/dist/server/extension.mjs +1 -1
  255. package/dist/server/git-layer.d.mts +6 -11
  256. package/dist/server/git-layer.mjs +29 -23
  257. package/dist/server/git-namespace.d.mts +5 -4
  258. package/dist/server/git-namespace.mjs +3 -2
  259. package/dist/server/joined.d.mts +21 -40
  260. package/dist/server/joined.mjs +11 -62
  261. package/dist/server/lifecycle.mjs +65 -69
  262. package/dist/server/registry.mjs +28 -3
  263. package/dist/server/server.mjs +245 -465
  264. package/dist/signin/context.d.mts +1 -2
  265. package/dist/signin/layer.d.mts +1 -1
  266. package/dist/signin/layer.mjs +1 -1
  267. package/dist/storage/allotted.mjs +18 -3
  268. package/dist/storage/batch-upkeep.mjs +274 -0
  269. package/dist/{core/purge.d.mts → storage/batches.d.mts} +4 -4
  270. package/dist/storage/batches.mjs +344 -0
  271. package/dist/storage/budget.mjs +2 -2
  272. package/dist/storage/calls.d.mts +1 -2
  273. package/dist/storage/calls.mjs +144 -158
  274. package/dist/storage/chunks.d.mts +9 -0
  275. package/dist/storage/chunks.mjs +297 -0
  276. package/dist/storage/clean-up.mjs +85 -19
  277. package/dist/storage/counted-bucket.mjs +4 -4
  278. package/dist/storage/fetch.d.mts +1 -0
  279. package/dist/storage/fetch.mjs +298 -216
  280. package/dist/storage/file-limits.mjs +24 -0
  281. package/dist/storage/host-bucket.mjs +1 -2
  282. package/dist/storage/id-mix.mjs +19 -5
  283. package/dist/storage/index-bitmaps.mjs +9 -2
  284. package/dist/storage/index-build.d.mts +1 -1
  285. package/dist/storage/index-build.mjs +185 -84
  286. package/dist/storage/index-fetch.mjs +128 -74
  287. package/dist/storage/index-files.d.mts +3 -0
  288. package/dist/storage/index-files.mjs +10 -5
  289. package/dist/storage/index-graph.mjs +72 -22
  290. package/dist/storage/index-reach.mjs +33 -5
  291. package/dist/storage/index-remap.mjs +208 -65
  292. package/dist/storage/index-shallow.mjs +5 -3
  293. package/dist/storage/index-whole.mjs +127 -0
  294. package/dist/storage/largest-files.mjs +48 -0
  295. package/dist/storage/layout.mjs +23 -0
  296. package/dist/storage/lfs-pointers.mjs +10 -1
  297. package/dist/storage/loose.d.mts +7 -4
  298. package/dist/storage/loose.mjs +214 -67
  299. package/dist/storage/memory-budget.mjs +44 -8
  300. package/dist/storage/merge-plan.mjs +3 -2
  301. package/dist/storage/merge-row.mjs +7 -1
  302. package/dist/storage/merge-stream.mjs +164 -25
  303. package/dist/storage/merge-walk.mjs +8 -4
  304. package/dist/storage/merge-write.mjs +1 -1
  305. package/dist/storage/merge.d.mts +1 -1
  306. package/dist/storage/merge.mjs +1 -1
  307. package/dist/storage/object-rows.d.mts +1 -0
  308. package/dist/storage/object-rows.mjs +385 -65
  309. package/dist/storage/oid-table.mjs +171 -0
  310. package/dist/storage/pack-order.mjs +8 -4
  311. package/dist/storage/pack-ranges.d.mts +1 -2
  312. package/dist/storage/pack-ranges.mjs +4 -5
  313. package/dist/storage/pack-reads.d.mts +2 -1
  314. package/dist/storage/pack-reads.mjs +165 -49
  315. package/dist/storage/pack-receive.d.mts +1 -1
  316. package/dist/storage/pack-receive.mjs +85 -27
  317. package/dist/storage/packs.d.mts +1 -1
  318. package/dist/storage/packs.mjs +172 -86
  319. package/dist/storage/placed-reads.mjs +1 -1
  320. package/dist/storage/plan-columns.d.mts +4 -0
  321. package/dist/storage/plan-columns.mjs +238 -0
  322. package/dist/storage/prune-keep.mjs +299 -37
  323. package/dist/storage/prune-walk.mjs +240 -62
  324. package/dist/storage/prune.mjs +749 -213
  325. package/dist/storage/push-allotment.mjs +91 -12
  326. package/dist/storage/push-uploads.mjs +40 -16
  327. package/dist/storage/pushed-commits.mjs +4 -2
  328. package/dist/storage/quarantine.d.mts +1 -1
  329. package/dist/storage/quarantine.mjs +9 -9
  330. package/dist/storage/range-cache.mjs +125 -8
  331. package/dist/storage/ready.d.mts +1 -1
  332. package/dist/storage/ready.mjs +55 -25
  333. package/dist/storage/receive-bounds.mjs +51 -15
  334. package/dist/storage/receive-state.mjs +8 -0
  335. package/dist/storage/receive-steps.mjs +71 -18
  336. package/dist/storage/repack-backlog.mjs +6 -3
  337. package/dist/storage/repack.d.mts +2 -2
  338. package/dist/storage/repack.mjs +1 -8
  339. package/dist/storage/rows.d.mts +1 -1
  340. package/dist/storage/rows.mjs +13 -2
  341. package/dist/storage/runs.mjs +195 -43
  342. package/dist/storage/send-list.d.mts +1 -0
  343. package/dist/storage/send-list.mjs +54 -10
  344. package/dist/storage/shallow.d.mts +1 -0
  345. package/dist/storage/shallow.mjs +26 -4
  346. package/dist/storage/single-flight.mjs +13 -7
  347. package/dist/storage/stream-whole.mjs +132 -28
  348. package/dist/storage/unpack.mjs +371 -79
  349. package/dist/storage/visible.mjs +31 -3
  350. package/dist/storage/walk.mjs +194 -39
  351. package/dist/storage/wants.mjs +5 -5
  352. package/dist/store/bodies.mjs +38 -0
  353. package/dist/store/call-count.d.mts +8 -12
  354. package/dist/store/call-count.mjs +34 -46
  355. package/dist/store/catalogue.d.mts +2 -2
  356. package/dist/store/catalogue.mjs +146 -35
  357. package/dist/store/crossing.mjs +1 -3
  358. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  359. package/dist/store/cursor-seal-public.d.mts +5 -0
  360. package/dist/store/cursor-seal-public.mjs +5 -0
  361. package/dist/store/cursor-seal.d.mts +16 -3
  362. package/dist/store/cursor-seal.mjs +40 -18
  363. package/dist/store/door.mjs +183 -0
  364. package/dist/store/errors.d.mts +3 -4
  365. package/dist/store/errors.mjs +24 -34
  366. package/dist/store/git-store.mjs +25 -7
  367. package/dist/store/job-try.mjs +9 -32
  368. package/dist/store/list-job.mjs +44 -8
  369. package/dist/store/records.d.mts +5 -0
  370. package/dist/store/records.mjs +12 -6
  371. package/dist/store/repo-record.d.mts +10 -9
  372. package/dist/store/repo-record.mjs +123 -28
  373. package/dist/store/reservations.mjs +1 -1
  374. package/dist/store/scopes.mjs +21 -2
  375. package/dist/store/settle.mjs +4 -4
  376. package/dist/sync/bound.d.mts +2 -0
  377. package/dist/sync/bound.mjs +11 -2
  378. package/dist/sync/github.d.mts +6 -1
  379. package/dist/sync/github.mjs +56 -44
  380. package/dist/sync/http.mjs +36 -1
  381. package/dist/sync/import.mjs +32 -18
  382. package/dist/sync/layer.mjs +6 -2
  383. package/dist/sync/lfs-batch.mjs +118 -0
  384. package/dist/sync/lfs-copy.mjs +262 -0
  385. package/dist/sync/mirror.mjs +227 -151
  386. package/dist/sync/said.mjs +16 -37
  387. package/dist/sync/smart-http.mjs +4 -2
  388. package/dist/sync/step.mjs +58 -30
  389. package/dist/sync/tries.mjs +52 -21
  390. package/dist/sync.d.mts +2 -2
  391. package/dist/topics/advance.mjs +10 -11
  392. package/dist/topics/base.d.mts +15 -0
  393. package/dist/topics/base.mjs +8 -0
  394. package/dist/topics/host.mjs +2 -20
  395. package/dist/topics/layer.d.mts +4 -9
  396. package/dist/topics/layer.mjs +3 -4
  397. package/dist/topics/members.mjs +4 -4
  398. package/dist/topics/public.d.mts +2 -1
  399. package/dist/topics/topic.mjs +2 -2
  400. package/package.json +5 -9
  401. package/dist/auth/bridge.mjs +0 -30
  402. package/dist/auth/helpers.d.mts +0 -17
  403. package/dist/contracts/promises.d.mts +0 -39
  404. package/dist/core/call-names.d.mts +0 -3
  405. package/dist/core/clock.mjs +0 -18
  406. package/dist/core/registered-rows.d.mts +0 -5
  407. package/dist/core/repack.d.mts +0 -11
  408. package/dist/http/handler.d.mts +0 -2
  409. package/dist/lfs/calls.mjs +0 -26
  410. package/dist/rest/api.d.mts +0 -23
  411. package/dist/rest/blobs.d.mts +0 -825
  412. package/dist/rest/commits.d.mts +0 -3510
  413. package/dist/rest/errors.d.mts +0 -2104
  414. package/dist/rest/events.d.mts +0 -423
  415. package/dist/rest/files.d.mts +0 -1330
  416. package/dist/rest/forks.d.mts +0 -2136
  417. package/dist/rest/handler.d.mts +0 -21
  418. package/dist/rest/handlers.d.mts +0 -8
  419. package/dist/rest/merges.d.mts +0 -473
  420. package/dist/rest/queue.d.mts +0 -5861
  421. package/dist/rest/refs.d.mts +0 -2959
  422. package/dist/rest/repos.d.mts +0 -2539
  423. package/dist/rest/tags.d.mts +0 -1304
  424. package/dist/rest/tokens.d.mts +0 -2590
  425. package/dist/rest/topics.d.mts +0 -2204
  426. package/dist/rest/trees.d.mts +0 -1693
  427. package/dist/rest/work.d.mts +0 -1248
  428. package/dist/rest.d.mts +0 -2
  429. package/dist/rest.mjs +0 -1
  430. package/dist/server/lifecycle.d.mts +0 -2
  431. package/dist/server/registry.d.mts +0 -16
  432. package/dist/server/server.d.mts +0 -36
  433. package/dist/storage/repack-job.d.mts +0 -3
  434. package/dist/store/promises.d.mts +0 -11
  435. package/dist/store/promises.mjs +0 -327
  436. package/dist/topics/host.d.mts +0 -7
@@ -2,7 +2,7 @@ import { gitError } from "../contracts/result.mjs";
2
2
  import { hexOf } from "../protocol/bytes/hex.mjs";
3
3
  import { Sha1 } from "../protocol/bytes/sha1.mjs";
4
4
  import { answerSpent, pastCallLimit } from "../store/errors.mjs";
5
- import { copyHeldBytes, isMergeIncomplete, mergeIncomplete } from "./index-bitmaps.mjs";
5
+ import { copyHeldBytes, isKeepUnclosed, isMergeIncomplete, mergeIncomplete } from "./index-bitmaps.mjs";
6
6
  import { belowGraphs, copyMergedBitmaps, coveredPacks, indexRowOf, mergeCallsAfterOpen, mergeChunk, newBuildId, putOnce, wordsOf } from "./index-build.mjs";
7
7
  import { BasesWriter, TypesWriter, indexBasesBytes, indexTypesBytes, openBases, openTypes, typeCodes } from "./index-files.mjs";
8
8
  import { mergeHeldBytes, mergeIndexGraphs } from "./index-graph.mjs";
@@ -14,13 +14,15 @@ import { spentIn } from "../contracts/calls-spent.mjs";
14
14
  import { startPut } from "./merge.mjs";
15
15
  import { writeOrder } from "./merge-choose.mjs";
16
16
  import { openRanges, rangeRanks, readExactly } from "./pack-ranges.mjs";
17
- import { compareIds } from "./raw-ids.mjs";
17
+ import { hasBit, setBit } from "./prune-keep.mjs";
18
+ import { compareIds, orderById } from "./raw-ids.mjs";
18
19
  import * as Effect from "effect/Effect";
19
20
  // src/storage/index-remap.ts
20
21
  /**
21
22
  * The plan of a remap of `layers` once a merge takes `merged`'s packs, of `objects` objects in
22
- * all: `undefined` when it can't remap, as when a merged pack isn't one the row covers, or a
23
- * covered pack isn't listed. `listed` is the listing before the merge.
23
+ * all, 0 for packs a prune step empties with no merge: `undefined` when it can't remap, as when a
24
+ * merged pack isn't one the row covers, or a covered pack isn't listed. `listed` is the listing
25
+ * before the merge.
24
26
  */
25
27
  const remapPlan = (layers, listed, merged, objects) => {
26
28
  const counts = new Map(listed.packs.map((pack) => [pack.id, pack.objects]));
@@ -87,24 +89,38 @@ const keptRowBytes = 64;
87
89
  * planned: the map, 4 bytes a tail position, with the tail's IDs, the rows kept and their join;
88
90
  * then the map through the graph merge's and the copy's, with every bitmap's entry,
89
91
  * `mergeEntryBytes`; or `.bases`' rows, the old and the new, with each row's code and a chunk of
90
- * `.types`.
92
+ * `.types`. A merge that `keeps` adds a bit a tail position, the IDs it dropped as they're built
93
+ * beside the tail's and then beside the graph merge's, and the bitmaps' copy beside both, since
94
+ * it runs before the graph's file finishes.
91
95
  */
92
- const remapHeldMost = (plan, layers, objects) => {
96
+ const remapHeldMost = (plan, layers, objects, keeps = false) => {
93
97
  const tail = plan.positions - plan.prefix;
94
98
  const positions = plan.prefix + tail + objects;
95
99
  const commits = layers.reduce((sum, layer) => sum + layer.commits, 0);
96
100
  const bitmaps = layers.reduce((sum, layer) => sum + layer.bitmaps, 0);
97
101
  const deltas = layers.reduce((sum, layer) => sum + layer.deltas, 0);
98
102
  const files = layers.map((layer) => layer.first + layer.positions);
99
- const map = tail * 4;
103
+ const map = tail * 4 + (keeps ? Math.ceil(tail / 8) : 0);
104
+ const taken = plan.tail.reduce((sum, pack) => sum + (pack.next === void 0 ? pack.objects : 0), 0);
105
+ const dropped = keeps ? Math.max(0, taken - objects) : 0;
106
+ const ids = map + tail * 20 + joinBytes(tail) + plan.rows * keptRowBytes;
107
+ const graph = commits * 4 + mergeHeldBytes(layers.length);
108
+ const copy = bitmaps * 640 + copyHeldBytes(positions, bitmaps, files);
100
109
  const phases = [
101
- map + tail * 20 + joinBytes(tail) + plan.rows * keptRowBytes,
102
- map + commits * 4 + mergeHeldBytes(layers.length),
103
- map + bitmaps * 640 + copyHeldBytes(positions, bitmaps, files),
110
+ ids + goneBuildBytes(dropped),
111
+ map + goneHeldBytes(dropped) + graph,
112
+ map + (keeps ? goneHeldBytes(dropped) + graph : 0) + copy,
104
113
  map + bitmaps * 640 + deltas * 16 + objects * 8 + plan.rows * 112 + mergeChunk * 9
105
114
  ];
106
115
  return Math.max(...phases);
107
116
  };
117
+ /**
118
+ * What `goneIds` holds as it builds `count` dropped IDs: theirs twice, gathered then sorted, their
119
+ * order, and `orderById`'s two tables of counts.
120
+ */
121
+ const goneBuildBytes = (count) => count === 0 ? 0 : count * 44 + 524292;
122
+ /** What the sorted dropped IDs hold once built, through the graph merge. */
123
+ const goneHeldBytes = (count) => count * 20;
108
124
  /** Where `layers` hold an old position: its layer and its place there. */
109
125
  const layerAt = (layers, position) => layers.find((layer) => position >= layer.first && position < layer.first + layer.positions);
110
126
  /** The `.types` parts `oldTypes` reads over old positions `[from, to)`: one a layer or chunk. */
@@ -152,6 +168,8 @@ const defaultRemapCpuMost = 3e4;
152
168
  const remapUnits = (plan, layers) => layers.reduce((sum, layer) => sum + layer.bitmaps, 0) * (plan.positions - plan.prefix);
153
169
  /** Whether a remap's CPU, its units at `remapNsPerUnit`, would pass `cpuMost` ms. */
154
170
  const remapCpuPast = (units, cpuMost) => units * 26 > Math.round(cpuMost * 1e6);
171
+ /** The objects `merged` lays in the tail: its pack's, or none for packs emptied. */
172
+ const mergedObjects = (merged) => merged.kind === "pack" ? merged.pack.objects : 0;
155
173
  /**
156
174
  * The calls a remap makes past its graphs' heads: `remapCalls` with a layer merge's reads of
157
175
  * graphs of `octopus` table entries each, its `.bitmaps` over the merged pack's positions too, in
@@ -201,17 +219,31 @@ const remapPast = (input) => {
201
219
  const layers = row.layers;
202
220
  if (remapCpuPast(remapUnits(plan, layers), input.cpuMost)) return "cpu";
203
221
  if (input.lease !== void 0 && input.lease >= input.grace) return "lease";
204
- if (pastCallsLeft(input.calls, remapCallsMost(plan, layers, merged.pack.objects, input.bucket.multipart))) return "calls";
205
- const held = remapHeldMost(plan, layers, merged.pack.objects);
222
+ if (pastCallsLeft(input.calls, remapCallsMost(plan, layers, mergedObjects(merged), input.bucket.multipart))) return "calls";
223
+ const held = remapHeldMost(plan, layers, mergedObjects(merged), input.keeps !== void 0);
206
224
  if (!input.allotment.tryGrow(held)) return "memory";
207
225
  input.allotment.shrink(held);
208
226
  };
227
+ /**
228
+ * Whether a remap fits, from its plan and the merge alone, before any read: `'cpu'` when its CPU
229
+ * passes `cpuMost`, which no try changes, and `'calls'` when `before`, its own calls at most and
230
+ * the listing's commit pass what the try has left, as `remapPast` weighs them. A resumed merge
231
+ * whose remap fits a fresh try, but not what its last try has left, saves for the next (#2196).
232
+ */
233
+ const remapFits = (fit) => {
234
+ const { plan, layers } = fit;
235
+ if (remapCpuPast(remapUnits(plan, layers), fit.cpuMost)) return "cpu";
236
+ const needs = (fit.before ?? 0) + remapCallsMost(plan, layers, fit.objects, fit.multipart);
237
+ return pastCallsLeft(fit.calls, needs) ? "calls" : void 0;
238
+ };
209
239
  const lost = (message) => gitError("DATA_LOSS", message);
210
240
  /**
211
241
  * A remap's decline, one line in the log with its cause, so a bound it always passes shows as a
212
242
  * pattern: then the merge commits alone, and the next `git.index` builds again.
213
243
  */
214
244
  const declined = (repo, cause) => Effect.logWarning(`git.repack's remap of repo ${repo} declined, ${cause}`).pipe(Effect.as(void 0));
245
+ /** A remap's decline past a bound `remapPast` weighs, as `remapIndex` logs it. */
246
+ const declinedPast = (repo, past) => declined(repo, `past its ${past} bound`);
215
247
  /** A remap's allotment's refusal to grow, its own, so `remapFailure` tells it from another's. */
216
248
  const remapBusy = /* @__PURE__ */ gitError("UNAVAILABLE", "A repack's remap couldn't grow its allotment", { context: { reason: "busy" } });
217
249
  /**
@@ -257,20 +289,26 @@ const mergedRanges = (bucket, pack, base) => Effect.map(mergedOwn(rangesOf(bucke
257
289
  });
258
290
  /**
259
291
  * Each tail position's ID, by its old position, and the rows the merge left: theirs from each
260
- * run's region, by ID, each with its old position. `undefined` when a folded row isn't one the
261
- * row held.
292
+ * run's region, by ID, each with its old position. With `input.keeps`, the tail positions the
293
+ * merge dropped too, a bit each. `undefined` when a folded row isn't one the row held.
262
294
  */
263
295
  const tailIds = /* @__PURE__ */ Effect.fnUntraced(function* (input, old) {
264
296
  const { bucket, listed, plan } = input;
265
297
  const tail = plan.positions - plan.prefix;
266
298
  const ids = new Uint8Array(tail * 20);
267
- for (const ranges of old) for (let rank = 0; rank < ranges.count; rank += rangeRanks) {
268
- const count = Math.min(rangeRanks, ranges.count - rank);
269
- const chunk = yield* ranges.ids(rank, count);
270
- const positions = yield* ranges.positions(rank, count);
271
- for (let at = 0; at < count; at += 1) {
272
- const place = ranges.base + (positions[at] ?? 0) - plan.prefix;
273
- ids.set(chunk.subarray(at * 20, at * 20 + 20), place * 20);
299
+ const dropped = input.keeps === void 0 ? void 0 : new Uint8Array(Math.ceil(tail / 8));
300
+ for (const [index, ranges] of old.entries()) {
301
+ const pack = plan.tail[index];
302
+ const keeps = pack?.next === void 0 ? input.keeps : void 0;
303
+ for (let rank = 0; rank < ranges.count; rank += rangeRanks) {
304
+ const count = Math.min(rangeRanks, ranges.count - rank);
305
+ const chunk = yield* ranges.ids(rank, count);
306
+ const positions = yield* ranges.positions(rank, count);
307
+ for (let at = 0; at < count; at += 1) {
308
+ const place = ranges.base + (positions[at] ?? 0) - plan.prefix;
309
+ ids.set(chunk.subarray(at * 20, at * 20 + 20), place * 20);
310
+ if (dropped !== void 0 && keeps?.(pack?.id ?? "", rank + at) === false) setBit(dropped, place);
311
+ }
274
312
  }
275
313
  }
276
314
  const folded = new Set(input.folded);
@@ -293,13 +331,52 @@ const tailIds = /* @__PURE__ */ Effect.fnUntraced(function* (input, old) {
293
331
  kept.sort((a, b) => compareIds(a.id, 0, b.id, 0));
294
332
  return {
295
333
  ids,
296
- kept
334
+ kept,
335
+ dropped
297
336
  };
298
337
  });
299
- /** A bitmap's bits moved: the prefix's words as they were, each tail bit through `map`. */
338
+ /** How many tail positions `map` leaves `missing`: the objects the merge dropped. */
339
+ const goneCount = (map) => {
340
+ let count = 0;
341
+ for (const to of map) if (to === 4294967295) count += 1;
342
+ return count;
343
+ };
344
+ /**
345
+ * The IDs of the `count` tail positions `map` leaves `missing`, the ones the merge dropped, in ID
346
+ * order, for the graph merge to leave out.
347
+ */
348
+ const goneIds = (ids, map, count) => {
349
+ const gone = new Uint8Array(count * 20);
350
+ let at = 0;
351
+ for (const [place, to] of map.entries()) if (to === 4294967295) {
352
+ gone.set(ids.subarray(place * 20, place * 20 + 20), at * 20);
353
+ at += 1;
354
+ }
355
+ const sorted = new Uint8Array(count * 20);
356
+ for (const [to, from] of orderById(gone, count).entries()) sorted.set(gone.subarray(from * 20, from * 20 + 20), to * 20);
357
+ return sorted;
358
+ };
359
+ /** Whether `sorted`, IDs in order, holds the one at `offset` of `ids`. */
360
+ const holdsId = (sorted, ids, offset) => {
361
+ let low = 0;
362
+ let high = sorted.length / 20;
363
+ while (low < high) {
364
+ const middle = low + high >>> 1;
365
+ const order = compareIds(sorted, middle * 20, ids, offset);
366
+ if (order === 0) return true;
367
+ if (order < 0) low = middle + 1;
368
+ else high = middle;
369
+ }
370
+ return false;
371
+ };
372
+ /**
373
+ * A bitmap's bits moved: the prefix's words as they were, each tail bit through `map`. `false`
374
+ * when a bit is at a position `map` leaves `missing`, one the merge dropped.
375
+ */
300
376
  const movedBits = (prefix, map) => (bits, into) => {
301
377
  const whole = prefix >>> 5;
302
378
  into.set(bits.subarray(0, Math.min(whole, into.length)));
379
+ let placed = true;
303
380
  for (let word = whole; word < bits.length; word += 1) {
304
381
  let left = bits[word] ?? 0;
305
382
  while (left !== 0) {
@@ -307,9 +384,11 @@ const movedBits = (prefix, map) => (bits, into) => {
307
384
  left ^= low;
308
385
  const position = word * 32 + (31 - Math.clz32(low));
309
386
  const to = position < prefix ? position : map[position - prefix] ?? 4294967295;
310
- if (to !== 4294967295) into[to >>> 5] = (into[to >>> 5] ?? 0) | 1 << (to & 31);
387
+ if (to === 4294967295) placed = false;
388
+ else into[to >>> 5] = (into[to >>> 5] ?? 0) | 1 << (to & 31);
311
389
  }
312
390
  }
391
+ return placed;
313
392
  };
314
393
  /** Each layer's `.types`, its header read and checked once a remap, as a layer merge opens it. */
315
394
  const layerTypes = (input) => {
@@ -356,11 +435,12 @@ const oldBases = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
356
435
  /**
357
436
  * The remapped `.bases` rows: the prefix's as they were; the merged pack's, from its own plan,
358
437
  * past the prefix; and each other tail pack's, moved as its pack is. A row of a merged pack is
359
- * gone, its pack's objects the merged pack's now.
438
+ * gone, its pack's objects the merged pack's now, or gone with them when they're emptied.
360
439
  */
361
440
  const remappedBases = (input, old) => {
362
441
  const { plan, merged } = input;
363
- const out = new Uint32Array(old.length + merged.bases.length);
442
+ const own = merged.kind === "pack" ? merged.bases : /* @__PURE__ */ new Uint32Array(0);
443
+ const out = new Uint32Array(old.length + own.length);
364
444
  let length = 0;
365
445
  const push = (position, base) => {
366
446
  out[length] = position;
@@ -368,7 +448,7 @@ const remappedBases = (input, old) => {
368
448
  length += 2;
369
449
  };
370
450
  for (let at = 0; at < old.length && (old[at] ?? 0) < plan.prefix; at += 2) push(old[at] ?? 0, old[at + 1] ?? 0);
371
- for (let at = 0; at < merged.bases.length; at += 2) push((merged.bases[at] ?? 0) + plan.prefix, (merged.bases[at + 1] ?? 0) + plan.prefix);
451
+ for (let at = 0; at < own.length; at += 2) push((own[at] ?? 0) + plan.prefix, (own[at + 1] ?? 0) + plan.prefix);
372
452
  for (let at = 0; at < old.length; at += 2) {
373
453
  const position = old[at] ?? 0;
374
454
  const pack = plan.tail.find((each) => position >= each.old && position < each.old + each.objects);
@@ -393,25 +473,26 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
393
473
  if (past !== void 0) return yield* declined(listed.repo, `past its ${past} bound`);
394
474
  const graphs = yield* belowGraphs(bucket, listed.repo, layers);
395
475
  const octopus = graphs.map((graph) => graph.octopus);
396
- if (pastCallsLeft(input.calls, callsAfterHeads(plan, layers, merged.pack.objects, octopus, bucket.multipart))) return yield* declined(listed.repo, "past its calls bound, with its graphs' octopus tables");
476
+ if (pastCallsLeft(input.calls, callsAfterHeads(plan, layers, mergedObjects(merged), octopus, bucket.multipart))) return yield* declined(listed.repo, "past its calls bound, with its graphs' octopus tables");
397
477
  const build = newBuildId();
398
478
  const files = indexFiles(listed.repo, build);
399
- const objects = merged.pack.objects;
479
+ const objects = mergedObjects(merged);
400
480
  const positions = plan.prefix + tailOf(plan, objects, input.folded.length);
401
481
  const tail = plan.positions - plan.prefix;
402
482
  const bytesOf = new Map(listed.packs.map((pack) => [pack.id, pack.bytes]));
403
- yield* allotment.grow(tail * 4);
483
+ const map4 = tail * 4 + (input.keeps === void 0 ? 0 : Math.ceil(tail / 8));
484
+ yield* allotment.grow(map4);
404
485
  yield* allotment.grow(tail * 20 + joinBytes(tail));
405
486
  const old = yield* Effect.forEach(plan.tail, (pack) => rangesOf(bucket, pack.id, pack.objects, bytesOf.get(pack.id) ?? 0, pack.old));
406
487
  const read = yield* tailIds(input, old);
407
488
  if (read === void 0) {
408
- allotment.shrink(tail * 24 + joinBytes(tail));
489
+ allotment.shrink(map4 + tail * 20 + joinBytes(tail));
409
490
  return yield* declined(listed.repo, "a row the merge folded isn't one the row held");
410
491
  }
411
492
  const rowsFirst = positions - read.kept.length;
412
493
  const regionIds = new Uint8Array(read.kept.length * 20);
413
494
  for (const [at, each] of read.kept.entries()) regionIds.set(each.id, at * 20);
414
- const next = [yield* mergedRanges(bucket, merged.pack, plan.prefix), ...plan.tail.flatMap((pack, at) => {
495
+ const next = [...merged.kind === "pack" ? [yield* mergedRanges(bucket, merged.pack, plan.prefix)] : [], ...plan.tail.flatMap((pack, at) => {
415
496
  const ranges = old[at];
416
497
  return pack.next === void 0 || ranges === void 0 ? [] : [{
417
498
  ...ranges,
@@ -423,17 +504,12 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
423
504
  positions: Uint32Array.from(read.kept, (_, at) => rowsFirst + at)
424
505
  };
425
506
  const map = yield* joinIds(read.ids, tail, next, region);
426
- allotment.shrink(tail * 20 + joinBytes(tail));
427
- if (map.includes(4294967295)) return yield* Effect.fail(mergeIncomplete("The merge left a tail object out"));
428
- const { commits } = yield* mergeIndexGraphs({
429
- bucket,
430
- graphs,
431
- key: files.graph,
432
- allotment
433
- });
434
- const entries = layers.reduce((sum, layer) => sum + layer.bitmaps, 0) * 640;
435
- yield* allotment.grow(entries);
436
- const stored = yield* openLayerBitmaps(bucket, listed.repo, layers);
507
+ const { dropped } = read;
508
+ if (map.some((to, at) => to === 4294967295 && (dropped === void 0 || !hasBit(dropped, at)))) return yield* Effect.fail(mergeIncomplete("The merge left a tail object out"));
509
+ const count = goneCount(map);
510
+ yield* allotment.grow(goneBuildBytes(count));
511
+ const gone = count === 0 ? void 0 : goneIds(read.ids, map, count);
512
+ allotment.shrink(tail * 20 + joinBytes(tail) + goneBuildBytes(count) - goneHeldBytes(count));
437
513
  const move = {
438
514
  bits: movedBits(plan.prefix, map),
439
515
  position: (at) => {
@@ -441,15 +517,46 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
441
517
  return to === 4294967295 ? void 0 : to;
442
518
  }
443
519
  };
444
- const bitmaps = yield* copyMergedBitmaps({
445
- bucket,
446
- graphs,
447
- files,
448
- positions,
449
- kept: stored.entries,
450
- allotment,
451
- move
520
+ const copy = Effect.fnUntraced(function* (renumbered) {
521
+ const entries = layers.reduce((sum, layer) => sum + layer.bitmaps, 0) * 640;
522
+ yield* allotment.grow(entries);
523
+ const stored = yield* openLayerBitmaps(bucket, listed.repo, layers);
524
+ return {
525
+ entries,
526
+ bitmaps: yield* copyMergedBitmaps({
527
+ bucket,
528
+ graphs,
529
+ files,
530
+ positions,
531
+ kept: stored.entries.filter(({ entry }) => move.position(entry.position) !== void 0),
532
+ allotment,
533
+ move,
534
+ renumbered
535
+ })
536
+ };
452
537
  });
538
+ const copied = yield* Effect.gen(function* () {
539
+ const early = [];
540
+ const { commits } = yield* mergeIndexGraphs({
541
+ bucket,
542
+ graphs,
543
+ key: files.graph,
544
+ allotment,
545
+ drops: gone === void 0 ? void 0 : (ids, offset) => holdsId(gone, ids, offset),
546
+ beforeFinish: gone === void 0 ? void 0 : (renumbered) => Effect.map(copy(renumbered), (each) => {
547
+ early.push(each);
548
+ })
549
+ });
550
+ allotment.shrink(goneHeldBytes(count));
551
+ const { entries, bitmaps } = early[0] ?? (yield* copy());
552
+ return {
553
+ commits,
554
+ entries,
555
+ bitmaps
556
+ };
557
+ }).pipe(Effect.catchIf(isKeepUnclosed, (error) => Effect.logError(`git.repack's remap of repo ${listed.repo} declined, its merge's keep isn't closed: ${error.message}`).pipe(Effect.as(void 0))));
558
+ if (copied === void 0) return void 0;
559
+ const { commits, entries, bitmaps } = copied;
453
560
  const filesBytes = layers.reduce((sum, layer) => sum + layer.deltas, 0) * 16 + objects * 8 + plan.rows * 112 + mergeChunk * 9;
454
561
  yield* allotment.grow(filesBytes);
455
562
  const types = Effect.gen(function* () {
@@ -459,7 +566,7 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
459
566
  yield* put.write(writer.head());
460
567
  const typesOf = layerTypes(input);
461
568
  yield* oldTypes(input, typesOf, 0, plan.prefix, write);
462
- for (const kind of writeOrder) for (let left = merged.kinds[kind]; left > 0; left -= mergeChunk) yield* write(new Uint8Array(Math.min(left, mergeChunk)).fill(typeCodes[kind]));
569
+ for (const kind of writeOrder) for (let left = merged.kind === "pack" ? merged.kinds[kind] : 0; left > 0; left -= mergeChunk) yield* write(new Uint8Array(Math.min(left, mergeChunk)).fill(typeCodes[kind]));
463
570
  for (const pack of plan.tail) if (pack.next !== void 0) yield* oldTypes(input, typesOf, pack.old, pack.old + pack.objects, write);
464
571
  const rowCodes = /* @__PURE__ */ new Map();
465
572
  for (const run of plan.runs) yield* oldTypes(input, typesOf, run.first, run.first + run.rows, (codes, first) => Effect.sync(() => {
@@ -481,7 +588,7 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
481
588
  });
482
589
  yield* Effect.scoped(types);
483
590
  yield* Effect.scoped(bases);
484
- allotment.shrink(filesBytes + entries + tail * 4);
591
+ allotment.shrink(filesBytes + entries + map4);
485
592
  const sha = new Sha1();
486
593
  sha.update(regionIds);
487
594
  if (regionIds.byteLength > 0) yield* putOnce(bucket, files.region, regionIds);
@@ -490,7 +597,7 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
490
597
  groups: [{
491
598
  packs: [
492
599
  ...plan.prefixPacks,
493
- merged.pack.id,
600
+ ...merged.kind === "pack" ? [merged.pack.id] : [],
494
601
  ...plan.tail.flatMap((pack) => pack.next === void 0 ? [] : [pack.id])
495
602
  ],
496
603
  rows: read.kept.length
@@ -504,7 +611,12 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
504
611
  bitmaps: bitmaps.count,
505
612
  table: bitmaps.table
506
613
  };
507
- return {
614
+ const roots = layers.flatMap((each) => (each.roots ?? []).flatMap((at) => {
615
+ const to = move.position(at);
616
+ return to === void 0 ? [] : [to];
617
+ }));
618
+ if (roots.length > 0) layer.roots = [...new Set(roots)].sort((a, b) => a - b);
619
+ const rebuilt = {
508
620
  rounds: row.rounds,
509
621
  layers: [layer],
510
622
  replaced: [...row.replaced.filter((each) => each.at + input.grace > input.at), ...layers.map((each) => ({
@@ -512,9 +624,33 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
512
624
  at: input.at
513
625
  }))]
514
626
  };
627
+ if (row.roots !== void 0) rebuilt.roots = row.roots;
628
+ return rebuilt;
515
629
  });
516
630
  /**
517
- * The `index` row a geometric step's merge leaves, laid again over its pack, or `undefined` when
631
+ * The row a merge's remap lays again, and its plan, from the row and the merge alone, as `remapRow`
632
+ * weighs them before any read: `undefined` when the row isn't built, is a refusal for spent tries,
633
+ * is marked lost, or doesn't cover the listing before the merge, but what `parts` holds; or the
634
+ * merge, `taken`, of `objects` objects, took a pack it doesn't cover.
635
+ */
636
+ const remapDue = (parts, listed, taken, objects) => {
637
+ const row = indexRowOf({
638
+ ...indexRowKey,
639
+ value: parts.row
640
+ });
641
+ if (row === void 0 || "refused" in row || row.refusal !== void 0 || row.lost === true) return void 0;
642
+ const held = parts.holdsUncovered === true ? pruneRemapHeld(row.layers, listed, taken) : parts.holds?.packs;
643
+ if (!coversListing(row.layers, listed, held)) return void 0;
644
+ const plan = remapPlan(row.layers, listed, taken, objects);
645
+ return plan === void 0 ? void 0 : {
646
+ row,
647
+ plan
648
+ };
649
+ };
650
+ /**
651
+ * The `index` row a geometric step's or a prune rewrite's merge leaves, laid again over its pack,
652
+ * the rewrite's dropped objects left out, or the row a prune step leaves when it empties packs
653
+ * with no merge, their positions gone, or `undefined` when
518
654
  * it can't be: the row isn't built, is a refusal for spent tries, is marked lost, or doesn't
519
655
  * cover the listing before the merge; the merge took a pack it doesn't cover; the remap
520
656
  * declines, as `remapIndex` says; or it fails of its own, its calls run out, its allotment can't
@@ -524,14 +660,9 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
524
660
  * any other failure.
525
661
  */
526
662
  const remapRow = (parts, input) => Effect.scoped(Effect.gen(function* () {
527
- const row = indexRowOf({
528
- ...indexRowKey,
529
- value: parts.row
530
- });
531
- if (row === void 0 || "refused" in row || row.refusal !== void 0 || row.lost === true) return void 0;
532
- if (!coversListing(row.layers, input.listed, parts.holds?.packs)) return void 0;
533
- const plan = remapPlan(row.layers, input.listed, input.taken, input.merged.pack.objects);
534
- if (plan === void 0) return void 0;
663
+ const due = remapDue(parts, input.listed, input.taken, mergedObjects(input.merged));
664
+ if (due === void 0) return void 0;
665
+ const { row, plan } = due;
535
666
  const { calls } = parts;
536
667
  const built = yield* remapIndex({
537
668
  bucket: calls === void 0 ? input.bucket : calls.within(remapCallsBound(calls.most)).bucket,
@@ -540,6 +671,7 @@ const remapRow = (parts, input) => Effect.scoped(Effect.gen(function* () {
540
671
  plan,
541
672
  merged: input.merged,
542
673
  folded: input.folded,
674
+ keeps: input.keeps,
543
675
  allotment: yield* parts.budget.upkeep(0, remapBusy),
544
676
  at: input.at,
545
677
  grace: parts.grace,
@@ -590,6 +722,17 @@ const coversListing = (layers, listed, held = /* @__PURE__ */ new Set()) => {
590
722
  const ids = new Set(listed.packs.map((pack) => pack.id));
591
723
  return [...covered].every((id) => ids.has(id)) && listed.packs.every((pack) => covered.has(pack.id) || held.has(pack.id));
592
724
  };
725
+ /**
726
+ * What a prune rewrite's remap holds: each listed pack `layers` don't cover that the merge doesn't
727
+ * take, `taken`, as a push's pack waits for git.index's update. A cruft step's pack, listed before
728
+ * the rewrite's step and not yet covered, so stays out of the row it lays, and a merge never waits
729
+ * on git.index to drop what it drops. A pack the merge takes that the row doesn't cover still
730
+ * declines the remap, in `remapPlan`.
731
+ */
732
+ const pruneRemapHeld = (layers, listed, taken) => {
733
+ const covered = coveredPacks(layers);
734
+ return new Set(listed.packs.flatMap((pack) => covered.has(pack.id) || taken.has(pack.id) ? [] : [pack.id]));
735
+ };
593
736
  /** The object rows `layers` cover: each group's rows, as git.index read them. */
594
737
  const rowsCovered = (layers) => layers.reduce((sum, layer) => sum + layer.groups.reduce((each, group) => each + group.rows, 0), 0);
595
738
  /**
@@ -631,4 +774,4 @@ const liftsHolds = (old, now, listed) => {
631
774
  const is = coveredPacks(now.layers);
632
775
  return listed.packs.some((pack) => is.has(pack.id) && !was.has(pack.id)) || rowsCovered(now.layers) > rowsCovered(old.layers);
633
776
  };
634
- export { coversListing, defaultRemapCpuMost, indexHolds, liftsHolds, movedBits, remapCalls, remapCallsBound, remapCallsMost, remapCpuPast, remapHeldMost, remapIndex, remapPast, remapPlan, remapRow, remapUnits, replacedAtCommit };
777
+ export { coversListing, declinedPast, defaultRemapCpuMost, goneBuildBytes, indexHolds, liftsHolds, movedBits, pruneRemapHeld, remapCalls, remapCallsBound, remapCallsMost, remapCpuPast, remapDue, remapFits, remapHeldMost, remapIndex, remapPast, remapPlan, remapRow, remapUnits, replacedAtCommit };
@@ -265,8 +265,9 @@ const indexShallow = /* @__PURE__ */ Effect.fnUntraced(function* (walk, request)
265
265
  });
266
266
  /** What it held, given back, but for the lines it returns: nothing, when it held nothing. */
267
267
  const given = Effect.suspend(() => Effect.andThen(heldBytes > 0 ? read.release(heldBytes) : Effect.void, readsHeld > 0 ? read.letGoReads(readsHeld) : Effect.void));
268
- const shallows = yield* clientShallowsOf(request.shallows);
269
- const clientShallows = new Set(shallows.map((shallow) => shallow.oid));
268
+ const held = yield* clientShallowsOf(request.shallows);
269
+ const clientShallows = new Set(held.map((shallow) => shallow.oid));
270
+ const shallows = held.filter((shallow) => !read.roots.has(shallow.oid));
270
271
  const depth = request.depth;
271
272
  if (depth === void 0) {
272
273
  yield* given;
@@ -297,7 +298,8 @@ const indexShallow = /* @__PURE__ */ Effect.fnUntraced(function* (walk, request)
297
298
  yield* keep(2 * (edge.numbers.length + edge.extras.length) * 70);
298
299
  const edgeOids = yield* oidsOf(edge);
299
300
  const unshallowed = shallows.filter((shallow) => hasMet(within, shallow));
300
- const kept = shallows.filter((shallow) => !hasMet(within, shallow)).map((each) => each.oid);
301
+ const unshallowedIds = new Set(unshallowed.map((shallow) => shallow.oid));
302
+ const kept = [...clientShallows].filter((oid) => !unshallowedIds.has(oid));
301
303
  const starts = yield* startsOf(unshallowed);
302
304
  yield* given;
303
305
  return {
@@ -0,0 +1,127 @@
1
+ import { packIndexBytes } from "../protocol/packs/idx.mjs";
2
+ import { packPositionsBytes } from "../protocol/packs/pos.mjs";
3
+ import { bodyOfBytes, bucketDo, readEach } from "./calls.mjs";
4
+ import { indexBasesBytes, indexTypesBytes } from "./index-files.mjs";
5
+ import { indexGraphBytes } from "./index-graph.mjs";
6
+ import { indexFiles, isPackId, packFiles } from "./layout.mjs";
7
+ import * as Effect from "effect/Effect";
8
+ // src/storage/index-whole.ts
9
+ /**
10
+ * The most a fetch reads of a small index's files whole, all at once, before its walk: 1 MiB, the
11
+ * writer's meter. Its files are read in turn by range otherwise, one wait each (#2523): about 23
12
+ * for a small fetch, at about 70 ms a get on R2. Past it, they're read by range as before.
13
+ */
14
+ const wholeIndexMost = 1048576;
15
+ /**
16
+ * The files read at once, as the bitmaps' reads are: a small index's 6 in one round, and one over
17
+ * many packs in rounds of 16, never one get a file all open together.
18
+ */
19
+ const filesAtOnce = 16;
20
+ /** The packs whose `.idx` holds no 8-byte offsets: under 2 GiB. */
21
+ const smallPackBytes = 2 ** 31;
22
+ /**
23
+ * The files a fetch's walk and send list read of an index of `layers` over `packs`: each layer's
24
+ * `.graph`, `.bitmaps` when it has any, `.types` and `.bases` when it has deltas, and each pack's
25
+ * `.idx` and `.pos`, with the least each can be from the row and the listing, no call made: a
26
+ * graph's octopus rows aren't in the row, so its least counts none. An index with a region's rows
27
+ * or a pack past 2 GiB is none of these: `undefined`, so it's read by range.
28
+ */
29
+ const indexFilesOf = (repo, layers, packs) => {
30
+ const files = [];
31
+ for (const layer of layers) {
32
+ if (layer.groups.some((group) => group.rows > 0)) return void 0;
33
+ const at = indexFiles(repo, layer.build);
34
+ const positions = layer.first + layer.positions;
35
+ files.push({
36
+ key: at.graph,
37
+ least: indexGraphBytes(layer.commits, 0)
38
+ });
39
+ files.push({
40
+ key: at.types,
41
+ least: indexTypesBytes(layer.positions)
42
+ });
43
+ if (layer.bitmaps > 0) files.push({
44
+ key: at.bitmaps,
45
+ least: layer.table + layer.bitmaps * 20 + 20
46
+ });
47
+ if (layer.deltas > 0) files.push({
48
+ key: at.bases,
49
+ least: indexBasesBytes(positions, layer.deltas)
50
+ });
51
+ }
52
+ for (const pack of packs) {
53
+ if (pack.bytes >= smallPackBytes || !isPackId(pack.id)) return void 0;
54
+ const at = packFiles(pack.id);
55
+ files.push({
56
+ key: at.idx,
57
+ least: packIndexBytes(pack.objects, 0)
58
+ });
59
+ files.push({
60
+ key: at.pos,
61
+ least: packPositionsBytes(pack.objects)
62
+ });
63
+ }
64
+ return files;
65
+ };
66
+ /** A file read whole past what was left of the bound. */
67
+ var PastBound = class {
68
+ _tag = "PastBound";
69
+ };
70
+ /**
71
+ * Each of `files` read whole, `filesAtOnce` at a time, their buffers together at most `most`:
72
+ * `undefined` when they pass it, so the caller reads by range, as before. Each file's chunks are
73
+ * copied as they come into one buffer, the file's least to start, charged before it's made, so
74
+ * no chunk is kept and nothing live goes uncharged: one too small for a chunk is made again, at
75
+ * twice its size or the chunk's need, both charged while the copy runs, and the old one given
76
+ * back after. An empty chunk is skipped. A read's failure is the fetch's, as one by range is.
77
+ */
78
+ const wholeFiles = (bucket, files, most) => Effect.suspend(() => {
79
+ let left = most;
80
+ const read = (file) => Effect.suspend(() => {
81
+ let held = /* @__PURE__ */ new Uint8Array(0);
82
+ let length = 0;
83
+ /** `held` made again with room for `need`, charged first: false past the bound. */
84
+ const grow = (need) => {
85
+ const size = Math.max(need, Math.min(held.byteLength * 2, left));
86
+ if (size > left) return false;
87
+ left -= size;
88
+ const next = new Uint8Array(size);
89
+ next.set(held.subarray(0, length));
90
+ left += held.byteLength;
91
+ held = next;
92
+ return true;
93
+ };
94
+ const take = (chunk) => {
95
+ if (chunk.byteLength === 0) return Effect.void;
96
+ if (length + chunk.byteLength > held.byteLength && !grow(length + chunk.byteLength)) return Effect.fail(new PastBound());
97
+ held.set(chunk, length);
98
+ length += chunk.byteLength;
99
+ return Effect.void;
100
+ };
101
+ if (!grow(file.least)) return Effect.succeed(void 0);
102
+ return bucketDo(readEach(bucket, file.key, void 0, take).pipe(Effect.map(() => [file.key, held.subarray(0, length)]), Effect.catchTag("PastBound", () => Effect.succeed(void 0))));
103
+ });
104
+ return Effect.map(Effect.forEach(files, read, { concurrency: filesAtOnce }), (read) => {
105
+ const held = read.filter((file) => file !== void 0);
106
+ return held.length === files.length ? {
107
+ files: new Map(held),
108
+ bytes: most - left
109
+ } : void 0;
110
+ });
111
+ });
112
+ /**
113
+ * `bucket`, each of `files` read from the bytes held, with no call: a range as the bucket answers
114
+ * it, cut at the file's end, and the whole file without one. Every other key reads through.
115
+ */
116
+ const heldFiles = (bucket, files) => ({
117
+ ...bucket,
118
+ read: (key, range) => {
119
+ const whole = files.get(key);
120
+ if (whole === void 0) return bucket.read(key, range);
121
+ if (range === void 0) return bodyOfBytes(whole);
122
+ const from = Math.min(range.offset, whole.byteLength);
123
+ const to = Math.max(from, Math.min(range.offset + range.length, whole.byteLength));
124
+ return bodyOfBytes(whole.subarray(from, to));
125
+ }
126
+ });
127
+ export { heldFiles, indexFilesOf, wholeFiles, wholeIndexMost };