@ref0/git 0.12.0 → 0.14.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 (247) hide show
  1. package/dist/access/private-refs.mjs +3 -3
  2. package/dist/auth/auth.d.mts +2 -2
  3. package/dist/auth/auth.mjs +3 -6
  4. package/dist/auth/authorize.mjs +1 -17
  5. package/dist/auth/helpers.mjs +3 -11
  6. package/dist/auth/host-services.mjs +11 -0
  7. package/dist/auth/policy.d.mts +27 -7
  8. package/dist/auth/policy.mjs +8 -4
  9. package/dist/auth/tokens-layer.d.mts +1 -2
  10. package/dist/auth/tokens-layer.mjs +2 -3
  11. package/dist/auth/tokens-public.d.mts +3 -3
  12. package/dist/auth/tokens.d.mts +1 -8
  13. package/dist/auth/tokens.mjs +1 -8
  14. package/dist/auth.d.mts +1 -4
  15. package/dist/auth.mjs +1 -3
  16. package/dist/client/git-http.mjs +18 -4
  17. package/dist/client/push-upload.mjs +33 -7
  18. package/dist/client/remote.mjs +94 -28
  19. package/dist/client/slice-push.d.mts +1 -1
  20. package/dist/contracts/access.d.mts +8 -8
  21. package/dist/contracts/actors.d.mts +2 -34
  22. package/dist/contracts/blobs.d.mts +2 -2
  23. package/dist/contracts/client.d.mts +8 -3
  24. package/dist/contracts/commits.d.mts +10 -2
  25. package/dist/contracts/commits.mjs +9 -1
  26. package/dist/contracts/files.d.mts +2 -2
  27. package/dist/contracts/forks.d.mts +11 -1
  28. package/dist/contracts/git.d.mts +18 -7
  29. package/dist/contracts/git.mjs +3 -2
  30. package/dist/contracts/lfs.d.mts +0 -7
  31. package/dist/contracts/objects.d.mts +80 -10
  32. package/dist/contracts/operations.d.mts +3 -0
  33. package/dist/contracts/operations.mjs +12 -2
  34. package/dist/contracts/push-uploads.d.mts +44 -5
  35. package/dist/contracts/push-uploads.mjs +7 -3
  36. package/dist/contracts/refs.d.mts +28 -6
  37. package/dist/contracts/remote.mjs +1 -3
  38. package/dist/contracts/repo-records.d.mts +1 -0
  39. package/dist/contracts/repos.d.mts +90 -2
  40. package/dist/contracts/repos.mjs +29 -2
  41. package/dist/contracts/result.d.mts +23 -18
  42. package/dist/contracts/result.mjs +17 -4
  43. package/dist/contracts/rules.d.mts +22 -22
  44. package/dist/contracts/server.d.mts +28 -77
  45. package/dist/contracts/signin.d.mts +1 -1
  46. package/dist/contracts/sync.d.mts +79 -19
  47. package/dist/contracts/sync.mjs +34 -10
  48. package/dist/contracts/tokens.d.mts +1 -6
  49. package/dist/contracts/tokens.mjs +1 -2
  50. package/dist/contracts/topics.d.mts +0 -5
  51. package/dist/contracts/work.d.mts +66 -2
  52. package/dist/contracts/work.mjs +8 -1
  53. package/dist/core/access.mjs +27 -5
  54. package/dist/core/ancestry.d.mts +9 -0
  55. package/dist/core/ancestry.mjs +6 -6
  56. package/dist/core/asked.mjs +42 -4
  57. package/dist/core/call-names.mjs +1 -0
  58. package/dist/core/call-services.mjs +2 -1
  59. package/dist/core/events/deliver.mjs +10 -2
  60. package/dist/core/forks.mjs +3 -3
  61. package/dist/core/imports.mjs +147 -9
  62. package/dist/core/index-job.mjs +9 -6
  63. package/dist/core/job-view.mjs +8 -9
  64. package/dist/core/mirror-rows.mjs +19 -4
  65. package/dist/core/objects/commits.mjs +16 -6
  66. package/dist/core/parts.d.mts +6 -1
  67. package/dist/core/parts.mjs +1 -4
  68. package/dist/core/purge.mjs +76 -6
  69. package/dist/core/push-decide.mjs +1 -1
  70. package/dist/core/push-files.d.mts +12 -0
  71. package/dist/core/push-files.mjs +225 -0
  72. package/dist/core/push-repo.d.mts +8 -0
  73. package/dist/core/push-repo.mjs +56 -0
  74. package/dist/core/push.d.mts +17 -0
  75. package/dist/core/push.mjs +98 -26
  76. package/dist/core/receipts.mjs +26 -10
  77. package/dist/core/ref-view.mjs +59 -5
  78. package/dist/core/refs.mjs +13 -8
  79. package/dist/core/repack.mjs +11 -8
  80. package/dist/core/repo-info.mjs +16 -9
  81. package/dist/core/repos.mjs +30 -14
  82. package/dist/core/seam.mjs +2 -2
  83. package/dist/core/view.d.mts +6 -0
  84. package/dist/core/view.mjs +45 -12
  85. package/dist/core/work.mjs +47 -22
  86. package/dist/effect.d.mts +3 -1
  87. package/dist/effect.mjs +3 -1
  88. package/dist/engine/reads.mjs +13 -6
  89. package/dist/engine/walk.mjs +4 -4
  90. package/dist/event-streams/event-streams.d.mts +1 -1
  91. package/dist/event-streams/event-streams.mjs +1 -1
  92. package/dist/event-streams/stream.d.mts +1 -1
  93. package/dist/event-streams/stream.mjs +1 -1
  94. package/dist/extend.d.mts +3 -3
  95. package/dist/extend.mjs +2 -2
  96. package/dist/http/answers.mjs +4 -2
  97. package/dist/http/core-parts.mjs +64 -15
  98. package/dist/http/handler.mjs +2 -2
  99. package/dist/http/node.mjs +5 -4
  100. package/dist/http/parts.d.mts +1 -0
  101. package/dist/http/push-upload-job.mjs +503 -0
  102. package/dist/http/push-uploads.d.mts +1 -0
  103. package/dist/http/push-uploads.mjs +114 -56
  104. package/dist/http/upload-pack.mjs +7 -6
  105. package/dist/index.d.mts +23 -24
  106. package/dist/index.mjs +4 -7
  107. package/dist/lfs/base.d.mts +7 -3
  108. package/dist/lfs/base.mjs +2 -1
  109. package/dist/lfs/copy.d.mts +46 -0
  110. package/dist/lfs/copy.mjs +26 -0
  111. package/dist/lfs/layer.mjs +4 -2
  112. package/dist/lfs/objects.d.mts +6 -0
  113. package/dist/lfs/objects.mjs +68 -41
  114. package/dist/lfs/rows.d.mts +13 -0
  115. package/dist/lfs/service.d.mts +1 -7
  116. package/dist/lfs/service.mjs +1 -9
  117. package/dist/lfs/upload-most.mjs +5 -5
  118. package/dist/node.d.mts +2 -2
  119. package/dist/protocol/bytes/sha256-hasher.d.mts +15 -0
  120. package/dist/protocol/bytes/sha256.d.mts +32 -0
  121. package/dist/protocol/bytes/sha256.mjs +105 -49
  122. package/dist/protocol/wire/advertisement.mjs +9 -4
  123. package/dist/protocol/wire/lines.d.mts +4 -2
  124. package/dist/protocol/wire/lines.mjs +11 -5
  125. package/dist/protocol/wire/push-uploads.mjs +13 -1
  126. package/dist/protocol/wire/v2.mjs +2 -2
  127. package/dist/protocol.d.mts +3 -1
  128. package/dist/protocol.mjs +3 -1
  129. package/dist/queue/advance.mjs +1 -1
  130. package/dist/queue/host.d.mts +1 -7
  131. package/dist/queue/host.mjs +1 -7
  132. package/dist/queue/layer.mjs +1 -1
  133. package/dist/queue/trim.mjs +1 -1
  134. package/dist/rest/blobs.d.mts +31 -23
  135. package/dist/rest/blobs.mjs +1 -1
  136. package/dist/rest/caller.d.mts +49 -9
  137. package/dist/rest/caller.mjs +1 -1
  138. package/dist/rest/client.d.mts +10 -3
  139. package/dist/rest/client.mjs +4 -0
  140. package/dist/rest/commits.d.mts +273 -240
  141. package/dist/rest/errors.d.mts +24 -4
  142. package/dist/rest/events.d.mts +9 -6
  143. package/dist/rest/events.mjs +1 -2
  144. package/dist/rest/files.d.mts +127 -115
  145. package/dist/rest/forks.d.mts +121 -97
  146. package/dist/rest/handler.mjs +4 -57
  147. package/dist/rest/handlers.d.mts +1 -1
  148. package/dist/rest/handlers.mjs +18 -4
  149. package/dist/rest/layer.mjs +2 -1
  150. package/dist/rest/me.d.mts +8 -4
  151. package/dist/rest/merges.d.mts +8 -4
  152. package/dist/rest/paths.mjs +1 -0
  153. package/dist/rest/queue.d.mts +282 -226
  154. package/dist/rest/refs.d.mts +205 -176
  155. package/dist/rest/repos.d.mts +108 -80
  156. package/dist/rest/tags.d.mts +24 -12
  157. package/dist/rest/tokens.d.mts +235 -211
  158. package/dist/rest/topics.d.mts +53 -33
  159. package/dist/rest/trees.d.mts +105 -89
  160. package/dist/rest/work.d.mts +467 -20
  161. package/dist/rest/work.mjs +8 -0
  162. package/dist/server/edge-node.d.mts +9 -13
  163. package/dist/server/edge-node.mjs +9 -12
  164. package/dist/server/git-layer.d.mts +1 -6
  165. package/dist/server/git-layer.mjs +2 -2
  166. package/dist/server/git-namespace.d.mts +3 -3
  167. package/dist/server/joined.d.mts +15 -22
  168. package/dist/server/joined.mjs +5 -29
  169. package/dist/server/lifecycle.mjs +107 -23
  170. package/dist/server/registry.mjs +9 -1
  171. package/dist/server/server.mjs +133 -212
  172. package/dist/storage/budget.mjs +2 -2
  173. package/dist/storage/clean-up.mjs +13 -10
  174. package/dist/storage/fetch.mjs +13 -8
  175. package/dist/storage/file-limits.mjs +24 -0
  176. package/dist/storage/index-build.d.mts +1 -0
  177. package/dist/storage/index-build.mjs +106 -62
  178. package/dist/storage/index-fetch.mjs +16 -3
  179. package/dist/storage/index-reach.mjs +33 -5
  180. package/dist/storage/index-remap.mjs +8 -1
  181. package/dist/storage/index-shallow.mjs +5 -3
  182. package/dist/storage/largest-files.mjs +48 -0
  183. package/dist/storage/lfs-pointers.mjs +10 -1
  184. package/dist/storage/loose.mjs +3 -1
  185. package/dist/storage/memory-budget.mjs +28 -4
  186. package/dist/storage/pack-reads.mjs +8 -8
  187. package/dist/storage/pack-receive.mjs +83 -25
  188. package/dist/storage/packs.mjs +37 -21
  189. package/dist/storage/prune-keep.mjs +203 -34
  190. package/dist/storage/prune-walk.mjs +54 -16
  191. package/dist/storage/prune.mjs +629 -196
  192. package/dist/storage/push-uploads.mjs +36 -12
  193. package/dist/storage/quarantine.mjs +9 -9
  194. package/dist/storage/ready.mjs +47 -19
  195. package/dist/storage/receive-bounds.mjs +29 -8
  196. package/dist/storage/receive-state.mjs +8 -0
  197. package/dist/storage/receive-steps.mjs +71 -18
  198. package/dist/storage/repack.d.mts +1 -1
  199. package/dist/storage/repack.mjs +1 -8
  200. package/dist/storage/rows.mjs +12 -1
  201. package/dist/storage/shallow.d.mts +1 -0
  202. package/dist/storage/shallow.mjs +26 -4
  203. package/dist/storage/stream-whole.mjs +5 -2
  204. package/dist/storage/visible.mjs +29 -1
  205. package/dist/storage/walk.mjs +2 -1
  206. package/dist/store/catalogue.mjs +1 -0
  207. package/dist/store/cursor-seal-namespace.d.mts +2 -0
  208. package/dist/store/cursor-seal-public.d.mts +5 -0
  209. package/dist/store/cursor-seal-public.mjs +5 -0
  210. package/dist/store/cursor-seal.d.mts +16 -2
  211. package/dist/store/cursor-seal.mjs +26 -14
  212. package/dist/store/errors.mjs +9 -1
  213. package/dist/store/records.d.mts +2 -0
  214. package/dist/store/records.mjs +9 -6
  215. package/dist/store/repo-record.d.mts +9 -7
  216. package/dist/store/repo-record.mjs +102 -19
  217. package/dist/store/scopes.mjs +10 -2
  218. package/dist/sync/bound.d.mts +2 -0
  219. package/dist/sync/bound.mjs +11 -2
  220. package/dist/sync/github.d.mts +6 -1
  221. package/dist/sync/github.mjs +55 -43
  222. package/dist/sync/http.mjs +36 -1
  223. package/dist/sync/import.mjs +1 -0
  224. package/dist/sync/layer.mjs +6 -2
  225. package/dist/sync/lfs-batch.mjs +119 -0
  226. package/dist/sync/lfs-copy.mjs +251 -0
  227. package/dist/sync/mirror.mjs +210 -137
  228. package/dist/sync/smart-http.mjs +4 -2
  229. package/dist/sync/step.mjs +25 -5
  230. package/dist/sync/tries.mjs +45 -14
  231. package/dist/sync.d.mts +2 -2
  232. package/dist/topics/host.mjs +1 -19
  233. package/dist/topics/layer.mjs +1 -1
  234. package/package.json +3 -8
  235. package/dist/auth/bridge.mjs +0 -30
  236. package/dist/auth/helpers.d.mts +0 -17
  237. package/dist/core/purge.d.mts +0 -8
  238. package/dist/core/registered-rows.d.mts +0 -5
  239. package/dist/core/repack.d.mts +0 -11
  240. package/dist/http/handler.d.mts +0 -2
  241. package/dist/rest/handler.d.mts +0 -21
  242. package/dist/rest.d.mts +0 -2
  243. package/dist/rest.mjs +0 -1
  244. package/dist/server/registry.d.mts +0 -16
  245. package/dist/server/server.d.mts +0 -36
  246. package/dist/storage/repack-job.d.mts +0 -3
  247. package/dist/topics/host.d.mts +0 -7
@@ -58,10 +58,11 @@ const endLeaving = /* @__PURE__ */ Effect.fnUntraced(function* (bucket, listed,
58
58
  const sooner = (one, other) => one === void 0 ? other : Math.min(one, other);
59
59
  /**
60
60
  * `collection`'s rows from its first, a page at a time, each as `decode` reads it, until `enough`
61
- * holds of the rows with work, which `isWork` picks, or none is left. Each step starts again from
62
- * the first row, so no cursor is kept: rows a step ends are gone from the next one's pages.
61
+ * holds of the rows with work, which `isWork` picks, or none is left. A row with none yet is due at
62
+ * `dueAt`. Each step starts again from the first row, so no cursor is kept: rows a step ends are
63
+ * gone from the next one's pages.
63
64
  */
64
- const scan = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, collection, decode, isWork, enough) {
65
+ const scan = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, collection, decode, isWork, enough, dueAt = (row) => row.value.removeAt) {
65
66
  const work = [];
66
67
  let later;
67
68
  let held = false;
@@ -80,7 +81,7 @@ const scan = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, collecti
80
81
  for (const row of rows) {
81
82
  const one = yield* decode(row);
82
83
  if (isWork(one)) work.push(one);
83
- else later = sooner(later, one.value.removeAt);
84
+ else later = sooner(later, dueAt(one));
84
85
  }
85
86
  const last = rows.at(-1);
86
87
  if (rows.length < 1e4 || last === void 0) return {
@@ -117,7 +118,8 @@ const leavingOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, cov
117
118
  });
118
119
  /**
119
120
  * `git.repack`'s clean-up of a repo's `quarantine`, `leaving`, `cover` and `staged` rows whose
120
- * `removeAt` has passed, as one step whose change the core commits:
121
+ * `removeAt` has passed, or for a deleted repo's open `quarantine` and `leaving` rows, its `leaveAt`
122
+ * (#2476), as one step whose change the core commits:
121
123
  * - an open `quarantine` row is committed abandoned first, so its writer's listing is refused;
122
124
  * - an abandoned one has its marker and bytes deleted, then its row, a `staged` row put for it;
123
125
  * - a `leaving` row is committed taken first, so a sync's or a fetch's listing is refused (#394),
@@ -135,16 +137,17 @@ const leavingOf = /* @__PURE__ */ Effect.fnUntraced(function* (store, scope, cov
135
137
  * `undefined` when the repo holds no row of the four kinds.
136
138
  */
137
139
  const cleanUp = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
138
- const { store, bucket, listed, at } = input;
140
+ const { store, bucket, listed, at, leaveAt } = input;
139
141
  const scope = repoScope(listed.repo);
140
142
  const isDue = (row) => row.value.removeAt <= at;
143
+ const dueBy = (row) => leaveAt === void 0 ? row.value.removeAt : Math.min(row.value.removeAt, leaveAt);
141
144
  const isAbandoned = (row) => row.value.state === "abandoned";
142
145
  const isTaken = (row) => row.value.taken === true;
143
146
  const pastBatch = (rows) => rows.length > 25;
144
- const scanLeft = (collection) => scan(store, scope, collection, decodeLeft, (row) => isTaken(row) || isDue(row), (work) => pastBatch(work.filter(isTaken)) || pastBatch(work.filter((row) => !isTaken(row))));
145
- const quarantined = yield* scan(store, scope, objectCollections.quarantine, (row) => decodeHeld(QuarantineRow, row), (row) => isAbandoned(row) || isDue(row), (work) => pastBatch(work.filter(isAbandoned)) || pastBatch(work.filter((row) => !isAbandoned(row))));
146
- const leaving = yield* scanLeft(objectCollections.leaving);
147
- const covers = yield* scanLeft(objectCollections.cover);
147
+ const scanLeft = (collection, dueAt) => scan(store, scope, collection, decodeLeft, (row) => isTaken(row) || dueAt(row) <= at, (work) => pastBatch(work.filter(isTaken)) || pastBatch(work.filter((row) => !isTaken(row))), dueAt);
148
+ const quarantined = yield* scan(store, scope, objectCollections.quarantine, (row) => decodeHeld(QuarantineRow, row), (row) => isAbandoned(row) || dueBy(row) <= at, (work) => pastBatch(work.filter(isAbandoned)) || pastBatch(work.filter((row) => !isAbandoned(row))), dueBy);
149
+ const leaving = yield* scanLeft(objectCollections.leaving, dueBy);
150
+ const covers = yield* scanLeft(objectCollections.cover, (row) => row.value.removeAt);
148
151
  const staged = yield* scan(store, scope, objectCollections.staged, (row) => decodeHeld(StagedRow, row), isDue, pastBatch);
149
152
  const lefts = [leaving, covers];
150
153
  if (!quarantined.held && !lefts.some((found) => found.held) && !staged.held) return void 0;
@@ -14,13 +14,13 @@ import { isSet } from "./bits.mjs";
14
14
  import { typeOfCode } from "./index-files.mjs";
15
15
  import { ListCursor, sizeOf } from "./send-list.mjs";
16
16
  import { indexSendSet } from "./index-fetch.mjs";
17
- import { planShallow } from "./shallow.mjs";
17
+ import { planShallow, withRootsSent } from "./shallow.mjs";
18
18
  import { countedReads, fetchReadsOf, historyOf, lost, notHeld, unreadable, walk } from "./walk.mjs";
19
19
  import * as Clock$1 from "effect/Clock";
20
20
  import * as Effect from "effect/Effect";
21
21
  // src/storage/fetch.ts
22
22
  /**
23
- * `createGitServer`'s `fetchLimits` when it names none: a clone of a large repo fits within them.
23
+ * `Git.layer`'s `fetchLimits` when it names none: a clone of a large repo fits within them.
24
24
  * Its hour is also how long a deleted repo's packs stay readable, in `leaving` rows.
25
25
  */
26
26
  const defaultFetchLimits = {
@@ -52,7 +52,7 @@ const pastLimits = (limits, fetchLimits) => {
52
52
  if (past === void 0) return void 0;
53
53
  return gitError("INVALID_ARGUMENT", `This fetch's limits ask for ${limits[past]} ${past}, past the server's limit of ${fetchLimits[past]}`, {
54
54
  hint: `Limit the fetch to ${fetchLimits[past]} ${past}`,
55
- hostHint: "Raise createGitServer's fetchLimits"
55
+ hostHint: "Raise Git.layer's fetchLimits"
56
56
  });
57
57
  };
58
58
  /** What the pack writer holds at once: its buffers, its compressor, one object's body. */
@@ -632,13 +632,14 @@ const followedTags = /* @__PURE__ */ Effect.fnUntraced(function* (read, tags, sk
632
632
  * Each object is read and sent once.
633
633
  */
634
634
  const planFetch = /* @__PURE__ */ Effect.fnUntraced(function* (read, request, tags, objectsMost) {
635
- const deepened = yield* planShallow(read, request);
636
- const { clientShallows, cut } = deepened;
635
+ const planned = yield* planShallow(read, request);
636
+ const { clientShallows, cut } = planned;
637
637
  const ends = /* @__PURE__ */ new Set([...clientShallows, ...cut]);
638
638
  const haves = yield* walk(read, request.haves, (object) => ends.has(object.oid) ? [] : historyOf(object), /* @__PURE__ */ new Set(), () => void 0);
639
- const had = /* @__PURE__ */ new Set([...haves.keys(), ...deepened.unshallow]);
639
+ const had = /* @__PURE__ */ new Set([...haves.keys(), ...planned.unshallow]);
640
640
  const wanted = new Set(request.wants);
641
- const history = yield* walk(read, [...request.wants, ...deepened.starts], (object) => cut.has(object.oid) ? [] : historyOf(object), had, (oid) => wanted.has(oid) ? notHeld(oid) : lost(oid));
641
+ const history = yield* walk(read, [...request.wants, ...planned.starts], (object) => cut.has(object.oid) ? [] : historyOf(object), had, (oid) => wanted.has(oid) ? notHeld(oid) : lost(oid));
642
+ const deepened = read.roots.size === 0 ? planned : withRootsSent(planned, [...read.roots].filter((oid) => history.get(oid)?.type === "commit"));
642
643
  const edges = /* @__PURE__ */ new Set();
643
644
  for (const object of history.values()) {
644
645
  if (object.type !== "commit" || cut.has(object.oid)) continue;
@@ -980,7 +981,11 @@ const planFetchWithin = /* @__PURE__ */ Effect.fnUntraced(function* (reads, inpu
980
981
  const { deepened, objects, copies, rows, list, unplaced } = yield* Effect.gen(function* () {
981
982
  const clone = request.haves.length === 0;
982
983
  const checked = callsChecked(within.calls, clone);
983
- const read = countedReads(reads, within.readsMost ?? fetchReadsOf(limits), within.charge, checked, within.release);
984
+ const roots = input.roots;
985
+ const read = countedReads(roots === void 0 || roots.length === 0 ? reads : {
986
+ ...reads,
987
+ roots: new Set(roots)
988
+ }, within.readsMost ?? fetchReadsOf(limits), within.charge, checked, within.release);
984
989
  const planned = yield* objectsPlanned(read, request, input.tags ?? [], limits.objects, {
985
990
  ...within,
986
991
  clone,
@@ -0,0 +1,24 @@
1
+ import { pushUploadMost } from "./push-uploads.mjs";
2
+ // src/storage/file-limits.ts
3
+ /**
4
+ * A pushed file's sizes, set from GitHub's (#2395), read 2026-11-30 at
5
+ * https://docs.github.com/en/repositories/working-with-files/managing-large-files/about-large-files-on-github:
6
+ * "If you attempt to add or update a file that is larger than 50 MiB, you will receive a warning
7
+ * from Git." and "GitHub blocks files larger than 100 MiB." GitLab sets no default. The wiki's
8
+ * `operations.md` quotes these, and changes with them.
9
+ */
10
+ /** Past it, a push's file is told on band 2 to go to Git LFS: `pushes.files.warnAbove`'s default. */
11
+ const fileWarnBytes = 52428800;
12
+ /**
13
+ * Past it, a push carrying the file is refused, naming its path and size: `pushes.files.refuseAbove`'s
14
+ * default. A staged import's steps, which keep no list of their largest files, refuse a file past it
15
+ * as they read it.
16
+ */
17
+ const fileRefuseBytes = 104857600;
18
+ /**
19
+ * The largest file a push's pack is read with, hashed as it streams and never held, and the largest
20
+ * a stored pack's entry may say it is: the pack's own bound, `pushUploadMost`, so a file past the
21
+ * refusal is named before it's refused, and `refuseAbove` may go up to it.
22
+ */
23
+ const fileBytesMost = pushUploadMost;
24
+ export { fileBytesMost, fileRefuseBytes, fileWarnBytes };
@@ -4,6 +4,7 @@ import "../contracts/ids.mjs";
4
4
  import "../contracts/objects.mjs";
5
5
  import "../contracts/services.mjs";
6
6
  import "../contracts/store.mjs";
7
+ import "../protocol/objects/commit.mjs";
7
8
  import "../store/call-count.mjs";
8
9
  import "./fetch.mjs";
9
10
  import "./index-graph.mjs";
@@ -5,9 +5,9 @@ import { Sha1 } from "../protocol/bytes/sha1.mjs";
5
5
  import { writeCommitGraph } from "../protocol/packs/graph.mjs";
6
6
  import { IndexerCache } from "../protocol/packs/indexer.mjs";
7
7
  import { oidBytes } from "../protocol/packs/idx.mjs";
8
+ import { noRepoRoots } from "../protocol/objects/commit.mjs";
8
9
  import { rawLinks } from "../protocol/objects/links-raw.mjs";
9
- import { rootsOf } from "../store/repo-record.mjs";
10
- import { repoRootsKey, repoScope } from "../store/scopes.mjs";
10
+ import { rootsDigest } from "../store/repo-record.mjs";
11
11
  import { randomText } from "../store/random.mjs";
12
12
  import { allottableOf, uploadPartBytes } from "./budget.mjs";
13
13
  import { bucketDo, bucketPut, joined, readWhole, sizedPutCalls, streamedPutCalls } from "./calls.mjs";
@@ -89,7 +89,9 @@ const IndexLayer = /* @__PURE__ */ Schema.Struct({
89
89
  commits: Count,
90
90
  deltas: Count,
91
91
  bitmaps: Count,
92
- table: Count
92
+ table: Count,
93
+ /** The positions of the repo's roots among its own, sorted: none in a repo with none. */
94
+ roots: Schema.optionalKey(Schema.Array(Count))
93
95
  });
94
96
  /**
95
97
  * A build under way: its ID, the packs it covers in position order, its region's rows and their
@@ -122,7 +124,11 @@ const IndexData = /* @__PURE__ */ Schema.Struct({
122
124
  */
123
125
  dense: Schema.optionalKey(Schema.Literal(false)),
124
126
  /** A whole build's bitmaps written so far, a part a try: none before its first part. */
125
- bitmapsCut: Schema.optionalKey(Schema.suspend(() => BitmapsCut))
127
+ bitmapsCut: Schema.optionalKey(Schema.suspend(() => BitmapsCut)),
128
+ /** The digest of the roots the build is over, `rootsKeyOf`'s: none in a repo with none. */
129
+ roots: Schema.optionalKey(Schema.String),
130
+ /** The positions of the roots its region and slices have met so far, sorted: none, none yet. */
131
+ rootPositions: Schema.optionalKey(Schema.Array(Count))
126
132
  });
127
133
  /**
128
134
  * A whole build's bitmaps under way (#1068): the key of the order they're made in, how many of
@@ -179,13 +185,20 @@ const IndexRefusal = /* @__PURE__ */ Schema.Struct({
179
185
  * a row whose files a read found failing their own checks (`lostIndexRow`): no read answers from
180
186
  * it, and the next try builds whole, its row unmarked (Q839 (5)). A refusal over its layers keeps
181
187
  * the mark, and so does every other row that keeps them: only a whole build's row drops it.
188
+ * Each layer keeps where the repo's roots sit among its positions, so a fetch tells which it
189
+ * sends by its bits, with no lookup by ID.
182
190
  */
183
191
  const BuiltIndex = /* @__PURE__ */ Schema.Struct({
184
192
  rounds: Count,
185
193
  layers: Schema.Array(IndexLayer),
186
194
  replaced: Schema.Array(ReplacedBuild),
187
195
  refusal: Schema.optionalKey(IndexRefusal),
188
- lost: Schema.optionalKey(Schema.Literal(true))
196
+ lost: Schema.optionalKey(Schema.Literal(true)),
197
+ /**
198
+ * The digest of the roots every layer was built over, `rootsKeyOf`'s: none in a repo with none.
199
+ * An index over other roots than a read's is stale, so the read walks instead.
200
+ */
201
+ roots: Schema.optionalKey(Schema.String)
189
202
  });
190
203
  /** How long a repo waits after its first refusal for spent tries before a push saves more. */
191
204
  const triesWait = 864e5;
@@ -263,6 +276,18 @@ const lostIndexRow = (row) => {
263
276
  }
264
277
  };
265
278
  };
279
+ /**
280
+ * The digest an index keeps of the roots it's over: `rootsDigest`'s, the one the ready pack keeps
281
+ * too, and none for a repo with none, as most are.
282
+ */
283
+ const rootsKeyOf = (roots) => {
284
+ const ids = [...roots];
285
+ return ids.length === 0 ? void 0 : rootsDigest(ids);
286
+ };
287
+ /** Whether `built` is over `roots`, which a read was given: else it's stale for that read. */
288
+ const builtOver = (built, roots = noRepoRoots) => built.roots === rootsKeyOf(roots);
289
+ /** `positions` and `more`, sorted, each once. */
290
+ const withPositions = (positions, more) => [.../* @__PURE__ */ new Set([...positions ?? [], ...more])].sort((a, b) => a - b);
266
291
  /** A prune's end, with when the next file it kept is due. */
267
292
  const prunedAt = (due) => due === void 0 ? { kind: "pruned" } : {
268
293
  kind: "pruned",
@@ -350,7 +375,7 @@ const startedUpdate = (listed, built) => {
350
375
  ...started({
351
376
  ...listed,
352
377
  packs: listed.packs.filter((pack) => !covered.has(pack.id))
353
- }),
378
+ }, built.roots),
354
379
  below: built.layers
355
380
  };
356
381
  };
@@ -362,28 +387,32 @@ const startedMerge = (listed, built) => ({
362
387
  ...started({
363
388
  ...listed,
364
389
  packs: []
365
- }),
390
+ }, built.roots),
366
391
  below: built.layers,
367
392
  merge: true,
368
393
  step: "merge"
369
394
  });
370
- /** A fresh build of `listed`. */
371
- const started = (listed) => ({
372
- below: [],
373
- merge: false,
374
- build: newBuildId(),
375
- packs: positionOrder(listed.packs).map(({ id }) => id),
376
- rows: 0,
377
- region: "",
378
- step: "region",
379
- pack: 0,
380
- offset: 12,
381
- position: 0,
382
- slices: [],
383
- commits: 0,
384
- bitmaps: 0,
385
- table: 0
386
- });
395
+ /** A fresh build of `listed`, over the roots `roots`, `rootsKeyOf`'s digest. */
396
+ const started = (listed, roots) => {
397
+ const data = {
398
+ below: [],
399
+ merge: false,
400
+ build: newBuildId(),
401
+ packs: positionOrder(listed.packs).map(({ id }) => id),
402
+ rows: 0,
403
+ region: "",
404
+ step: "region",
405
+ pack: 0,
406
+ offset: 12,
407
+ position: 0,
408
+ slices: [],
409
+ commits: 0,
410
+ bitmaps: 0,
411
+ table: 0
412
+ };
413
+ if (roots !== void 0) data.roots = roots;
414
+ return data;
415
+ };
387
416
  /** The positions the layers below `data` hold, where its own start. */
388
417
  const firstOf = (below) => {
389
418
  const last = below[below.length - 1];
@@ -640,7 +669,7 @@ const regionStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, d
640
669
  const files = indexFiles(listed.repo, data.build);
641
670
  const { layout, first, packed } = yield* layoutOf(bucket, listed, data);
642
671
  const held = data.below.length === 0 ? void 0 : yield* heldBelow(parts, listed, layout, first);
643
- const roots = yield* rootsAt(parts, listed);
672
+ const roots = rootsIn(parts);
644
673
  const links = new SliceLinks((bytes) => allotment.tryGrow(bytes));
645
674
  const types = [];
646
675
  const commits = [];
@@ -676,6 +705,7 @@ const regionStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, d
676
705
  region: read.digest,
677
706
  step: "graph"
678
707
  };
708
+ if (rootPositions.size > 0) done.rootPositions = withPositions(data.rootPositions, rootPositions);
679
709
  if (read.rows === 0) return done;
680
710
  const region = withRows(layout.region, packed, read.ids);
681
711
  const targets = yield* joinCharged(links, layout.ranges, region, allotment);
@@ -707,15 +737,8 @@ const heldBelow = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, la
707
737
  for (let at = 0; at < read.rows; at += 1) if ((positions[at] ?? 4294967295) < first) held.add(hexOf(read.ids.subarray(at * 20, at * 20 + 20)));
708
738
  return held;
709
739
  });
710
- /**
711
- * The repo's roots, which a build writes with no parents in its graph and no parent edges, so
712
- * neither its bitmaps nor its generations pass one. Read on their own: an index try's own reads
713
- * are of its objects, and roots change only at the import's landing, before any ref names them.
714
- */
715
- const rootsAt = (parts, listed) => Effect.flatMap(parts.store.read({
716
- scope: repoScope(listed.repo),
717
- reads: [repoRootsKey]
718
- }), (snapshot) => rootsOf(snapshot.results[0]));
740
+ /** The repo's roots the try was given, read with its row: none when it was given none. */
741
+ const rootsIn = (parts) => parts.roots ?? noRepoRoots;
719
742
  /**
720
743
  * What the region holds of each row past its links: its ID, twice while the IDs grow, its type,
721
744
  * and a commit's entry and its ID as text, rounded up.
@@ -736,7 +759,7 @@ const graphStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, da
736
759
  key: files.graph,
737
760
  allotment,
738
761
  most: parts.graphMost,
739
- roots: yield* rootsAt(parts, listed)
762
+ roots: rootsIn(parts)
740
763
  };
741
764
  if (below !== void 0) graphInput.below = below;
742
765
  const written = (yield* storedSize(parts.bucket, files.graph)) === void 0 ? yield* writeIndexGraph(graphInput) : {
@@ -785,7 +808,7 @@ const storedTypesOf = (bucket, files, slices, base) => Effect.fnUntraced(functio
785
808
  */
786
809
  const readStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, data, allotment) {
787
810
  const { counted } = parts;
788
- const roots = yield* rootsAt(parts, listed);
811
+ const roots = rootsIn(parts);
789
812
  const counts = data.packs.map((id) => listed.packs.find((each) => each.id === id)?.objects ?? 0);
790
813
  const bounds = parts.bounds ?? sliceBounds;
791
814
  const entries = data.narrowed?.entries ?? bounds.entries ?? 65536;
@@ -870,7 +893,11 @@ const readStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, dat
870
893
  ...edges.slice,
871
894
  deltas: slice.bases.length / 2
872
895
  }];
873
- const { narrowed: _narrowed, ...past } = data;
896
+ const { narrowed: _narrowed, ...kept } = data;
897
+ const past = slice.roots.size === 0 ? kept : {
898
+ ...kept,
899
+ rootPositions: withPositions(data.rootPositions, slice.roots)
900
+ };
874
901
  if (slice.next !== void 0) {
875
902
  const after = narrowedAfter(data.narrowed, at.position, { next: slice.next.position });
876
903
  const moved = {
@@ -1214,7 +1241,6 @@ const bitmapsWritten = /* @__PURE__ */ Effect.fnUntraced(function* (parts, lower
1214
1241
  allotment,
1215
1242
  bits: walking
1216
1243
  };
1217
- const rootsOnce = yield* Effect.cached(rootsAt(parts, listed));
1218
1244
  const below = data.below.length === 0 ? void 0 : {
1219
1245
  first,
1220
1246
  entries: entriesBelow,
@@ -1231,7 +1257,7 @@ const bitmapsWritten = /* @__PURE__ */ Effect.fnUntraced(function* (parts, lower
1231
1257
  if (walks.carried?.position === position) carry.from = walks.carried.walk;
1232
1258
  const walked = yield* reachOf({
1233
1259
  ...reach,
1234
- roots: yield* rootsOnce
1260
+ roots: rootsIn(parts)
1235
1261
  }, [{ position }], carry);
1236
1262
  if (walked === void 0) return void 0;
1237
1263
  const most = ewahMostWords(walked.length) * 4;
@@ -1728,9 +1754,19 @@ const roundsAfter = (input) => (input.round ?? 0) + 1;
1728
1754
  * the repo's version during its read, and finds at its commit that it was.
1729
1755
  */
1730
1756
  const addsNothing = (data) => data.merge !== true && data.below.length > 0 && data.packs.length === 0 && data.rows === 0 && data.commits === 0 && data.bitmaps === 0;
1757
+ /** `layer` with the roots at `positions`, sorted: none kept where there are none. */
1758
+ const withRoots = (layer, positions) => positions.length === 0 ? layer : {
1759
+ ...layer,
1760
+ roots: positions
1761
+ };
1762
+ /** `row` over the roots `roots`, `rootsKeyOf`'s digest: none kept where the repo has none. */
1763
+ const rootedRow = (row, roots) => roots === void 0 ? row : {
1764
+ ...row,
1765
+ roots
1766
+ };
1731
1767
  /**
1732
1768
  * The commit step: the row, its layers those below the build and the build's own, over the packs
1733
- * it began with and its region.
1769
+ * it began with and its region, and over the roots it began with, each layer's at its positions.
1734
1770
  */
1735
1771
  const commitStep = (listed, data, input) => Effect.sync(() => {
1736
1772
  if (data.merge) {
@@ -1746,13 +1782,16 @@ const commitStep = (listed, data, input) => Effect.sync(() => {
1746
1782
  bitmaps: data.bitmaps,
1747
1783
  table: data.table
1748
1784
  };
1785
+ const roots = withPositions([], data.below.flatMap((layer) => layer.roots ?? []));
1786
+ const layer = withRoots(merged, roots);
1787
+ const row = {
1788
+ rounds: roundsAfter(input),
1789
+ layers: [layer],
1790
+ replaced: replacedBy(input, [layer])
1791
+ };
1749
1792
  return {
1750
1793
  kind: "done",
1751
- row: {
1752
- rounds: roundsAfter(input),
1753
- layers: [merged],
1754
- replaced: replacedBy(input, [merged])
1755
- },
1794
+ row: rootedRow(row, data.roots),
1756
1795
  data
1757
1796
  };
1758
1797
  }
@@ -1771,14 +1810,15 @@ const commitStep = (listed, data, input) => Effect.sync(() => {
1771
1810
  bitmaps: data.bitmaps,
1772
1811
  table: data.table
1773
1812
  };
1774
- const layers = [...data.below, layer];
1813
+ const layers = [...data.below, withRoots(layer, data.rootPositions ?? [])];
1814
+ const row = {
1815
+ rounds: roundsAfter(input),
1816
+ layers,
1817
+ replaced: replacedBy(input, layers)
1818
+ };
1775
1819
  return {
1776
1820
  kind: "done",
1777
- row: {
1778
- rounds: roundsAfter(input),
1779
- layers,
1780
- replaced: replacedBy(input, layers)
1781
- },
1821
+ row: rootedRow(row, data.roots),
1782
1822
  data
1783
1823
  };
1784
1824
  });
@@ -1924,7 +1964,7 @@ const indexStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
1924
1964
  const kept = builtOf(row);
1925
1965
  if (kept !== void 0) return {
1926
1966
  kind: "done",
1927
- row: {
1967
+ row: rootedRow({
1928
1968
  rounds,
1929
1969
  layers: kept.layers,
1930
1970
  replaced: replacedBy(input, kept.layers),
@@ -1933,7 +1973,7 @@ const indexStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
1933
1973
  ...held
1934
1974
  },
1935
1975
  ...kept.lost === true && { lost: true }
1936
- }
1976
+ }, kept.roots)
1937
1977
  };
1938
1978
  return {
1939
1979
  kind: "done",
@@ -1967,21 +2007,23 @@ const indexStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
1967
2007
  });
1968
2008
  };
1969
2009
  if (input.failed !== void 0) return waiting(input.failed.reason);
1970
- if (input.data === void 0 && row !== void 0 && !indexSaves(indexStatus(row, limits, input.at, listedIds(listed)))) return prunedAt(yield* prune());
2010
+ const rootsKey = rootsKeyOf(rootsIn(parts));
1971
2011
  const built = builtOf(row);
1972
- const current = input.data === void 0 && built?.lost === true ? "lost" : input.data === void 0 && built !== void 0 && coversAll(built.layers, listed) ? yield* upToDate(parts, listed, built, input.tips).pipe(Effect.catchIf(isLost, (error) => Effect.as(layersLost(listed, error), "lost"))) : false;
2012
+ const stale = built !== void 0 && !builtOver(built, rootsIn(parts));
2013
+ if (input.data === void 0 && row !== void 0 && !stale && !indexSaves(indexStatus(row, limits, input.at, listedIds(listed)))) return prunedAt(yield* prune());
2014
+ const current = input.data === void 0 && built?.lost === true ? "lost" : input.data === void 0 && built !== void 0 && !stale && coversAll(built.layers, listed) ? yield* upToDate(parts, listed, built, input.tips).pipe(Effect.catchIf(isLost, (error) => Effect.as(layersLost(listed, error), "lost"))) : false;
1973
2015
  if (current === true) return prunedAt(yield* prune());
1974
2016
  if (current === "moved" && input.lastCheck !== true) return { kind: "moved" };
1975
- const fresh = () => built === void 0 || current === "lost" || !coversAll(built.layers, listed) ? started(listed) : built.layers.length < 8 ? startedUpdate(listed, built) : startedMerge(listed, built);
2017
+ const fresh = () => built === void 0 || stale || current === "lost" || !coversAll(built.layers, listed) ? started(listed, rootsKey) : built.layers.length < 8 ? startedUpdate(listed, built) : startedMerge(listed, built);
1976
2018
  const kept = input.data;
1977
2019
  const sameBelow = kept !== void 0 && (kept.below.length === 0 || kept.below.map((layer) => layer.build).join() === (built?.layers ?? []).map((layer) => layer.build).join());
1978
- const again = (from) => from.below.length === 0 && from.merge !== true ? started(listed) : fresh();
1979
- const data = kept !== void 0 && built?.lost === true && kept.below.length > 0 ? started(listed) : kept === void 0 || !covers(kept, listed) || !sameBelow ? fresh() : kept.step === "region" ? again(kept) : kept;
2020
+ const again = (from) => from.below.length === 0 && from.merge !== true ? started(listed, rootsKey) : fresh();
2021
+ const data = kept !== void 0 && built?.lost === true && kept.below.length > 0 ? started(listed, rootsKey) : kept === void 0 || kept.roots !== rootsKey || !covers(kept, listed) || !sameBelow ? fresh() : kept.step === "region" ? again(kept) : kept;
1980
2022
  const more = (next) => ({
1981
2023
  kind: "more",
1982
2024
  data: next
1983
2025
  });
1984
- const orWhole = (step) => data.below.length === 0 ? step : step.pipe(Effect.catchIf(isLost, (error) => Effect.as(layersLost(listed, error), started(listed))));
2026
+ const orWhole = (step) => data.below.length === 0 ? step : step.pipe(Effect.catchIf(isLost, (error) => Effect.as(layersLost(listed, error), started(listed, rootsKey))));
1985
2027
  if (input.lastCheck === true && input.data === void 0) return more(data);
1986
2028
  if (data.step === "region") yield* prune(data.build);
1987
2029
  if (data.step === "commit" && addsNothing(data)) {
@@ -2022,7 +2064,7 @@ const indexStep = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
2022
2064
  return yield* Effect.fail(read.failure);
2023
2065
  }
2024
2066
  const bitmaps = yield* Effect.result(named(orWhole(bitmapsStep(parts, listed, data, input, allotment))));
2025
- if (Result.isSuccess(bitmaps)) return more(bitmaps.success ?? started(listed));
2067
+ if (Result.isSuccess(bitmaps)) return more(bitmaps.success ?? started(listed, rootsKey));
2026
2068
  if (isSliceRefused(bitmaps.failure)) return final(bitmaps.failure);
2027
2069
  return yield* Effect.fail(bitmaps.failure);
2028
2070
  }, Effect.scoped);
@@ -2052,9 +2094,11 @@ const indexTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, limits, lis
2052
2094
  if (input.deleted !== void 0) step.deleted = input.deleted;
2053
2095
  if (input.failed !== void 0) step.failed = input.failed;
2054
2096
  if (input.lastCheck === true) step.lastCheck = true;
2097
+ const roots = new Set(input.roots ?? []);
2055
2098
  const ended = yield* indexStep({
2056
2099
  ...parts,
2057
- graphMost: limits.graphMost
2100
+ graphMost: limits.graphMost,
2101
+ roots
2058
2102
  }, listed, step);
2059
2103
  if (ended.kind !== "done") return ended;
2060
2104
  return {
@@ -2066,4 +2110,4 @@ const indexTry = /* @__PURE__ */ Effect.fnUntraced(function* (parts, limits, lis
2066
2110
  data: ended.data
2067
2111
  };
2068
2112
  });
2069
- export { BitmapsCut, BuiltIndex, IndexBounds, IndexData, IndexGroup, IndexLayer, IndexRefusal, IndexRow, IndexSlice, IndexTries, Narrowed, RefusedIndex, ReplacedBuild, belowGraphs, bitmapsJoinHeld, bitmapsJoinMost, boundsOf, builtIndexOf, chooseCommits, copyMergedBitmaps, coveredPacks, coversAll, decodeIndexValue, denseBelow, denseBelowReads, edgesMost, entriesHeld, floors, graphMostOf, indexBitmapsCallsAfter, indexReadCallsAfter, indexRowOf, indexSaves, indexStatus, indexStep, indexSteps, indexTry, limitsOf, lostIndexRow, madeMost, mergeCallsAfterOpen, mergeChunk, mergeHeldMost, narrowedAfter, newBuildId, positionOrder, pruneBuilds, putOnce, reachesBytes, reachesOf, readFurther, rowsOfLayer, sliceBounds, storedTypesOf, triesWait, triesWaitMost, triesWaitOf, wordsOf };
2113
+ export { BitmapsCut, BuiltIndex, IndexBounds, IndexData, IndexGroup, IndexLayer, IndexRefusal, IndexRow, IndexSlice, IndexTries, Narrowed, RefusedIndex, ReplacedBuild, belowGraphs, bitmapsJoinHeld, bitmapsJoinMost, boundsOf, builtIndexOf, builtOver, chooseCommits, copyMergedBitmaps, coveredPacks, coversAll, decodeIndexValue, denseBelow, denseBelowReads, edgesMost, entriesHeld, floors, graphMostOf, indexBitmapsCallsAfter, indexReadCallsAfter, indexRowOf, indexSaves, indexStatus, indexStep, indexSteps, indexTry, limitsOf, lostIndexRow, madeMost, mergeCallsAfterOpen, mergeChunk, mergeHeldMost, narrowedAfter, newBuildId, positionOrder, pruneBuilds, putOnce, reachesBytes, reachesOf, readFurther, rootsKeyOf, rowsOfLayer, sliceBounds, storedTypesOf, triesWait, triesWaitMost, triesWaitOf, wordsOf };
@@ -6,7 +6,7 @@ import { repoScope } from "../store/scopes.mjs";
6
6
  import { anySet, bitCount, clearBit, isSet, nextSet, setBit } from "./bits.mjs";
7
7
  import { bitmapWords } from "./ewah.mjs";
8
8
  import { ewahMostWords } from "./index-bitmaps.mjs";
9
- import { builtIndexOf, coveredPacks, coversAll, decodeIndexValue } from "./index-build.mjs";
9
+ import { builtIndexOf, builtOver, coveredPacks, coversAll, decodeIndexValue } from "./index-build.mjs";
10
10
  import { openTypes, typeOfCode } from "./index-files.mjs";
11
11
  import { indexShallow, numberIn, numbersIn } from "./index-shallow.mjs";
12
12
  import { listOf } from "./send-list.mjs";
@@ -16,6 +16,7 @@ import { indexFiles, indexRowKey, isPackId, packFiles } from "./layout.mjs";
16
16
  import { rangeCached, rangeEntriesBytes } from "./range-cache.mjs";
17
17
  import { joinBytes, missing } from "./link-join.mjs";
18
18
  import { placedReads } from "./placed-reads.mjs";
19
+ import { withRootsSent } from "./shallow.mjs";
19
20
  import { lost, notHeld } from "./walk.mjs";
20
21
  import * as Effect from "effect/Effect";
21
22
  import * as Data from "effect/Data";
@@ -125,7 +126,7 @@ const openFetchIndex = /* @__PURE__ */ Effect.fnUntraced(function* (source, ahea
125
126
  reads: [indexRowKey]
126
127
  });
127
128
  const row = builtIndexOf(decodeIndexValue(snapshot.results[0]?.[0]?.value));
128
- if (row === void 0 || !coversAll(row.layers, listed)) return void 0;
129
+ if (row === void 0 || !builtOver(row, read.roots) || !coversAll(row.layers, listed)) return void 0;
129
130
  if (source.opened !== void 0) source.opened.opened = true;
130
131
  yield* ahead(fetchOpenCalls(row.layers));
131
132
  yield* hold(regionBytes(row.layers));
@@ -668,6 +669,18 @@ const indexSendSetOrNot = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
668
669
  if (position === 4294967295 ? heldExtras.has(tag) : isSet(held, position)) had.add(tag);
669
670
  }
670
671
  }
672
+ const rootsSent = /* @__PURE__ */ new Set();
673
+ const rootsAt = row.layers.flatMap((layer) => (layer.roots ?? []).filter((position) => isSet(send, position)));
674
+ const packed = rootsAt.filter((position) => layout.ranges.some((pack) => position >= pack.base && position < pack.base + pack.count));
675
+ if (packed.length > 0) yield* ahead({
676
+ bucket: 2 * packed.length,
677
+ store: 0
678
+ });
679
+ for (const position of rootsAt) {
680
+ const root = hexOf(yield* layout.idAt(position));
681
+ if (read.roots.has(root)) rootsSent.add(root);
682
+ }
683
+ for (const root of read.roots) if (sentExtras.get(root)?.kind === "commit") rootsSent.add(root);
671
684
  yield* index.letRangesGo;
672
685
  const windows = [];
673
686
  for (const [at, layer] of row.layers.entries()) {
@@ -777,7 +790,7 @@ const indexSendSetOrNot = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
777
790
  return restIds.has(oid) || position !== 4294967295 && isSet(send, position);
778
791
  }));
779
792
  }),
780
- deepened
793
+ deepened: withRootsSent(deepened, rootsSent)
781
794
  };
782
795
  });
783
796
  export { fetchOpenCalls, indexEligible, indexSendSet };
@@ -1,5 +1,6 @@
1
+ import { hexOf } from "../protocol/bytes/hex.mjs";
1
2
  import { bitmapWords } from "./ewah.mjs";
2
- import { builtIndexOf, coversAll, decodeIndexValue } from "./index-build.mjs";
3
+ import { builtIndexOf, builtOver, coversAll, decodeIndexValue } from "./index-build.mjs";
3
4
  import { hasBit, idsOf, openLayerBitmaps, openLayout, orIntoAtOnce, orIntoBytes, orIntoFiles, orWords, reachOf, whileFollowed } from "./index-layers.mjs";
4
5
  import { readReserveBytes } from "./budget.mjs";
5
6
  import { missing } from "./link-join.mjs";
@@ -148,14 +149,18 @@ const outsideOf = /* @__PURE__ */ Effect.fnUntraced(function* (input, tips, most
148
149
  closed: true
149
150
  };
150
151
  });
151
- /** Whether `row` names a built index that covers `listed`, so a reach of it answers. */
152
+ /**
153
+ * Whether `row` names a built index that covers `listed`, so a reach of it may answer: `tipsReach`
154
+ * still walks past one built over other roots.
155
+ */
152
156
  const indexCovers = (input, listed) => {
153
157
  const built = builtIndexOf(decodeIndexValue(input.row));
154
158
  return built !== void 0 && coversAll(built.layers, listed);
155
159
  };
156
160
  /**
157
161
  * What `input.tips` reach, by the index `input.row` names over `listed`, or `undefined` when it
158
- * doesn't cover `listed`, as after a repack took a covered pack out, for the caller's walk. A tip
162
+ * doesn't cover `listed`, as after a repack took a covered pack out, or was built over other
163
+ * roots than `input.roots`, for the caller's walk. A tip
159
164
  * whose reach won't close within `most` sets `pastLimit`. Where `unclosed`, so does one whose walk
160
165
  * meets an object past the bytes it may follow at once, which a fetch's want check refuses as
161
166
  * `levelTooLarge`: a visible set still shows its tips, and what their bitmaps reach. Its walks
@@ -168,7 +173,7 @@ const tipsReach = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, in
168
173
  tooLarge = true;
169
174
  })) : walk;
170
175
  const built = builtIndexOf(decodeIndexValue(input.row));
171
- if (built === void 0 || !coversAll(built.layers, listed)) return void 0;
176
+ if (built === void 0 || !builtOver(built, input.roots) || !coversAll(built.layers, listed)) return void 0;
172
177
  const last = built.layers[built.layers.length - 1];
173
178
  const words = bitmapWords(last === void 0 ? 0 : last.first + last.positions);
174
179
  const files = orIntoFiles(built.layers);
@@ -284,6 +289,29 @@ const reachAnswers = /* @__PURE__ */ Effect.fnUntraced(function* (reach, wants,
284
289
  return answers;
285
290
  });
286
291
  /**
292
+ * Which of `input.roots` the tips reach, by the index `input.row` names over `listed`: each root
293
+ * whose position a layer keeps that the tips' union holds, and each the walk outside the index
294
+ * met. A root's ID is read only where the union holds it, so one the tips don't reach, as one only
295
+ * a hidden ref reaches, costs no call, as a fetch's `rootsSent` reads them (#2462). `undefined`
296
+ * where the index can't give the walk's answer: none covers `listed`, it's over other roots, or
297
+ * a tip's reach won't close.
298
+ */
299
+ const reachedRoots = /* @__PURE__ */ Effect.fnUntraced(function* (parts, listed, input) {
300
+ const built = builtIndexOf(decodeIndexValue(input.row));
301
+ if (built === void 0) return void 0;
302
+ const reach = yield* tipsReach(parts, listed, input);
303
+ if (reach === void 0 || reach.pastLimit !== void 0) return void 0;
304
+ const roots = input.roots ?? /* @__PURE__ */ new Set();
305
+ const reached = /* @__PURE__ */ new Set();
306
+ for (const layer of built.layers) for (const position of layer.roots ?? []) {
307
+ if (!hasBit(reach.union, position)) continue;
308
+ const root = hexOf(yield* reach.layout.idAt(position));
309
+ if (roots.has(root)) reached.add(root);
310
+ }
311
+ for (const root of roots) if (reach.outside?.has(root) === true) reached.add(root);
312
+ return reached;
313
+ }, Effect.scoped);
314
+ /**
287
315
  * Which of `input.wants` the tips reach, by the index `input.row` names over `listed`, as
288
316
  * `reachAnswers` says. A tip whose reach won't close within `most` leaves the wants it doesn't
289
317
  * show reached unanswered and sets `pastLimit`, and its caller refuses them alike. An index that
@@ -321,4 +349,4 @@ const wantsBy = /* @__PURE__ */ Effect.fnUntraced(function* (reach, wants) {
321
349
  updatesRefused
322
350
  };
323
351
  });
324
- export { ReachCache, indexCovers, indexReach, reachAnswers, reachCacheBytes, tipsReach, wantsBy };
352
+ export { ReachCache, indexCovers, indexReach, reachAnswers, reachCacheBytes, reachedRoots, tipsReach, wantsBy };
@@ -504,7 +504,12 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
504
504
  bitmaps: bitmaps.count,
505
505
  table: bitmaps.table
506
506
  };
507
- return {
507
+ const roots = layers.flatMap((each) => (each.roots ?? []).flatMap((at) => {
508
+ const to = move.position(at);
509
+ return to === void 0 ? [] : [to];
510
+ }));
511
+ if (roots.length > 0) layer.roots = [...new Set(roots)].sort((a, b) => a - b);
512
+ const rebuilt = {
508
513
  rounds: row.rounds,
509
514
  layers: [layer],
510
515
  replaced: [...row.replaced.filter((each) => each.at + input.grace > input.at), ...layers.map((each) => ({
@@ -512,6 +517,8 @@ const remapIndex = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
512
517
  at: input.at
513
518
  }))]
514
519
  };
520
+ if (row.roots !== void 0) rebuilt.roots = row.roots;
521
+ return rebuilt;
515
522
  });
516
523
  /**
517
524
  * The `index` row a geometric step's merge leaves, laid again over its pack, or `undefined` when