@ref0/git 0.20.0 → 0.26.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 (379) hide show
  1. package/dist/access/private-refs.mjs +1 -1
  2. package/dist/auth/access-jwt.mjs +3 -3
  3. package/dist/auth/auth-namespace.d.mts +3 -3
  4. package/dist/auth/auth-namespace.mjs +3 -2
  5. package/dist/auth/auth.d.mts +3 -3
  6. package/dist/auth/auth.mjs +9 -8
  7. package/dist/auth/authorize.mjs +1 -1
  8. package/dist/auth/fences.d.mts +1 -1
  9. package/dist/auth/host-function.mjs +1 -1
  10. package/dist/auth/host-services.mjs +4 -6
  11. package/dist/auth/identify.d.mts +1 -1
  12. package/dist/auth/identify.mjs +6 -0
  13. package/dist/auth/token-cleanup.mjs +2 -2
  14. package/dist/auth/token-rows.mjs +6 -1
  15. package/dist/auth/token-text.mjs +1 -1
  16. package/dist/auth/tokens-base.d.mts +1 -1
  17. package/dist/auth/tokens.d.mts +1 -1
  18. package/dist/auth/tokens.mjs +1 -1
  19. package/dist/client/client.d.mts +15 -7
  20. package/dist/client/client.mjs +21 -12
  21. package/dist/client/git-http.mjs +1 -1
  22. package/dist/client/local.mjs +60 -24
  23. package/dist/client/negotiate.mjs +3 -3
  24. package/dist/client/push-upload.mjs +26 -10
  25. package/dist/client/remote.mjs +4 -3
  26. package/dist/client/run-remote-helper.d.mts +2 -2
  27. package/dist/client/run-remote-helper.mjs +6 -6
  28. package/dist/client/slice-push.d.mts +1 -1
  29. package/dist/client/transport.mjs +3 -3
  30. package/dist/contracts/blobs.d.mts +3 -3
  31. package/dist/contracts/blobs.mjs +1 -1
  32. package/dist/contracts/calls-spent.mjs +5 -33
  33. package/dist/contracts/client.d.mts +15 -14
  34. package/dist/contracts/commits.d.mts +4 -4
  35. package/dist/contracts/commits.mjs +1 -1
  36. package/dist/contracts/engine.d.mts +2 -2
  37. package/dist/contracts/events.d.mts +1 -1
  38. package/dist/contracts/events.mjs +1 -1
  39. package/dist/contracts/files.d.mts +4 -4
  40. package/dist/contracts/files.mjs +1 -1
  41. package/dist/contracts/forks.d.mts +4 -4
  42. package/dist/contracts/forks.mjs +1 -1
  43. package/dist/contracts/git-hooks.d.mts +1 -1
  44. package/dist/contracts/git.d.mts +9 -5
  45. package/dist/contracts/grants.d.mts +1 -1
  46. package/dist/contracts/merges.d.mts +1 -1
  47. package/dist/contracts/object-values.d.mts +1 -0
  48. package/dist/contracts/object-values.mjs +16 -1
  49. package/dist/contracts/objects.d.mts +30 -18
  50. package/dist/contracts/opaque.mjs +1 -1
  51. package/dist/contracts/operations.mjs +1 -1
  52. package/dist/contracts/queue.d.mts +208 -44
  53. package/dist/contracts/queue.mjs +5 -5
  54. package/dist/contracts/refs.d.mts +5 -5
  55. package/dist/contracts/refs.mjs +1 -1
  56. package/dist/contracts/remote.d.mts +3 -6
  57. package/dist/contracts/repos.d.mts +3 -3
  58. package/dist/contracts/repos.mjs +1 -1
  59. package/dist/contracts/result.d.mts +10 -7
  60. package/dist/contracts/result.mjs +8 -3
  61. package/dist/contracts/rules.d.mts +13 -12
  62. package/dist/contracts/server.d.mts +8 -10
  63. package/dist/contracts/services.d.mts +6 -9
  64. package/dist/contracts/services.mjs +1 -2
  65. package/dist/contracts/signin.d.mts +1 -1
  66. package/dist/contracts/store.d.mts +2 -2
  67. package/dist/contracts/sync.d.mts +63 -6
  68. package/dist/contracts/sync.mjs +3 -2
  69. package/dist/contracts/tags.d.mts +3 -3
  70. package/dist/contracts/tags.mjs +1 -1
  71. package/dist/contracts/tokens.d.mts +2 -2
  72. package/dist/contracts/tokens.mjs +1 -1
  73. package/dist/contracts/topics.d.mts +9 -9
  74. package/dist/contracts/trees.d.mts +4 -4
  75. package/dist/contracts/trees.mjs +1 -1
  76. package/dist/contracts/work.d.mts +4 -4
  77. package/dist/contracts/work.mjs +2 -2
  78. package/dist/core/access.d.mts +1 -1
  79. package/dist/core/ancestry.mjs +30 -34
  80. package/dist/core/{promise.mjs → call-groups.mjs} +7 -30
  81. package/dist/core/call-services.mjs +1 -1
  82. package/dist/core/events/deliver.d.mts +2 -2
  83. package/dist/core/events/deliver.mjs +3 -3
  84. package/dist/core/events/retired.mjs +1 -1
  85. package/dist/core/forks.mjs +5 -5
  86. package/dist/core/hooks/groups.mjs +2 -2
  87. package/dist/core/imports.mjs +101 -21
  88. package/dist/core/index-job.mjs +14 -9
  89. package/dist/core/index-lost.d.mts +1 -1
  90. package/dist/core/loose-tally.mjs +38 -15
  91. package/dist/core/merge-parts.d.mts +17 -4
  92. package/dist/core/merge-parts.mjs +7 -2
  93. package/dist/core/mirror-rows.mjs +31 -1
  94. package/dist/core/objects/blobs.mjs +8 -10
  95. package/dist/core/objects/files.mjs +20 -17
  96. package/dist/core/objects/objects-layer.mjs +1 -1
  97. package/dist/core/objects/peel.mjs +1 -7
  98. package/dist/core/objects/reading.mjs +19 -18
  99. package/dist/core/objects/tree-edits.mjs +1 -1
  100. package/dist/core/objects/trees.mjs +257 -58
  101. package/dist/core/objects/writing.mjs +3 -9
  102. package/dist/core/own-writes.mjs +1 -1
  103. package/dist/core/parts.d.mts +8 -1
  104. package/dist/core/parts.mjs +8 -4
  105. package/dist/core/purge.mjs +31 -18
  106. package/dist/core/push.d.mts +2 -2
  107. package/dist/core/push.mjs +145 -98
  108. package/dist/core/receipts.d.mts +2 -2
  109. package/dist/core/receipts.mjs +9 -2
  110. package/dist/core/ref-index-job.mjs +4 -4
  111. package/dist/core/ref-view.mjs +74 -31
  112. package/dist/core/refs.mjs +3 -3
  113. package/dist/core/repack.mjs +25 -30
  114. package/dist/core/repo-info.mjs +1 -1
  115. package/dist/core/repos.mjs +1 -1
  116. package/dist/core/rules/changes.mjs +18 -40
  117. package/dist/core/rules/check.mjs +6 -5
  118. package/dist/core/rules/commit-changes.mjs +114 -58
  119. package/dist/core/rules/context.d.mts +3 -3
  120. package/dist/core/rules/context.mjs +18 -14
  121. package/dist/core/rules/fetch.mjs +1 -1
  122. package/dist/core/rules/protect.mjs +30 -17
  123. package/dist/core/saved-caller-views.d.mts +1 -1
  124. package/dist/core/saved-caller-views.mjs +3 -3
  125. package/dist/core/saved-callers.d.mts +1 -1
  126. package/dist/core/saved-callers.mjs +1 -1
  127. package/dist/core/seam.d.mts +1 -2
  128. package/dist/core/view.d.mts +6 -3
  129. package/dist/core/view.mjs +11 -10
  130. package/dist/core/work.mjs +2 -2
  131. package/dist/engine/allotted-xdiff.mjs +3 -16
  132. package/dist/engine/combined.d.mts +3 -0
  133. package/dist/engine/combined.mjs +200 -185
  134. package/dist/engine/content.d.mts +2 -2
  135. package/dist/engine/content.mjs +1 -1
  136. package/dist/engine/merge.mjs +7 -9
  137. package/dist/engine/reads.d.mts +2 -2
  138. package/dist/engine/reads.mjs +22 -14
  139. package/dist/engine/xdiff.d.mts +1 -1
  140. package/dist/engine/xdiff.mjs +1 -1
  141. package/dist/event-streams/event-streams.d.mts +1 -1
  142. package/dist/event-streams/event-streams.mjs +1 -1
  143. package/dist/event-streams/stream.d.mts +2 -2
  144. package/dist/event-streams/stream.mjs +3 -3
  145. package/dist/extend.d.mts +2 -6
  146. package/dist/extend.mjs +1 -5
  147. package/dist/http/core-parts.mjs +83 -26
  148. package/dist/http/handler.mjs +54 -9
  149. package/dist/http/parts.d.mts +1 -0
  150. package/dist/http/push-upload-job.mjs +138 -24
  151. package/dist/http/push-uploads.mjs +2 -2
  152. package/dist/http/receive-pack.mjs +14 -53
  153. package/dist/http/request-snapshot.mjs +258 -0
  154. package/dist/http/upload-pack.mjs +23 -18
  155. package/dist/index.d.mts +29 -21
  156. package/dist/index.mjs +11 -2
  157. package/dist/lfs/base.d.mts +1 -1
  158. package/dist/lfs/copy.d.mts +49 -1
  159. package/dist/lfs/copy.mjs +135 -22
  160. package/dist/lfs/layer.d.mts +4 -3
  161. package/dist/lfs/layer.mjs +4 -5
  162. package/dist/lfs/locks.mjs +2 -2
  163. package/dist/lfs/objects.d.mts +1 -1
  164. package/dist/lfs/objects.mjs +3 -3
  165. package/dist/lfs/pointers.mjs +1 -1
  166. package/dist/lfs/rows.d.mts +1 -1
  167. package/dist/lfs/rows.mjs +11 -4
  168. package/dist/lfs/upkeep.mjs +40 -9
  169. package/dist/lfs/uploaded.mjs +1 -1
  170. package/dist/lfs/wire.mjs +1 -1
  171. package/dist/merges/merges.mjs +17 -2
  172. package/dist/protocol/bytes/buffers.d.mts +1 -1
  173. package/dist/protocol/bytes/buffers.mjs +1 -1
  174. package/dist/protocol/bytes/deflate.d.mts +1 -1
  175. package/dist/protocol/bytes/deflate.mjs +1 -1
  176. package/dist/protocol/bytes/inflate.d.mts +1 -1
  177. package/dist/protocol/bytes/inflate.mjs +1 -1
  178. package/dist/protocol/bytes/sha1.d.mts +1 -1
  179. package/dist/protocol/bytes/sha1.mjs +1 -1
  180. package/dist/protocol/diff/read.d.mts +2 -1
  181. package/dist/protocol/diff/read.mjs +102 -8
  182. package/dist/protocol/packs/graph.mjs +1 -1
  183. package/dist/protocol/packs/idx.d.mts +1 -1
  184. package/dist/protocol/packs/idx.mjs +1 -1
  185. package/dist/protocol/packs/parts.mjs +1 -1
  186. package/dist/protocol/packs/reader.d.mts +1 -1
  187. package/dist/protocol/packs/reader.mjs +1 -1
  188. package/dist/protocol/packs/write-error.d.mts +1 -1
  189. package/dist/protocol/packs/write-error.mjs +1 -1
  190. package/dist/protocol/packs/writer.mjs +3 -3
  191. package/dist/protocol/wire/advertisement.d.mts +1 -1
  192. package/dist/protocol/wire/advertisement.mjs +3 -2
  193. package/dist/protocol/wire/fetch.d.mts +1 -1
  194. package/dist/protocol/wire/fetch.mjs +1 -1
  195. package/dist/protocol/wire/lines.d.mts +9 -1
  196. package/dist/protocol/wire/lines.mjs +28 -1
  197. package/dist/protocol/wire/push-uploads.mjs +10 -7
  198. package/dist/protocol/wire/receive-pack.d.mts +1 -1
  199. package/dist/protocol/wire/receive-pack.mjs +1 -1
  200. package/dist/protocol/wire/report-status.d.mts +1 -1
  201. package/dist/protocol/wire/report-status.mjs +1 -1
  202. package/dist/protocol/wire/v2.d.mts +1 -1
  203. package/dist/protocol/wire/v2.mjs +1 -1
  204. package/dist/queue/advance.mjs +31 -24
  205. package/dist/queue/base.d.mts +5 -3
  206. package/dist/queue/calls.mjs +5 -5
  207. package/dist/queue/commit.mjs +1 -1
  208. package/dist/queue/host.d.mts +1 -1
  209. package/dist/queue/layer.d.mts +0 -1
  210. package/dist/queue/layer.mjs +9 -5
  211. package/dist/queue/schedule.mjs +1 -1
  212. package/dist/queue/search.mjs +1 -1
  213. package/dist/queue/state.mjs +1 -1
  214. package/dist/queue/trim.mjs +2 -2
  215. package/dist/rest/client.d.mts +1 -1
  216. package/dist/rest/client.mjs +6 -6
  217. package/dist/rest/errors.mjs +1 -1
  218. package/dist/rest/handler.mjs +2 -2
  219. package/dist/rest/handlers.mjs +16 -6
  220. package/dist/rest/layer.mjs +1 -1
  221. package/dist/rest/listen.mjs +2 -2
  222. package/dist/rest/refs.mjs +1 -1
  223. package/dist/server/edge.mjs +27 -3
  224. package/dist/server/git-layer.d.mts +1 -2
  225. package/dist/server/git-layer.mjs +4 -5
  226. package/dist/server/lifecycle.mjs +1 -1
  227. package/dist/server/registry.mjs +2 -8
  228. package/dist/server/server.mjs +62 -43
  229. package/dist/signin/context.d.mts +1 -1
  230. package/dist/signin/context.mjs +1 -1
  231. package/dist/signin/forms.mjs +1 -1
  232. package/dist/signin/grants.d.mts +2 -2
  233. package/dist/signin/grants.mjs +1 -1
  234. package/dist/signin/wire.mjs +1 -1
  235. package/dist/storage/allotted.mjs +4 -9
  236. package/dist/storage/batch-upkeep.mjs +31 -12
  237. package/dist/storage/batches.d.mts +2 -3
  238. package/dist/storage/batches.mjs +52 -49
  239. package/dist/storage/budget.mjs +23 -1
  240. package/dist/storage/calls.d.mts +1 -1
  241. package/dist/storage/calls.mjs +41 -43
  242. package/dist/storage/charged-cache.mjs +180 -0
  243. package/dist/storage/chunks.d.mts +3 -3
  244. package/dist/storage/chunks.mjs +121 -8
  245. package/dist/storage/counted-bucket.mjs +32 -10
  246. package/dist/storage/fetch-row-cache.d.mts +6 -0
  247. package/dist/storage/fetch-row-cache.mjs +211 -0
  248. package/dist/storage/fetch.d.mts +1 -0
  249. package/dist/storage/fetch.mjs +54 -242
  250. package/dist/storage/held-types.d.mts +0 -1
  251. package/dist/storage/held-types.mjs +13 -4
  252. package/dist/storage/host-bucket.mjs +9 -4
  253. package/dist/storage/index-bitmaps.mjs +340 -65
  254. package/dist/storage/index-build.d.mts +2 -3
  255. package/dist/storage/index-build.mjs +274 -56
  256. package/dist/storage/index-fetch.d.mts +3 -1
  257. package/dist/storage/index-fetch.mjs +60 -21
  258. package/dist/storage/index-graph.mjs +1 -1
  259. package/dist/storage/index-layers.mjs +55 -25
  260. package/dist/storage/index-reach.mjs +15 -22
  261. package/dist/storage/index-whole.d.mts +7 -0
  262. package/dist/storage/index-whole.mjs +145 -37
  263. package/dist/storage/largest-files.mjs +1 -7
  264. package/dist/storage/layout.mjs +17 -1
  265. package/dist/storage/lfs-pointers.mjs +1 -6
  266. package/dist/storage/link-join.mjs +55 -16
  267. package/dist/storage/list-source.d.mts +7 -0
  268. package/dist/storage/list-source.mjs +288 -0
  269. package/dist/storage/loose.d.mts +8 -8
  270. package/dist/storage/loose.mjs +157 -91
  271. package/dist/storage/memory-budget.mjs +226 -22
  272. package/dist/storage/merge-cut.mjs +9 -6
  273. package/dist/storage/merge-fence.mjs +1 -1
  274. package/dist/storage/merge-row.mjs +1 -1
  275. package/dist/storage/merge.d.mts +2 -3
  276. package/dist/storage/merge.mjs +2 -2
  277. package/dist/storage/object-rows.d.mts +3 -3
  278. package/dist/storage/object-rows.mjs +179 -38
  279. package/dist/storage/pack-order.mjs +97 -44
  280. package/dist/storage/pack-ranges.mjs +44 -16
  281. package/dist/storage/pack-reads.d.mts +5 -3
  282. package/dist/storage/pack-reads.mjs +236 -72
  283. package/dist/storage/pack-receive.d.mts +1 -2
  284. package/dist/storage/pack-receive.mjs +24 -18
  285. package/dist/storage/packs.d.mts +1 -1
  286. package/dist/storage/packs.mjs +477 -116
  287. package/dist/storage/placed-reads.mjs +33 -16
  288. package/dist/storage/prune-seen.mjs +1 -1
  289. package/dist/storage/prune-walk.mjs +1 -1
  290. package/dist/storage/prune.mjs +4 -31
  291. package/dist/storage/push-allotment.mjs +26 -14
  292. package/dist/storage/push-uploads.mjs +195 -57
  293. package/dist/storage/pushed-commits.mjs +20 -1
  294. package/dist/storage/quarantine.d.mts +2 -3
  295. package/dist/storage/range-cache.mjs +175 -40
  296. package/dist/storage/raw-ids.mjs +39 -10
  297. package/dist/storage/ready.d.mts +2 -3
  298. package/dist/storage/ready.mjs +114 -38
  299. package/dist/storage/receive-bounds.mjs +31 -9
  300. package/dist/storage/receive-cache.d.mts +7 -0
  301. package/dist/storage/receive-cache.mjs +147 -0
  302. package/dist/storage/receive-files.mjs +1 -1
  303. package/dist/storage/receive-links.mjs +1 -1
  304. package/dist/storage/receive-state.d.mts +2 -2
  305. package/dist/storage/receive-state.mjs +6 -8
  306. package/dist/storage/receive-steps.d.mts +20 -0
  307. package/dist/storage/receive-steps.mjs +298 -13
  308. package/dist/storage/repack-backlog.mjs +1 -6
  309. package/dist/storage/repack-contained.mjs +2 -2
  310. package/dist/storage/repack-job.mjs +1 -1
  311. package/dist/storage/repack.d.mts +2 -3
  312. package/dist/storage/repack.mjs +54 -9
  313. package/dist/storage/request-cache.mjs +57 -0
  314. package/dist/storage/roots.mjs +1 -24
  315. package/dist/storage/rows.d.mts +2 -2
  316. package/dist/storage/rows.mjs +1 -1
  317. package/dist/storage/runs.d.mts +2 -2
  318. package/dist/storage/runs.mjs +1 -1
  319. package/dist/storage/send-list.mjs +62 -25
  320. package/dist/storage/stream-whole.mjs +84 -63
  321. package/dist/storage/swap-walk.mjs +1 -1
  322. package/dist/storage/unpack.mjs +878 -450
  323. package/dist/storage/visible.mjs +110 -32
  324. package/dist/storage/walk.mjs +1 -0
  325. package/dist/storage/wants.mjs +22 -58
  326. package/dist/store/call-count.d.mts +2 -2
  327. package/dist/store/call-count.mjs +24 -11
  328. package/dist/store/catalogue.d.mts +1 -1
  329. package/dist/store/catalogue.mjs +19 -7
  330. package/dist/store/crossing.mjs +1 -7
  331. package/dist/store/cursor-seal.d.mts +1 -1
  332. package/dist/store/cursor-seal.mjs +1 -1
  333. package/dist/store/door.mjs +9 -4
  334. package/dist/store/errors.d.mts +2 -2
  335. package/dist/store/errors.mjs +107 -19
  336. package/dist/store/git-store.mjs +7 -2
  337. package/dist/store/job-try.mjs +90 -9
  338. package/dist/store/list-job.mjs +10 -34
  339. package/dist/store/outbox.d.mts +2 -2
  340. package/dist/store/outbox.mjs +2 -2
  341. package/dist/store/queue-jobs.mjs +6 -12
  342. package/dist/store/records.d.mts +2 -2
  343. package/dist/store/records.mjs +2 -2
  344. package/dist/store/ref-rows.d.mts +2 -2
  345. package/dist/store/ref-rows.mjs +2 -2
  346. package/dist/store/repo-record.d.mts +2 -2
  347. package/dist/store/repo-record.mjs +3 -3
  348. package/dist/store/request-snapshot.mjs +5 -0
  349. package/dist/store/reservations.mjs +2 -2
  350. package/dist/store/topic-jobs.mjs +5 -11
  351. package/dist/sync/bound.d.mts +3 -3
  352. package/dist/sync/bound.mjs +10 -7
  353. package/dist/sync/github.mjs +65 -67
  354. package/dist/sync/http.mjs +1 -1
  355. package/dist/sync/import.mjs +201 -66
  356. package/dist/sync/layer.d.mts +1 -1
  357. package/dist/sync/layer.mjs +6 -6
  358. package/dist/sync/lfs-batch.mjs +1 -1
  359. package/dist/sync/lfs-copy.mjs +175 -15
  360. package/dist/sync/mirror.mjs +5 -10
  361. package/dist/sync/said.mjs +1 -1
  362. package/dist/sync/step.mjs +268 -86
  363. package/dist/sync/tries.mjs +25 -6
  364. package/dist/sync.d.mts +2 -2
  365. package/dist/sync.mjs +2 -2
  366. package/dist/topics/advance.mjs +3 -3
  367. package/dist/topics/calls.mjs +1 -1
  368. package/dist/topics/layer.d.mts +15 -14
  369. package/dist/topics/members.mjs +1 -1
  370. package/dist/topics/topic.mjs +1 -1
  371. package/package.json +3 -13
  372. package/dist/auth/helpers.mjs +0 -17
  373. package/dist/auth.d.mts +0 -5
  374. package/dist/auth.mjs +0 -5
  375. package/dist/core/rules/commit-changes.d.mts +0 -12
  376. package/dist/effect.d.mts +0 -9
  377. package/dist/effect.mjs +0 -7
  378. package/dist/server/joined.d.mts +0 -70
  379. package/dist/server/joined.mjs +0 -41
@@ -1,4 +1,5 @@
1
1
  import "../contracts/ids.mjs";
2
+ import { objectsReadMost } from "../contracts/object-values.mjs";
2
3
  import { gitError, gitErrorFrom } from "../contracts/result.mjs";
3
4
  import { partialImporter } from "./import.mjs";
4
5
  import { importedPullRefs } from "../contracts/sync.mjs";
@@ -6,9 +7,10 @@ import { push } from "../core/push.mjs";
6
7
  import { refusedLead } from "../client/answer.mjs";
7
8
  import { isRefName } from "../core/names.mjs";
8
9
  import { cutWords, utf8 } from "../protocol/bytes/text.mjs";
10
+ import { readCommit } from "../protocol/objects/commit.mjs";
9
11
  import { negotiate } from "../client/negotiate.mjs";
10
12
  import { discover, fetchTerms, remoteRefsAndHeadOf } from "../client/remote.mjs";
11
- import { oneShotReads, scopedReceiveStep } from "../storage/calls.mjs";
13
+ import { heldOnce, oneShotReads, scopedReader, scopedReceiveStep } from "../storage/calls.mjs";
12
14
  import { isPackId } from "../storage/layout.mjs";
13
15
  import { receiveCutParentsMost } from "../storage/receive-bounds.mjs";
14
16
  import { ReceiveRow, receiveKey, stagedRow } from "../storage/receive-steps.mjs";
@@ -21,18 +23,19 @@ import { listJobRow } from "../store/list-job.mjs";
21
23
  import { StoredRepo } from "../store/records.mjs";
22
24
  import { newChangeId, repoScope, selfKey } from "../store/scopes.mjs";
23
25
  import { asSync } from "./bound.mjs";
24
- import { copyLfs, withLfsPages } from "./lfs-copy.mjs";
25
- import { ImportRow, cancelKey, cutKey, cutRow, failedHint, failedRow, importEndDeletes, importKey, importRow, readImport, readTipPages, stoppedTry, tipPageKey, tipPageRow, tipPagesOf, tipRowBytes } from "../core/imports.mjs";
26
- import { ForGood, SyncTryError, forGood, fromRemote, httpOf, keptFieldsOf, openedFor, remoteOf, syncObjects, thrownOf, tried } from "./tries.mjs";
26
+ import { copyLfs, leftUpload, withLfsPages } from "./lfs-copy.mjs";
27
+ import { ImportRow, cancelKey, cutKey, cutRow, deepenReceiptPut, failedHint, failedRow, importEndDeletes, importKey, importRow, readImport, readTipPages, startRootsKey, startRootsOf, stoppedDeepen, stoppedTry, tipPageKey, tipPageRow, tipPagesOf, tipRowBytes } from "../core/imports.mjs";
28
+ import { infoReads, repoInfo } from "../core/repo-info.mjs";
29
+ import { ForGood, SyncTryError, forGood, fromRemote, httpOf, keptFieldsOf, openedFor, remoteOf, syncObjects, thrownOf, tooManyRoots, tried } from "./tries.mjs";
27
30
  import { currentRepo } from "../store/job-try.mjs";
28
31
  import { CoreParts, ObjectsParts } from "../core/parts.mjs";
29
32
  import { importOwner } from "../protocol/wire/lines.mjs";
30
33
  import { repoAccess } from "../core/access.mjs";
31
34
  import { viewAgainOf } from "../core/saved-caller-views.mjs";
32
- import * as Effect from "effect/Effect";
35
+ import { CurrentJob } from "@ref0/infra";
33
36
  import * as Schema from "effect/Schema";
37
+ import * as Effect from "effect/Effect";
34
38
  import * as Result from "effect/Result";
35
- import { CurrentJob } from "@ref0/infra";
36
39
  // src/sync/step.ts
37
40
  /**
38
41
  * One try of `sync.import`: one step of the import, committed with its record, so a try after
@@ -57,7 +60,7 @@ import { CurrentJob } from "@ref0/infra";
57
60
  */
58
61
  /** The deepest a segment's step grows: past it, a segment's history is whole anyway. */
59
62
  const stepMost = 1 << 20;
60
- const noDeepen = () => gitError("FAILED_PRECONDITION", "The remote doesn't take a shallow fetch, so no import of it stops at a depth", { hint: "Import it again without a depth" });
63
+ const noDeepen = (relative = false) => gitError("FAILED_PRECONDITION", relative ? "The remote doesn't take a relative deepen" : "The remote doesn't take a shallow fetch, so no import of it stops at a depth", { hint: relative ? "Pass 'unshallow: true' to fetch the rest of the history" : "Import it again without a depth" });
61
64
  const tooManyTips = (limits, bytes) => gitError("RESOURCE_EXHAUSTED", `The remote's branches and tags take ${bytes} bytes as refs`, {
62
65
  hint: `An import takes branches and tags of at most ${limits.tipBytes} bytes together, as a repo's refs count them`,
63
66
  context: {
@@ -203,35 +206,34 @@ const saved = (attempt, version, row, deletes = [], puts = []) => Effect.flatMap
203
206
  })));
204
207
  const more = { kind: "more" };
205
208
  const endedUnder = () => gitError("FAILED_PRECONDITION", "The import ended while its step ran", { hint: "Its record is no longer running, so the step writes nothing" });
206
- /** The import's record as a guard's read finds it, failing `endedUnder` unless it's running. */
207
- const runningIn = /* @__PURE__ */ Effect.fnUntraced(function* (rows) {
209
+ /** The import's record as a guard's read finds it, failing `endedUnder` unless running for `run`. */
210
+ const runningIn = /* @__PURE__ */ Effect.fnUntraced(function* (rows, run) {
208
211
  const [own] = rows ?? [];
209
212
  const row = own === void 0 ? void 0 : yield* decodeRow(ImportRow, own, "Import");
210
- if (row?.state !== "running") return yield* Effect.fail(endedUnder());
213
+ if (row?.state !== "running" || row.deepen?.run !== run) return yield* Effect.fail(endedUnder());
211
214
  return row;
212
215
  });
213
216
  /**
214
- * A step's push guard: the import's record still `running` in the push's own read, so a step whose
215
- * import another write ended since, such as the core's `failed` for a job gone, writes nothing.
217
+ * A step's push guard: the import's record still `running` for `run` in the push's own read, so a
218
+ * step whose import another write ended or superseded writes nothing.
216
219
  */
217
- const stillRunning = {
220
+ const stillRunning = (run) => ({
218
221
  reads: [importKey],
219
- check: (results) => Effect.asVoid(runningIn(results[0]))
220
- };
222
+ check: (results) => Effect.asVoid(runningIn(results[0], run))
223
+ });
221
224
  const cancelledUnder = () => gitError("FAILED_PRECONDITION", "The import was cancelled while it published", { hint: "It moves no more refs, and answers as cancelled" });
222
225
  const pageMovedUnder = () => gitError("UNAVAILABLE", "Another try moved the import's publish past this page first", { hint: "The job tries again, from the page its record names then" });
223
226
  /**
224
- * Publish's push guard for `page`: `stillRunning`, the record's cursor still at `page`, and no
225
- * cancel saved beside the record. So a try that read the record before another's page landed
226
- * never moves the cursor back, and a cancel saved since the try read the import moves no more
227
- * refs, the pages published before it staying, and `import` answers `import-cancelled`. A landing
228
- * keeps `stillRunning` alone: a segment in flight as a cancel commits still lands, and its objects
229
- * stay readable, as `CancelImport` says.
227
+ * Publish's push guard for `page` and optional deepen `run`: `stillRunning(run)`, the record's
228
+ * cursor still at `page`, and no cancel saved beside the record. So a try that read the record
229
+ * before another's page landed or another deepen replaced it never overwrites the newer run, and a
230
+ * cancel saved since moves no more refs. A landing keeps `stillRunning(run)` alone: a segment in
231
+ * flight as a cancel commits still lands, and its objects stay readable, as `CancelImport` says.
230
232
  */
231
- const uncancelled = (page) => ({
232
- reads: [...stillRunning.reads, cancelKey],
233
+ const uncancelled = (page, run) => ({
234
+ reads: [importKey, cancelKey],
233
235
  check: /* @__PURE__ */ Effect.fnUntraced(function* (results) {
234
- if (((yield* runningIn(results[0])).publishedPages ?? 0) !== page) return yield* Effect.fail(pageMovedUnder());
236
+ if (((yield* runningIn(results[0], run)).publishedPages ?? 0) !== page) return yield* Effect.fail(pageMovedUnder());
235
237
  const [cancel] = results[1] ?? [];
236
238
  if (cancel !== void 0) return yield* Effect.fail(cancelledUnder());
237
239
  })
@@ -265,10 +267,61 @@ const pullTips = (refs, own, limits) => {
265
267
  }
266
268
  return kept;
267
269
  };
270
+ /** Which of `oids` are already held in `listed`, checked in batches of `objectsReadMost`. */
271
+ const heldBatched = /* @__PURE__ */ Effect.fnUntraced(function* (objects, listed, oids) {
272
+ const held = /* @__PURE__ */ new Set();
273
+ for (let at = 0; at < oids.length; at += objectsReadMost) {
274
+ const found = yield* heldOnce(objects, listed, { oids: oids.slice(at, at + objectsReadMost) });
275
+ for (const oid of found) held.add(oid);
276
+ }
277
+ return held;
278
+ });
279
+ /** Bytes held at once while reading stored shallow-root commits to seed a deepen's cut. */
280
+ const rootReadBytes = 4194304;
281
+ /**
282
+ * The initial cut for a deepen: every stored parent of every shallow root in `roots`, read from
283
+ * the commits' raw stored bytes within an allotment so storage's `needs` check requires every
284
+ * parent of every unshallowed root before any segment lands or any root moves.
285
+ */
286
+ const cutOfRoots = (objects, listed, roots) => Effect.scoped(Effect.gen(function* () {
287
+ const tooLarge = gitError("RESOURCE_EXHAUSTED", "Shallow root too large", { context: { reason: "too-large" } });
288
+ const reader = yield* scopedReader(objects, listed);
289
+ const bytes = reader.allotment(rootReadBytes, tooLarge);
290
+ const cut = {};
291
+ let total = 0;
292
+ const queue = [...roots];
293
+ while (queue.length > 0) {
294
+ const batch = queue.splice(0, objectsReadMost);
295
+ const read = yield* reader.objects({
296
+ oids: batch,
297
+ bytes
298
+ });
299
+ const leftSet = new Set(read.left);
300
+ for (const oid of batch) {
301
+ if (leftSet.has(oid)) continue;
302
+ const object = read.objects.get(oid);
303
+ if (object !== void 0) bytes.shrink(object.bytes.byteLength);
304
+ const commit = object?.type === "commit" ? readCommit(object.bytes) : void 0;
305
+ if (commit === void 0 || Result.isFailure(commit)) return yield* forGood(gitError("DATA_LOSS", `Shallow root ${oid} unreadable`));
306
+ const { parents } = commit.success;
307
+ if (parents.length === 0) continue;
308
+ total += parents.length;
309
+ if (total > receiveCutParentsMost) return yield* forGood(gitError("RESOURCE_EXHAUSTED", `Over ${receiveCutParentsMost} shallow root parents`, { context: {
310
+ reason: "too-large",
311
+ limit: receiveCutParentsMost
312
+ } }));
313
+ cut[oid] = parents;
314
+ }
315
+ if (read.left.length >= batch.length) return yield* forGood(tooLarge);
316
+ queue.unshift(...read.left);
317
+ }
318
+ return cut;
319
+ }));
268
320
  /**
269
321
  * Step 1: the remote's branches and tags, and their tips, kept in pages beside the import's
270
322
  * record, with the pull requests' heads that fit beside them, in the commit that moves the record
271
- * past the listing.
323
+ * past the listing. For a deepen, also seeds `imports/cut` from the repo's stored shallow roots
324
+ * and adopts no default branch.
272
325
  */
273
326
  const listTips = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version, row, remote) {
274
327
  yield* report(attempt.context, "fetch", row);
@@ -286,7 +339,7 @@ const listTips = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version,
286
339
  const { limits } = attempt.bound;
287
340
  if (own > limits.tipBytes) return yield* forGood(tooManyTips(limits, own));
288
341
  const all = [...refs, ...pullTips(listing, own, limits)];
289
- const adopts = head?.startsWith("refs/heads/") === true && refs.has(head) ? head : void 0;
342
+ const adopts = row.deepen === void 0 && head?.startsWith("refs/heads/") === true && refs.has(head) ? head : void 0;
290
343
  const pages = tipPagesOf(all.sort(([a], [b]) => a < b ? -1 : 1), adopts, {
291
344
  bytes: limits.tipPageBytes,
292
345
  most: limits.publishBatch
@@ -295,10 +348,17 @@ const listTips = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version,
295
348
  ...row,
296
349
  tipPages: pages.length,
297
350
  publishedPages: 0,
298
- copied: all.length === 0
351
+ copied: row.deepen === void 0 && all.length === 0
299
352
  };
300
353
  if (adopts !== void 0) listedRow.head = adopts;
301
- yield* saved(attempt, version, listedRow, [], pages.map((tips, page) => tipPageRow(page, tips)));
354
+ const puts = pages.map((tips, page) => tipPageRow(page, tips));
355
+ if (row.deepen !== void 0) {
356
+ const opened = yield* openedRepo(attempt);
357
+ if (opened === void 0) return void 0;
358
+ const initialCut = yield* cutOfRoots(syncObjects(yield* ObjectsParts), opened.listed, row.roots);
359
+ if (Object.keys(initialCut).length > 0) puts.push(cutRow(row.roots, initialCut));
360
+ }
361
+ yield* saved(attempt, version, listedRow, [], puts);
302
362
  return more;
303
363
  });
304
364
  /**
@@ -306,6 +366,20 @@ const listTips = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, version,
306
366
  * check's refusal answers no: a defect in it stays a defect.
307
367
  */
308
368
  const deepens = (upload) => Effect.isSuccess(fetchTerms(upload, { depth: 1 }));
369
+ /** Most unreachable shallow root OIDs named verbatim in `unreachableRoots`' error message. */
370
+ const unreachableRootsMost = 8;
371
+ /** Typed refusal when the remote cannot serve history behind one or more hosted shallow roots. */
372
+ const unreachableRoots = (roots) => {
373
+ const shown = roots.slice(0, unreachableRootsMost).join(", ");
374
+ const rest = roots.length > unreachableRootsMost ? ` (+${roots.length - unreachableRootsMost} more)` : "";
375
+ return gitError("FAILED_PRECONDITION", `Remote cannot serve shallow root(s): ${shown}${rest}`, {
376
+ hint: "Pass a source with these commits",
377
+ context: {
378
+ reason: "shallow-roots-unreachable",
379
+ total: roots.length
380
+ }
381
+ });
382
+ };
309
383
  /** The pack as it arrives, counted, and stopped once it runs past `most` bytes. */
310
384
  const counted = (bytes, most) => {
311
385
  const seen = {
@@ -394,44 +468,113 @@ const fetchSegment = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row,
394
468
  const { http, heard } = yield* httpOf(remote, keptFieldsOf(bound, row.source));
395
469
  const upload = yield* Effect.mapError(discover(http), advertisedFrom(remote, "advertise its refs", heard));
396
470
  const shallow = yield* deepens(upload);
397
- if (!shallow && row.depth !== void 0) return yield* forGood(noDeepen());
398
- const asked = row.depth ?? 2147483647;
399
- const wanted = Math.min(row.deepest + row.step, asked);
400
- const request = {
401
- wants: tips,
402
- shallows: [...row.roots],
403
- includeTag: false
404
- };
405
- if (shallow) request.depth = wanted;
406
- const terms = yield* fetchTerms(upload, shallow ? { depth: wanted } : {});
407
- const negotiated = yield* negotiate({
471
+ const deepening = row.deepen;
472
+ if (!shallow && (deepening === void 0 ? row.depth !== void 0 : deepening.more !== void 0)) return yield* forGood(noDeepen());
473
+ const relative = deepening !== void 0 && shallow && (yield* Effect.isSuccess(fetchTerms(upload, { deepen: 1 }, true)));
474
+ const rootsWithParents = deepening === void 0 ? [] : row.roots.filter((oid) => (cut[oid]?.length ?? 0) > 0);
475
+ const missingParents = [...new Set(rootsWithParents.flatMap((oid) => cut[oid] ?? []))];
476
+ const tipSet = new Set(tips);
477
+ const canWantParents = missingParents.length > 0 && (upload.version === "v2" || upload.capabilities.includes("allow-tip-sha1-in-want") || upload.capabilities.includes("allow-reachable-sha1-in-want") || missingParents.every((oid) => tipSet.has(oid)));
478
+ const deepenStep = deepening?.more === void 0 ? row.step : Math.min(row.step, deepening.more - row.deepest);
479
+ const runNegotiate = (req, reqTerms, useHeld) => negotiate({
408
480
  http,
409
481
  version: upload.version,
410
- ...terms,
482
+ ...reqTerms,
411
483
  ofsDelta: false,
412
- request,
484
+ request: req,
413
485
  objects: oneShotReads(objects),
414
486
  listed: opened.listed,
415
- tips: [...new Set(opened.refs.values())],
416
- held: row.deepest > 0 ? tips : []
417
- }).pipe(Effect.mapError(fromRemote("negotiate a fetch", heard)));
487
+ tips: !useHeld ? [] : deepening === void 0 ? [...new Set(opened.refs.values())] : shallow ? [.../* @__PURE__ */ new Set([...opened.refs.values(), ...row.roots])] : [],
488
+ held: useHeld && row.deepest > 0 && shallow ? tips : []
489
+ });
490
+ let negotiated;
491
+ let nextDeepest = infiniteDepth;
492
+ let reachedTarget = true;
493
+ let canHalve = false;
494
+ let parentAnchored = false;
495
+ if (deepening?.more !== void 0 && !relative && tips.length > 0 && !canWantParents) return yield* forGood(noDeepen(true));
496
+ const negotiateError = fromRemote("negotiate a fetch", heard);
497
+ if (deepening === void 0 || tips.length > 0 && (relative || deepening.more === void 0)) {
498
+ const request = {
499
+ wants: tips,
500
+ shallows: shallow ? [...row.roots] : [],
501
+ includeTag: false
502
+ };
503
+ let terms;
504
+ if (deepening === void 0) {
505
+ const asked = row.depth ?? 2147483647;
506
+ const wanted = Math.min(row.deepest + row.step, asked);
507
+ if (shallow) request.depth = wanted;
508
+ terms = yield* fetchTerms(upload, shallow ? { depth: wanted } : {});
509
+ nextDeepest = shallow ? wanted : infiniteDepth;
510
+ reachedTarget = wanted >= asked;
511
+ canHalve = shallow;
512
+ } else if (relative) {
513
+ request.depth = deepenStep;
514
+ request.deepenRelative = true;
515
+ terms = yield* fetchTerms(upload, { deepen: deepenStep }, true);
516
+ nextDeepest = row.deepest + deepenStep;
517
+ reachedTarget = deepening.more !== void 0 && nextDeepest >= deepening.more;
518
+ canHalve = true;
519
+ } else {
520
+ if (shallow) request.depth = infiniteDepth;
521
+ terms = yield* fetchTerms(upload, shallow ? { unshallow: true } : {}, shallow);
522
+ }
523
+ negotiated = yield* runNegotiate(request, terms, true).pipe(Effect.mapError(negotiateError));
524
+ }
525
+ if (deepening !== void 0) {
526
+ const unshallowed = new Set(negotiated?.unshallow ?? []);
527
+ const uncovered = rootsWithParents.filter((oid) => !unshallowed.has(oid));
528
+ if (negotiated === void 0 || uncovered.length > 0) {
529
+ negotiated?.pack.cancel();
530
+ const missed = uncovered.length > 0 ? uncovered : row.roots;
531
+ if (!canWantParents) return yield* forGood(unreachableRoots(missed));
532
+ const depth = shallow ? deepenStep : void 0;
533
+ const parentRequest = {
534
+ wants: missingParents,
535
+ shallows: [],
536
+ includeTag: false
537
+ };
538
+ if (depth !== void 0) parentRequest.depth = depth;
539
+ const parentTerms = yield* fetchTerms(upload, depth !== void 0 ? { depth } : {});
540
+ nextDeepest = shallow ? row.deepest + deepenStep : infiniteDepth;
541
+ reachedTarget = !shallow || deepening.more !== void 0 && nextDeepest >= deepening.more;
542
+ canHalve = shallow;
543
+ negotiated = yield* runNegotiate(parentRequest, parentTerms, false).pipe(Effect.catchIf((error) => error.code === "FAILED_PRECONDITION", () => forGood(unreachableRoots(missed))), Effect.mapError((error) => error instanceof ForGood ? error : negotiateError(error)));
544
+ parentAnchored = true;
545
+ }
546
+ }
547
+ if (negotiated === void 0) return yield* forGood(unreachableRoots(row.roots));
418
548
  yield* report(context, "receive", row);
419
549
  const { pack } = negotiated;
420
550
  const { stream, seen } = counted(pack.bytes, most);
421
- const roots = shallow ? rootsAfter(row.roots, negotiated) : [];
551
+ const roots = !shallow ? [] : parentAnchored ? rootsAfter(row.roots, {
552
+ shallow: negotiated.shallow,
553
+ unshallow: rootsWithParents
554
+ }) : rootsAfter(row.roots, negotiated);
422
555
  if (roots.length > bound.limits.rootsMost) {
423
556
  pack.cancel();
424
- return yield* forGood(gitError("RESOURCE_EXHAUSTED", `An import takes at most ${bound.limits.rootsMost} shallow roots`, { context: {
425
- reason: "too-large",
426
- limit: bound.limits.rootsMost
427
- } }));
557
+ return yield* forGood(tooManyRoots(bound.limits.rootsMost));
428
558
  }
429
- const copied = roots.length === 0 || wanted >= asked || row.roots.length > 0 && sameRoots(roots, row.roots);
559
+ const copied = roots.length === 0 || reachedTarget || deepening === void 0 && row.roots.length > 0 && sameRoots(roots, row.roots);
430
560
  const pushedPack = {
431
561
  bytes: stream,
432
562
  objects: pack.objects
433
563
  };
434
- if (shallow && negotiated.shallow.length > 0) pushedPack.boundary = negotiated.shallow;
564
+ const beforeRoots = new Set(row.roots);
565
+ const candidateBoundary = shallow ? negotiated.shallow.filter((oid) => !beforeRoots.has(oid)) : [];
566
+ let boundary = candidateBoundary;
567
+ if (candidateBoundary.length > 0) boundary = yield* Effect.gen(function* () {
568
+ const heldInRepo = yield* heldBatched(objects, opened.listed, candidateBoundary);
569
+ const inRepo = candidateBoundary.filter((oid) => heldInRepo.has(oid));
570
+ if (inRepo.length === 0) return candidateBoundary;
571
+ const parentsByRoot = yield* cutOfRoots(objects, opened.listed, inRepo);
572
+ const allParents = [...new Set(Object.values(parentsByRoot).flat())];
573
+ const heldParents = yield* heldBatched(objects, opened.listed, allParents);
574
+ const complete = new Set(inRepo.filter((oid) => (parentsByRoot[oid] ?? []).every((p) => heldParents.has(p))));
575
+ return candidateBoundary.filter((oid) => !complete.has(oid));
576
+ }).pipe(Effect.onError(() => Effect.sync(() => pack.cancel())));
577
+ if (boundary.length > 0) pushedPack.boundary = boundary;
435
578
  const { needs, kept } = carriedCut(row.roots, roots, cut);
436
579
  if (needs.length > 0) pushedPack.needs = needs;
437
580
  pushedPack.cutMost = kept.reduce((left, [, parents]) => left - parents.length, receiveCutParentsMost);
@@ -440,7 +583,7 @@ const fetchSegment = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row,
440
583
  const next = () => ({
441
584
  ...fetched,
442
585
  roots,
443
- deepest: shallow ? wanted : infiniteDepth,
586
+ deepest: nextDeepest,
444
587
  step: stepAfter(row.step, seen.bytes, most),
445
588
  copied,
446
589
  objects: row.objects + pack.objects,
@@ -480,7 +623,7 @@ const fetchSegment = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row,
480
623
  jobs: []
481
624
  };
482
625
  },
483
- guard: stillRunning,
626
+ guard: stillRunning(row.deepen?.run),
484
627
  signal: stopped.signal
485
628
  });
486
629
  const pushed = yield* Effect.result(sent.pipe(Effect.mapError((error) => {
@@ -498,7 +641,7 @@ const fetchSegment = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row,
498
641
  if (final !== void 0) return yield* forGood(final);
499
642
  const refused = failure.code === "RESOURCE_EXHAUSTED" && halvedReasons.has(failure.context?.reason);
500
643
  if (!seen.over && !refused) return yield* Effect.fail(failure);
501
- if (!shallow || row.step === 1) return yield* forGood(seen.over ? overBudget(most) : leastRefused(failure, shallow));
644
+ if (!canHalve || row.step === 1) return yield* forGood(seen.over ? overBudget(most) : leastRefused(failure, canHalve));
502
645
  return yield* unstaged(attempt, row, { step: halvedStep(row) }, halvingRaced);
503
646
  });
504
647
  /** The fields of `row` a segment's landing writes, as its fetch made them. */
@@ -523,7 +666,7 @@ const staged = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, stagin
523
666
  if (!isPackId(pack)) return yield* Effect.fail(unsteppedPack(pack));
524
667
  const read = yield* readOwn(attempt);
525
668
  const now = read.row;
526
- const same = now?.state === "running" && now.step === row.step && now.deepest === row.deepest;
669
+ const same = now?.state === "running" && now.deepen?.run === row.deepen?.run && now.step === row.step && now.deepest === row.deepest;
527
670
  if (read.cancelled || now === void 0 || !same || now.receiving !== void 0) return;
528
671
  if (!(yield* saved(attempt, read.version, {
529
672
  ...now,
@@ -611,7 +754,7 @@ const resumedIn = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, rec
611
754
  jobs: []
612
755
  };
613
756
  },
614
- guard: stillRunning
757
+ guard: stillRunning(row.deepen?.run)
615
758
  });
616
759
  return more;
617
760
  });
@@ -642,7 +785,7 @@ const stageGoneAgain = () => gitError("FAILED_PRECONDITION", "Clean-up ended the
642
785
  const unstaged = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, next, raced) {
643
786
  const read = yield* readOwn(attempt);
644
787
  const now = read.row;
645
- const same = now?.state === "running" && now.step === row.step && now.deepest === row.deepest;
788
+ const same = now?.state === "running" && now.deepen?.run === row.deepen?.run && now.step === row.step && now.deepest === row.deepest;
646
789
  if (read.cancelled || now === void 0 || !same) return more;
647
790
  const { receiving, restaged: _restaged, ...rest } = now;
648
791
  const deletes = receiving === void 0 ? [] : [receiveKey(receiving.pack)];
@@ -687,18 +830,56 @@ const publishGuard = (read, page) => {
687
830
  };
688
831
  };
689
832
  /**
690
- * Step 3: the next page's refs moved to their tips, in one atomic commit that moves the record's
691
- * cursor past the page and deletes it. The first page's writes the import's roots as the repo's,
692
- * so no ref names a commit whose parents the repo lacks, and no walk from one reads past them. The
693
- * last page's marks the import done instead, with the
694
- * remote's default branch made the repo's when it's one of the tips, which the listing put on that
695
- * page. A ref another write moved first fails the try, and the next moves the page's refs from
696
- * where they are then; a refusal of another kind fails it with that ref's own error.
833
+ * Step 3: for a deepen, moves the repo's shallow roots in one atomic write via `rootsMoved`
834
+ * (moving no ref and adopting no default branch), marks the deepen done, and cleans up temporary
835
+ * import keys. For an initial import, moves the next page's refs to their tips, writing the
836
+ * import's roots on the first page and adopting the remote's default branch on the last.
697
837
  */
698
- const publish = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row) {
838
+ const publish = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row, caller) {
699
839
  const opened = yield* openedRepo(attempt);
700
840
  if (opened === void 0) return void 0;
701
841
  const { store } = yield* CoreParts;
842
+ const baseRequest = {
843
+ caller: attempt.bound.caller,
844
+ repo: opened.name,
845
+ internalId: attempt.internalId,
846
+ source: "import",
847
+ as: importOwner,
848
+ atomic: true
849
+ };
850
+ if (row.deepen !== void 0) {
851
+ const { deepen } = row;
852
+ const [startRootsRows, ...infoResults] = (yield* storeCall(store.read(repoScope(attempt.internalId), [startRootsKey, ...deepen.receipt !== void 0 ? infoReads : []]))).results;
853
+ const startRoots = yield* startRootsOf(startRootsRows).pipe(Effect.catchIf((error) => error.code === "DATA_LOSS", forGood));
854
+ yield* report(attempt.context, "publish", row);
855
+ const startSet = new Set(startRoots);
856
+ const finalSet = new Set(row.roots);
857
+ const shallow = row.roots.filter((oid) => !startSet.has(oid));
858
+ const unshallow = startRoots.filter((oid) => !finalSet.has(oid));
859
+ const receiptPut = deepen.receipt === void 0 ? [] : deepenReceiptPut(deepen, { info: {
860
+ ...yield* repoInfo(caller, attempt.internalId, opened.record, infoResults),
861
+ shallow: row.roots.length > 0
862
+ } });
863
+ yield* push({
864
+ ...baseRequest,
865
+ edits: [],
866
+ roots: {
867
+ shallow,
868
+ unshallow,
869
+ sent: startRoots
870
+ },
871
+ also: () => ({
872
+ put: [importRow({
873
+ ...row,
874
+ state: "done"
875
+ }), ...receiptPut],
876
+ delete: importEndDeletes(row),
877
+ jobs: []
878
+ }),
879
+ guard: uncancelled(0, deepen.run)
880
+ }).pipe(Effect.catchIf((error) => error.code === "FAILED_PRECONDITION" && error.context?.reason === "changed-while-checked" || error.code === "RESOURCE_EXHAUSTED", forGood));
881
+ return;
882
+ }
702
883
  const page = row.publishedPages ?? 0;
703
884
  const pages = row.tipPages ?? 0;
704
885
  const last = page + 1 >= pages;
@@ -718,13 +899,8 @@ const publish = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, row) {
718
899
  }];
719
900
  });
720
901
  const request = {
721
- caller: attempt.bound.caller,
722
- repo: opened.name,
723
- internalId: attempt.internalId,
724
- source: "import",
725
- as: importOwner,
902
+ ...baseRequest,
726
903
  edits,
727
- atomic: true,
728
904
  also: (at) => {
729
905
  const cursor = importRow(last ? {
730
906
  ...next,
@@ -784,10 +960,11 @@ const stepIn = /* @__PURE__ */ Effect.fnUntraced(function* (attempt) {
784
960
  if (viewed === void 0) return void 0;
785
961
  if (viewed.kind === "refused") return yield* forGood(viewed.error);
786
962
  if (!viewed.view.whole) return yield* forGood(partialImporter());
787
- return yield* asSync(stepAs(attempt, read, row));
963
+ const { deepen } = row;
964
+ return yield* asSync(stepAs(attempt, read, row, viewed.caller)).pipe(Effect.catch((error) => deepen === void 0 ? Effect.fail(error) : Effect.flatMap(readOwn(attempt), (now) => now.row?.deepen?.run !== deepen.run ? Effect.succeed(more) : Effect.fail(error))));
788
965
  });
789
966
  /** The step the record says is next, once who started the import is asked again. */
790
- const stepAs = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, read, row) {
967
+ const stepAs = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, read, row, caller) {
791
968
  if (row.receiving !== void 0) return yield* resumed(attempt, row, row.receiving, read.cut);
792
969
  if (row.copied) {
793
970
  const { lfs } = row;
@@ -796,7 +973,7 @@ const stepAs = /* @__PURE__ */ Effect.fnUntraced(function* (attempt, read, row)
796
973
  yield* copyLfs(attempt, read.version, row, lfs, copy);
797
974
  return more;
798
975
  }
799
- return yield* publish(attempt, row);
976
+ return yield* publish(attempt, row, caller);
800
977
  }
801
978
  const remote = yield* remoteOf(attempt.bound, row.source, attempt.context.signal, "read");
802
979
  if (row.tipPages === void 0) return yield* listTips(attempt, read.version, row, remote);
@@ -844,29 +1021,34 @@ const importTry = /* @__PURE__ */ Effect.fnUntraced(function* (bound) {
844
1021
  const importFailed = /* @__PURE__ */ Effect.fnUntraced(function* (bound, { error }) {
845
1022
  const internalId = yield* currentRepo;
846
1023
  const passing = error instanceof SyncTryError && !error.permanent;
847
- const last = error instanceof SyncTryError ? error.kept : stoppedTry;
848
- const cut = {
849
- ...last,
850
- message: cutWords(last.message, failedMessageMost)
851
- };
852
- const kept = passing ? {
853
- ...cut,
854
- hint: failedHint
855
- } : cut;
856
1024
  const marked = Effect.gen(function* () {
857
1025
  const { store } = yield* CoreParts;
858
1026
  for (;;) {
859
1027
  const read = yield* readImport(store, internalId);
860
1028
  const { row } = read;
861
1029
  if (row === void 0 || row.state !== "running") return;
1030
+ const isDeepen = row.deepen !== void 0;
1031
+ const last = error instanceof SyncTryError ? error.kept : isDeepen ? stoppedDeepen : stoppedTry;
1032
+ const cut = {
1033
+ ...last,
1034
+ message: cutWords(last.message, failedMessageMost)
1035
+ };
1036
+ const kept = passing ? {
1037
+ ...cut,
1038
+ hint: isDeepen ? "Deepen again with a new key" : failedHint
1039
+ } : cut;
1040
+ const receiptPut = read.cancelled ? [] : deepenReceiptPut(row.deepen, { error: kept });
862
1041
  if ((yield* storeCommit(store.commit(repoScope(internalId), {
863
1042
  id: newChangeId(),
864
1043
  expect: read.version,
865
- put: read.cancelled ? [] : [importRow(failedRow(row, kept))],
1044
+ put: read.cancelled ? [] : [importRow(failedRow(row, kept)), ...receiptPut],
866
1045
  delete: importEndDeletes(row)
867
- }))).ok) return;
1046
+ }))).ok) return row.lfs?.copying;
868
1047
  }
869
1048
  });
870
- yield* Effect.provideContext(marked, bound.needs).pipe(Effect.mapError(thrownOf));
1049
+ const copying = yield* Effect.provideContext(marked, bound.needs).pipe(Effect.mapError(thrownOf));
1050
+ if (copying === void 0) return;
1051
+ const copy = yield* bound.lfs;
1052
+ if (copy !== void 0) yield* leftUpload(copy, copying);
871
1053
  });
872
1054
  export { advertisedFrom, importFailed, importTry };
@@ -1,12 +1,13 @@
1
1
  import { runnerIn, untilAborted } from "../store/crossing.mjs";
2
2
  import { gitError, gitErrorFrom, isGitError } from "../contracts/result.mjs";
3
3
  import { openRepo } from "../core/access.mjs";
4
- import { CoreParts } from "../core/parts.mjs";
4
+ import { notFailed } from "../core/events/deliver.mjs";
5
+ import { CoreParts, QueueParts } from "../core/parts.mjs";
5
6
  import { KeptError, keptError } from "../core/receipts.mjs";
6
7
  import { SealedObjects } from "../core/view.mjs";
7
8
  import { gitHttpOver } from "../client/git-http.mjs";
8
9
  import { hostRecordOf } from "../store/catalogue.mjs";
9
- import { answerSpent } from "../store/errors.mjs";
10
+ import { answerSpent, storeCall } from "../store/errors.mjs";
10
11
  import { decodePacks } from "../store/git-store.mjs";
11
12
  import { WholeRepo, wholeRefs } from "../store/ref-rows.mjs";
12
13
  import { collections } from "../store/scopes.mjs";
@@ -15,11 +16,12 @@ import { quoted } from "../protocol/bytes/text.mjs";
15
16
  import { responseToWeb } from "./http.mjs";
16
17
  import { callLimitIn, spentAt, spentOf, spentRefusalOf } from "../contracts/calls-spent.mjs";
17
18
  import { chargeCall } from "../store/call-count.mjs";
18
- import * as Effect from "effect/Effect";
19
- import * as HttpClient from "effect/http/HttpClient";
19
+ import { isInfraError } from "@ref0/infra";
20
20
  import * as Schema from "effect/Schema";
21
- import * as Cause from "effect/Cause";
21
+ import * as Effect from "effect/Effect";
22
22
  import * as Predicate from "effect/Predicate";
23
+ import * as Cause from "effect/Cause";
24
+ import * as HttpClient from "effect/http/HttpClient";
23
25
  import * as HttpClientRequest from "effect/http/HttpClientRequest";
24
26
  // src/sync/tries.ts
25
27
  /**
@@ -195,4 +197,21 @@ const openedFor = /* @__PURE__ */ Effect.fnUntraced(function* (caller, internalI
195
197
  refs
196
198
  };
197
199
  });
198
- export { ForGood, SyncTryError, forGood, fromRemote, httpOf, keptFieldsOf, openedFor, remoteOf, senderOf, syncObjects, syncRetry, syncTryError, syncWhole, thrownOf, tried, unknownProvider };
200
+ const tooManyRoots = (most) => gitError("RESOURCE_EXHAUSTED", `An import takes at most ${most} shallow roots`, { context: {
201
+ reason: "too-large",
202
+ limit: most
203
+ } });
204
+ /**
205
+ * Revives a failed job row that `commit`'s `save()` skipped, shared by mirror resume and deepen
206
+ * start/replay: retries a failed row, discards and re-adds when its failed data was compacted, and
207
+ * re-adds if a prior crash happened after `discard` and before `add` (`NOT_FOUND`). A waiting or
208
+ * running job is left untouched (`not-failed`).
209
+ */
210
+ const reviveFailedJob = /* @__PURE__ */ Effect.fnUntraced(function* (scope, job) {
211
+ const { store } = yield* CoreParts;
212
+ const { jobs } = yield* QueueParts;
213
+ const state = yield* storeCall(jobs.retry(scope, job)).pipe(Effect.as(0), Effect.catchIf(notFailed, (error) => Effect.succeed(error.code === "NOT_FOUND" ? 1 : 0)), Effect.catchIf((error) => isInfraError(error.cause) && error.cause.reason === "compacted", () => Effect.succeed(2)));
214
+ if (state === 2) yield* storeCall(jobs.discard(scope, job)).pipe(Effect.catchIf(notFailed, () => Effect.void));
215
+ if (state > 0) yield* storeCall(store.add(scope, { jobs: [job] }));
216
+ });
217
+ export { ForGood, SyncTryError, forGood, fromRemote, httpOf, keptFieldsOf, openedFor, remoteOf, reviveFailedJob, senderOf, syncObjects, syncRetry, syncTryError, syncWhole, thrownOf, tooManyRoots, tried, unknownProvider };
package/dist/sync.d.mts CHANGED
@@ -1,6 +1,6 @@
1
- import { GitHubAppCredentials, ImportJobData, ImportLfsMissed, ImportLfsReason, ImportPhase, ImportProgress, ImportState, ImportStatus, ImportedMove, MirrorJobData, MirrorPause, MirrorState, ReportImportProgress, Sync, SyncCancelInput, SyncGitHubOptions, SyncImportInput, SyncLayerOptions, SyncMirrorInput, SyncMirrorsInput, SyncProvider, SyncPublishInput, SyncRemote, SyncRemoveMirrorInput, SyncSource, SyncTransport, SyncTrigger, cancelImport, importRepo, importedPullRefs, mirror, mirrors, publishImported, removeMirror } from "./contracts/sync.mjs";
1
+ import { GitHubAppCredentials, ImportJobData, ImportLfsMissed, ImportLfsReason, ImportPhase, ImportProgress, ImportState, ImportStatus, ImportedMove, MirrorJobData, MirrorPause, MirrorState, ReportImportProgress, Sync, SyncCancelInput, SyncDeepenInput, SyncDeepenMode, SyncGitHubOptions, SyncImportInput, SyncLayerOptions, SyncMirrorInput, SyncMirrorsInput, SyncProvider, SyncPublishInput, SyncRemote, SyncRemoveMirrorInput, SyncSource, SyncTransport, SyncTrigger, cancelImport, deepen, importRepo, importedPullRefs, mirror, mirrors, publishImported, removeMirror } from "./contracts/sync.mjs";
2
2
  import { github, webhookBodyBytes } from "./sync/github.mjs";
3
3
  import { partialImporter } from "./sync/import.mjs";
4
4
  import { layer } from "./sync/layer.mjs";
5
5
  import { smartHttp } from "./sync/smart-http.mjs";
6
- export { type GitHubAppCredentials, type ImportJobData, type ImportLfsMissed, type ImportLfsReason, type ImportPhase, type ImportProgress, type ImportState, type ImportStatus, type ImportedMove, type MirrorJobData, type MirrorPause, type MirrorState, type ReportImportProgress, Sync, type SyncCancelInput, type SyncGitHubOptions, type SyncImportInput, type SyncLayerOptions, type SyncMirrorInput, type SyncMirrorsInput, type SyncProvider, type SyncPublishInput, type SyncRemote, type SyncRemoveMirrorInput, type SyncSource, type SyncTransport, type SyncTrigger, cancelImport, github, importRepo as import, importedPullRefs, layer, mirror, mirrors, partialImporter, publishImported, removeMirror, smartHttp, webhookBodyBytes };
6
+ export { type GitHubAppCredentials, type ImportJobData, type ImportLfsMissed, type ImportLfsReason, type ImportPhase, type ImportProgress, type ImportState, type ImportStatus, type ImportedMove, type MirrorJobData, type MirrorPause, type MirrorState, type ReportImportProgress, Sync, type SyncCancelInput, type SyncDeepenInput, type SyncDeepenMode, type SyncGitHubOptions, type SyncImportInput, type SyncLayerOptions, type SyncMirrorInput, type SyncMirrorsInput, type SyncProvider, type SyncPublishInput, type SyncRemote, type SyncRemoveMirrorInput, type SyncSource, type SyncTransport, type SyncTrigger, cancelImport, deepen, github, importRepo as import, importedPullRefs, layer, mirror, mirrors, partialImporter, publishImported, removeMirror, smartHttp, webhookBodyBytes };
package/dist/sync.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { Sync, cancelImport, importRepo, importedPullRefs, mirror, mirrors, publishImported, removeMirror } from "./contracts/sync.mjs";
1
+ import { Sync, cancelImport, deepen, importRepo, importedPullRefs, mirror, mirrors, publishImported, removeMirror } from "./contracts/sync.mjs";
2
2
  import { github, webhookBodyBytes } from "./sync/github.mjs";
3
3
  import { partialImporter } from "./sync/import.mjs";
4
4
  import { layer } from "./sync/layer.mjs";
5
5
  import { smartHttp } from "./sync/smart-http.mjs";
6
- export { Sync, cancelImport, github, importRepo as import, importedPullRefs, layer, mirror, mirrors, partialImporter, publishImported, removeMirror, smartHttp, webhookBodyBytes };
6
+ export { Sync, cancelImport, deepen, github, importRepo as import, importedPullRefs, layer, mirror, mirrors, partialImporter, publishImported, removeMirror, smartHttp, webhookBodyBytes };
@@ -15,12 +15,12 @@ import { unwaited } from "./rows.mjs";
15
15
  import { commitTopic, currentSet, durationWords, entriesOf, failureOf, readTopic, setKeyOf, topicOf } from "./topic.mjs";
16
16
  import { ObjectsParts, QueueParts } from "../core/parts.mjs";
17
17
  import { checkedAnswer, plainAnswer } from "../core/rules/context.mjs";
18
- import * as Clock from "effect/Clock";
19
- import * as Effect from "effect/Effect";
20
- import * as Result from "effect/Result";
21
18
  import { CurrentJob, Job, LostTry } from "@ref0/infra";
19
+ import * as Effect from "effect/Effect";
22
20
  import * as Predicate from "effect/Predicate";
23
21
  import * as Context from "effect/Context";
22
+ import * as Result from "effect/Result";
23
+ import * as Clock from "effect/Clock";
24
24
  // src/topics/advance.ts
25
25
  /**
26
26
  * `topics.advance`, one step at a time, each one commit in one scope, read again before the