@ref0/git 0.7.0 → 0.9.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 (245) hide show
  1. package/dist/access/private-refs.mjs +0 -2
  2. package/dist/auth/authorize.mjs +31 -24
  3. package/dist/auth/bridge.mjs +8 -8
  4. package/dist/auth/fences.d.mts +0 -1
  5. package/dist/auth/fences.mjs +1 -1
  6. package/dist/auth/grants.d.mts +0 -1
  7. package/dist/auth/grants.mjs +2 -2
  8. package/dist/auth/host-function.d.mts +1 -7
  9. package/dist/auth/host-function.mjs +38 -38
  10. package/dist/auth/identify.d.mts +0 -1
  11. package/dist/auth/identify.mjs +1 -1
  12. package/dist/auth/policy.d.mts +7 -4
  13. package/dist/auth/policy.mjs +13 -10
  14. package/dist/auth/token-rows.mjs +2 -5
  15. package/dist/auth/tokens-layer.d.mts +0 -2
  16. package/dist/auth/tokens-public.d.mts +3 -3
  17. package/dist/auth/tokens-public.mjs +4 -2
  18. package/dist/auth/tokens.d.mts +6 -1
  19. package/dist/auth/tokens.mjs +7 -1
  20. package/dist/client/client.d.mts +22 -15
  21. package/dist/client/client.mjs +31 -27
  22. package/dist/client/git-http.mjs +22 -5
  23. package/dist/client/local.mjs +1 -1
  24. package/dist/client/namespace.d.mts +2 -0
  25. package/dist/client/push-upload.d.mts +1 -0
  26. package/dist/client/push-upload.mjs +169 -2
  27. package/dist/client/remote-helper.mjs +2 -4
  28. package/dist/client/remote.mjs +37 -15
  29. package/dist/client/run-remote-helper.mjs +4 -4
  30. package/dist/client/transport.mjs +26 -19
  31. package/dist/contracts/actors.d.mts +57 -28
  32. package/dist/contracts/actors.mjs +38 -2
  33. package/dist/contracts/authorize.d.mts +21 -15
  34. package/dist/contracts/callers.mjs +40 -0
  35. package/dist/contracts/calls-spent.d.mts +2 -12
  36. package/dist/contracts/calls-spent.mjs +4 -5
  37. package/dist/contracts/client.d.mts +16 -9
  38. package/dist/contracts/events.d.mts +82 -14
  39. package/dist/contracts/events.mjs +35 -9
  40. package/dist/contracts/files.d.mts +42 -42
  41. package/dist/contracts/forks.d.mts +0 -24
  42. package/dist/contracts/git-hooks.d.mts +217 -0
  43. package/dist/contracts/git-hooks.mjs +3 -1
  44. package/dist/contracts/git.d.mts +13 -3
  45. package/dist/contracts/grants.d.mts +46 -27
  46. package/dist/contracts/lfs.d.mts +17 -4
  47. package/dist/contracts/merges.d.mts +7 -7
  48. package/dist/contracts/objects.d.mts +38 -4
  49. package/dist/contracts/opaque.mjs +19 -1
  50. package/dist/contracts/operations.d.mts +8 -1
  51. package/dist/contracts/operations.mjs +209 -0
  52. package/dist/contracts/queue.d.mts +6 -5
  53. package/dist/contracts/queue.mjs +9 -20
  54. package/dist/contracts/remote.d.mts +13 -4
  55. package/dist/contracts/remote.mjs +3 -3
  56. package/dist/contracts/repos.d.mts +11 -40
  57. package/dist/contracts/repos.mjs +11 -10
  58. package/dist/contracts/result.d.mts +28 -11
  59. package/dist/contracts/result.mjs +32 -2
  60. package/dist/contracts/rules.d.mts +706 -46
  61. package/dist/contracts/rules.mjs +81 -2
  62. package/dist/contracts/server.d.mts +5 -275
  63. package/dist/contracts/services.d.mts +0 -3
  64. package/dist/contracts/services.mjs +1 -3
  65. package/dist/contracts/signin.d.mts +2 -2
  66. package/dist/contracts/signin.mjs +4 -5
  67. package/dist/contracts/sync.d.mts +1 -4
  68. package/dist/contracts/tokens.d.mts +29 -17
  69. package/dist/contracts/tokens.mjs +14 -3
  70. package/dist/contracts/topics.d.mts +38 -11
  71. package/dist/contracts/topics.mjs +8 -2
  72. package/dist/core/access.d.mts +0 -2
  73. package/dist/core/access.mjs +15 -4
  74. package/dist/core/ancestry.mjs +5 -4
  75. package/dist/core/events/deliver.mjs +19 -1
  76. package/dist/core/forks.mjs +30 -11
  77. package/dist/core/hooks/groups.d.mts +0 -1
  78. package/dist/core/hooks/groups.mjs +8 -9
  79. package/dist/core/index-job.mjs +23 -1
  80. package/dist/core/index-lost.d.mts +11 -0
  81. package/dist/core/index-lost.mjs +55 -0
  82. package/dist/core/loose-tally.mjs +46 -0
  83. package/dist/core/objects/commit-writes.mjs +1 -1
  84. package/dist/core/objects/commits.mjs +10 -9
  85. package/dist/core/objects/merges.mjs +1 -1
  86. package/dist/core/objects/reading.mjs +28 -13
  87. package/dist/core/objects/trees.mjs +1 -1
  88. package/dist/core/objects/writing.mjs +1 -0
  89. package/dist/core/parts.d.mts +7 -0
  90. package/dist/core/promise.mjs +1 -15
  91. package/dist/core/publish.mjs +9 -5
  92. package/dist/core/purge.mjs +30 -12
  93. package/dist/core/push.mjs +39 -16
  94. package/dist/core/ref-view.mjs +14 -6
  95. package/dist/core/repack.mjs +54 -27
  96. package/dist/core/repo-info.mjs +8 -6
  97. package/dist/core/repos.mjs +1 -0
  98. package/dist/core/rules/check.mjs +10 -10
  99. package/dist/core/rules/context.d.mts +3 -1
  100. package/dist/core/rules/context.mjs +16 -13
  101. package/dist/core/rules/fetch.mjs +17 -23
  102. package/dist/core/tokens.mjs +2 -1
  103. package/dist/core/view.d.mts +10 -1
  104. package/dist/core/view.mjs +15 -6
  105. package/dist/effect.d.mts +3 -6
  106. package/dist/effect.mjs +3 -6
  107. package/dist/engine/commits.mjs +23 -50
  108. package/dist/engine/failures.d.mts +1 -2
  109. package/dist/engine/failures.mjs +1 -3
  110. package/dist/engine/merge-base-walk.mjs +57 -142
  111. package/dist/engine/merge-bases.mjs +9 -7
  112. package/dist/engine/merge.mjs +20 -17
  113. package/dist/engine/parts.d.mts +1 -0
  114. package/dist/engine/parts.mjs +1 -1
  115. package/dist/engine/walk.mjs +15 -11
  116. package/dist/extend.d.mts +1 -2
  117. package/dist/extend.mjs +1 -2
  118. package/dist/http/core-parts.mjs +18 -10
  119. package/dist/http/handler.mjs +11 -31
  120. package/dist/http/parts.d.mts +0 -1
  121. package/dist/index.d.mts +29 -22
  122. package/dist/index.mjs +5 -2
  123. package/dist/lfs/base.d.mts +6 -3
  124. package/dist/lfs/base.mjs +2 -1
  125. package/dist/lfs/layer.d.mts +4 -3
  126. package/dist/lfs/layer.mjs +23 -9
  127. package/dist/lfs/objects.mjs +93 -41
  128. package/dist/lfs/pointers.mjs +69 -18
  129. package/dist/lfs/purge.mjs +6 -2
  130. package/dist/lfs/rows.mjs +24 -7
  131. package/dist/lfs/service.d.mts +6 -3
  132. package/dist/lfs/service.mjs +8 -2
  133. package/dist/lfs/upkeep.mjs +47 -28
  134. package/dist/lfs/upload-most.mjs +47 -0
  135. package/dist/lfs/uploaded.mjs +59 -0
  136. package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
  137. package/dist/protocol/bytes/streams.mjs +84 -2
  138. package/dist/protocol/bytes/text.mjs +6 -1
  139. package/dist/protocol/diff/read.d.mts +1 -0
  140. package/dist/protocol/diff/read.mjs +5 -2
  141. package/dist/protocol/objects/commit.d.mts +7 -0
  142. package/dist/protocol/objects/commit.mjs +5 -1
  143. package/dist/protocol/objects/fsck.mjs +6 -3
  144. package/dist/queue/advance.mjs +77 -18
  145. package/dist/queue/calls.mjs +4 -14
  146. package/dist/queue/host.d.mts +4 -0
  147. package/dist/queue/lanes.mjs +1 -1
  148. package/dist/queue/layer.mjs +4 -2
  149. package/dist/queue/limits.mjs +18 -2
  150. package/dist/queue/rows.mjs +10 -1
  151. package/dist/queue/schedule.mjs +1 -1
  152. package/dist/queue/search.mjs +3 -4
  153. package/dist/queue/trim.mjs +2 -2
  154. package/dist/rest/client-namespace.d.mts +2 -0
  155. package/dist/rest/client.d.mts +32 -8
  156. package/dist/rest/client.mjs +308 -382
  157. package/dist/rest/commits.d.mts +150 -150
  158. package/dist/rest/files.d.mts +18 -18
  159. package/dist/rest/forks.d.mts +77 -89
  160. package/dist/rest/handlers.mjs +2 -1
  161. package/dist/rest/listen.d.mts +8 -6
  162. package/dist/rest/listen.mjs +31 -75
  163. package/dist/rest/me.d.mts +2 -2
  164. package/dist/rest/merges.d.mts +7 -7
  165. package/dist/rest/refs.d.mts +27 -27
  166. package/dist/rest/repos.d.mts +40 -52
  167. package/dist/rest/tokens.d.mts +12 -12
  168. package/dist/rest/topics.d.mts +13 -13
  169. package/dist/rest/trees.d.mts +66 -66
  170. package/dist/rest/wire.d.mts +20 -2
  171. package/dist/rest/work.d.mts +39 -39
  172. package/dist/rest.d.mts +1 -7
  173. package/dist/rest.mjs +1 -5
  174. package/dist/server/git-layer.d.mts +10 -2
  175. package/dist/server/git-layer.mjs +29 -10
  176. package/dist/server/joined.d.mts +12 -6
  177. package/dist/server/joined.mjs +3 -2
  178. package/dist/server/registry.mjs +11 -5
  179. package/dist/server/server.d.mts +0 -1
  180. package/dist/server/server.mjs +42 -49
  181. package/dist/signin/context.d.mts +0 -1
  182. package/dist/signin/context.mjs +5 -9
  183. package/dist/storage/clean-up.mjs +3 -1
  184. package/dist/storage/fsck.mjs +12 -2
  185. package/dist/storage/graph-rebuild.mjs +262 -0
  186. package/dist/storage/index-bitmaps.mjs +16 -10
  187. package/dist/storage/index-build.mjs +160 -24
  188. package/dist/storage/index-graph.d.mts +1 -0
  189. package/dist/storage/index-graph.mjs +29 -5
  190. package/dist/storage/index-layers.d.mts +1 -0
  191. package/dist/storage/index-layers.mjs +5 -2
  192. package/dist/storage/index-reach.mjs +7 -5
  193. package/dist/storage/index-remap.mjs +5 -5
  194. package/dist/storage/index-visible.mjs +16 -5
  195. package/dist/storage/lfs-pointers.d.mts +5 -5
  196. package/dist/storage/lfs-pointers.mjs +37 -11
  197. package/dist/storage/links.mjs +3 -3
  198. package/dist/storage/loose.mjs +4 -1
  199. package/dist/storage/memory-budget.mjs +1 -1
  200. package/dist/storage/merge-fence.mjs +81 -19
  201. package/dist/storage/merge-most.mjs +1 -0
  202. package/dist/storage/merge-row.mjs +16 -4
  203. package/dist/storage/merge-stream.mjs +9 -6
  204. package/dist/storage/object-rows.mjs +17 -1
  205. package/dist/storage/pack-order.d.mts +1 -0
  206. package/dist/storage/pack-order.mjs +18 -1
  207. package/dist/storage/pack-receive.mjs +10 -6
  208. package/dist/storage/packs.mjs +58 -27
  209. package/dist/storage/prune-walk.mjs +5 -2
  210. package/dist/storage/prune.mjs +168 -70
  211. package/dist/storage/ready.d.mts +1 -1
  212. package/dist/storage/ready.mjs +12 -3
  213. package/dist/storage/receive-bounds.mjs +3 -2
  214. package/dist/storage/receive-state.mjs +1 -1
  215. package/dist/storage/repack-contained.mjs +22 -14
  216. package/dist/storage/repack.d.mts +1 -1
  217. package/dist/storage/repack.mjs +3 -2
  218. package/dist/storage/unpack.mjs +7 -0
  219. package/dist/storage/visible.mjs +3 -2
  220. package/dist/storage/walk.d.mts +1 -0
  221. package/dist/storage/walk.mjs +9 -5
  222. package/dist/storage/wants.mjs +17 -11
  223. package/dist/store/call-count.d.mts +31 -3
  224. package/dist/store/call-count.mjs +51 -20
  225. package/dist/store/errors.d.mts +7 -1
  226. package/dist/store/errors.mjs +7 -1
  227. package/dist/store/job-try.mjs +3 -1
  228. package/dist/store/records.mjs +26 -5
  229. package/dist/store/repo-record.mjs +36 -12
  230. package/dist/store/scopes.mjs +15 -2
  231. package/dist/sync/bound.d.mts +1 -1
  232. package/dist/sync/import.mjs +15 -3
  233. package/dist/sync/layer.d.mts +5 -1
  234. package/dist/sync/layer.mjs +11 -9
  235. package/dist/sync/mirror.mjs +1 -1
  236. package/dist/sync/step.mjs +15 -15
  237. package/dist/topics/advance.mjs +11 -10
  238. package/dist/topics/layer.mjs +1 -1
  239. package/dist/topics/members.mjs +38 -9
  240. package/package.json +3 -3
  241. package/dist/engine/merge-base-walk.d.mts +0 -3
  242. package/dist/server/routes.d.mts +0 -32
  243. package/dist/server/routes.mjs +0 -69
  244. package/dist/sync/bridge.d.mts +0 -6
  245. package/dist/sync/bridge.mjs +0 -29
@@ -251,15 +251,22 @@ const unpackObjects = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
251
251
  yield* fscked(input, objects);
252
252
  const cut = yield* connected(input, objects);
253
253
  const rows = [...objects.values()].map(objectRow);
254
+ let valuesBytes = 0;
254
255
  for (const row of rows) {
255
256
  const valueBytes = rowValueBytes(row.value);
256
257
  if (valueBytes > limits.valueBytes) return yield* Effect.fail(rowTooLarge(row.id, valueBytes));
258
+ valuesBytes += valueBytes;
257
259
  }
258
260
  const rowBytes = rows.reduce((sum, row) => sum + JSON.stringify(row).length, 0);
259
261
  if (rowBytes > limits$1.bytes) return yield* Effect.fail(tooLarge(rowBytes, limits$1.bytes));
262
+ const moved = {
263
+ objects: rows.length,
264
+ bytes: valuesBytes
265
+ };
260
266
  return {
261
267
  objects: [...objects.values()],
262
268
  rows,
269
+ moved,
263
270
  bytes,
264
271
  cut
265
272
  };
@@ -30,7 +30,8 @@ const visibleTooLong = (most) => gitError("RESOURCE_EXHAUSTED", `${tooLongText}
30
30
  /** Whether `error` is a set's refusal past its walk's bound, which a caller may tell in its own words. */
31
31
  const isVisibleTooLong = (error) => error.code === "RESOURCE_EXHAUSTED" && error.message.startsWith(tooLongText);
32
32
  /**
33
- * The objects `input.tips` reach in `listed`, read through `objects`, the repo's whole objects.
33
+ * The objects `input.tips` reach in `listed`, through no parent of `input.roots`, read through
34
+ * `objects`, the repo's whole objects.
34
35
  * Nothing is read until the set is first asked. Its walk's state is the set's own: it lives with
35
36
  * one request's view, for one caller, and is never shared across callers. A batch of the walk
36
37
  * that fails to read changes none of it, so an ask that fails leaves the set as it was, and the
@@ -54,7 +55,7 @@ const walkedVisible = (objects, listed, input, walk = {}) => {
54
55
  const stepped = (oid) => Effect.flatMap(walk.read(listed, {
55
56
  oid,
56
57
  ...call
57
- }), (object) => object === void 0 ? Effect.succeed(void 0) : stepsOf(object, !commits));
58
+ }), (object) => object === void 0 ? Effect.succeed(void 0) : stepsOf(object, !commits, input.roots));
58
59
  const found = yield* Effect.forEach(batch, stepped, { concurrency: 16 });
59
60
  frontier = frontier.slice(walkBatch);
60
61
  reads += batch.length;
@@ -3,6 +3,7 @@ import "../contracts/objects.mjs";
3
3
  import "../contracts/result.mjs";
4
4
  import "../contracts/store.mjs";
5
5
  import "../protocol/bytes/errors.mjs";
6
+ import "../protocol/objects/commit.mjs";
6
7
  import "./object-rows.mjs";
7
8
  import "./pack-reads.mjs";
8
9
  import "effect/Effect";
@@ -1,5 +1,5 @@
1
1
  import { gitError } from "../contracts/result.mjs";
2
- import { decodeCommit } from "../protocol/objects/commit.mjs";
2
+ import { decodeCommit, noRepoRoots, parentsWithin } from "../protocol/objects/commit.mjs";
3
3
  import { decodeTag } from "../protocol/objects/tag.mjs";
4
4
  import { treeEntriesIn, treeReader } from "../protocol/objects/tree.mjs";
5
5
  import "./links.mjs";
@@ -35,8 +35,11 @@ const treeEntriesOf = (bytes) => {
35
35
  }
36
36
  };
37
37
  const unreadable = (object, message) => gitError("DATA_LOSS", `The ${object.type} ${object.oid} is unreadable: ${message}`);
38
- /** What a plan takes from an object it read: bytes it holds that Git wouldn't take are `DATA_LOSS`. */
39
- const takenOf = (object) => {
38
+ /**
39
+ * What a plan takes from an object it read: bytes it holds that Git wouldn't take are `DATA_LOSS`.
40
+ * One of `roots` has no history, so no walk follows its parents, but its tree is followed.
41
+ */
42
+ const takenOf = (object, roots) => {
40
43
  const read = {
41
44
  oid: object.oid,
42
45
  type: object.type,
@@ -54,7 +57,7 @@ const takenOf = (object) => {
54
57
  })), Effect.mapError(lossOf));
55
58
  case "commit": return decodeCommit(object.bytes).pipe(Effect.map((commit) => ({
56
59
  ...read,
57
- history: commit.parents,
60
+ history: parentsWithin(roots, object.oid, commit.parents),
58
61
  tree: commit.tree
59
62
  })), Effect.mapError(lossOf));
60
63
  case "tree": return Effect.suspend(() => Effect.fromResult(treeEntriesOf(object.bytes))).pipe(Effect.map((entries) => ({
@@ -85,6 +88,7 @@ const tooManyReads = (readsMost) => gitError("RESOURCE_EXHAUSTED", `This fetch's
85
88
  * what's paid for trees and into what's paid for them, so each string is counted once.
86
89
  */
87
90
  const countedReads = (reads, readsMost, charge, calls, release) => {
91
+ const roots = reads.roots ?? noRepoRoots;
88
92
  let counted = 0;
89
93
  let entryBytesHeld = 0;
90
94
  let entryBytesPaid = 0;
@@ -113,7 +117,7 @@ const countedReads = (reads, readsMost, charge, calls, release) => {
113
117
  for (let at = 0; at < oids.length; at += 64) yield* each(oids.slice(at, at + 64), Effect.fnUntraced(function* (object) {
114
118
  const entries = object.type === "tree" ? treeEntriesIn(object.bytes) : 0;
115
119
  yield* holdEntries(entries);
116
- const taken = yield* takenOf(object);
120
+ const taken = yield* takenOf(object, roots);
117
121
  entryBytesHeld -= (entries - keptOf(taken)) * 70;
118
122
  found.set(object.oid, taken);
119
123
  }));
@@ -1,7 +1,7 @@
1
1
  import { objectsReadMost } from "../contracts/object-values.mjs";
2
2
  import { gitError } from "../contracts/result.mjs";
3
3
  import { hexOf } from "../protocol/bytes/hex.mjs";
4
- import { decodeCommit } from "../protocol/objects/commit.mjs";
4
+ import { decodeCommit, noRepoRoots, parentsWithin } from "../protocol/objects/commit.mjs";
5
5
  import { decodeTag, readTagTarget } from "../protocol/objects/tag.mjs";
6
6
  import { oidBytes } from "../protocol/packs/idx.mjs";
7
7
  import { effectOf, walkObjects } from "./calls.mjs";
@@ -97,14 +97,17 @@ const nowhere = {
97
97
  * walk reads trees; a tag to what it tags; a tree to its folders, and to its files, which are
98
98
  * reached unread. A blob, or a tree in a walk that reads none, leads nowhere, its bytes unread.
99
99
  */
100
- /** Where a walk goes from an object read whole: a blob, or a tree it doesn't walk, goes nowhere. */
101
- const stepsOfBytes = /* @__PURE__ */ Effect.fnUntraced(function* (object, bytes, readsTrees) {
100
+ /**
101
+ * Where a walk goes from an object read whole: a blob, or a tree it doesn't walk, goes nowhere. One
102
+ * of `roots` leads to its tree alone, never its parents.
103
+ */
104
+ const stepsOfBytes = /* @__PURE__ */ Effect.fnUntraced(function* (object, bytes, readsTrees, roots) {
102
105
  if (object.type === "blob" || object.type === "tree" && !readsTrees) return nowhere;
103
106
  const failed = (error) => unreadable(object, error.message);
104
107
  if (object.type === "commit") {
105
108
  const commit = yield* Effect.mapError(decodeCommit(bytes), failed);
106
109
  return {
107
- history: commit.parents,
110
+ history: parentsWithin(roots, object.oid, commit.parents),
108
111
  trees: readsTrees ? [commit.tree] : [],
109
112
  reached: []
110
113
  };
@@ -126,12 +129,12 @@ const stepsOfBytes = /* @__PURE__ */ Effect.fnUntraced(function* (object, bytes,
126
129
  * Where a walk goes from an object streamed: a blob, or a tree it doesn't walk, is cancelled
127
130
  * unread, so a tag's blob of any size costs its header alone.
128
131
  */
129
- const stepsOf = /* @__PURE__ */ Effect.fnUntraced(function* (object, readsTrees) {
132
+ const stepsOf = /* @__PURE__ */ Effect.fnUntraced(function* (object, readsTrees, roots = noRepoRoots) {
130
133
  if (object.type === "blob" || object.type === "tree" && !readsTrees) {
131
134
  yield* Effect.promise(() => object.bytes.cancel());
132
135
  return nowhere;
133
136
  }
134
- return yield* stepsOfBytes(object, yield* bytesOf(object), readsTrees);
137
+ return yield* stepsOfBytes(object, yield* bytesOf(object), readsTrees, roots);
135
138
  });
136
139
  /**
137
140
  * Every object a walk reads next from `steps`, a tag's object among them: what the visible set's
@@ -254,9 +257,10 @@ const lookedUp = /* @__PURE__ */ Effect.fnUntraced(function* (input, packed) {
254
257
  });
255
258
  /**
256
259
  * A read's meeting with an index that fails its own checks, `DATA_LOSS`: one error line in the
257
- * log, so the host hears of it, while the read walks as with no index.
260
+ * log, so the host hears of it, then `lost`, the core's ask for the row's rebuild, while the read
261
+ * walks as with no index.
258
262
  */
259
- const indexUnreadable = (repo, error) => Effect.logError(`The reachability index of repo ${repo} is unreadable, so its reads walk: ${error.message}`);
263
+ const indexUnreadable = (repo, error, lost = Effect.void) => Effect.logError(`The reachability index of repo ${repo} is unreadable, so its reads walk: ${error.message}`).pipe(Effect.andThen(lost));
260
264
  /**
261
265
  * The first of `wants` no readable ref reaches, or `undefined`. A want a ref names passes with no
262
266
  * read, as nearly every fetch's do. With the repo's reachability index, each other want is
@@ -275,8 +279,9 @@ const unreachableWant = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
275
279
  row: index.row,
276
280
  tips: [...input.tips],
277
281
  wants: asked,
282
+ roots: input.roots,
278
283
  ...signal
279
- }).pipe(Effect.catchIf((error) => error.code === "DATA_LOSS", (error) => indexUnreadable(input.listed.repo, error).pipe(Effect.as({ answers: /* @__PURE__ */ new Map() }))));
284
+ }).pipe(Effect.catchIf((error) => error.code === "DATA_LOSS", (error) => indexUnreadable(input.listed.repo, error, index.lost).pipe(Effect.as({ answers: /* @__PURE__ */ new Map() }))));
280
285
  if (pastLimit !== void 0 && asked.some((want) => answers.get(want) !== true)) return yield* Effect.fail(refused === true ? updatesRefused(pastLimit) : updatePending(pastLimit));
281
286
  const unknown = asked.filter((want) => answers.get(want) === void 0);
282
287
  const walked = unknown.length === 0 ? void 0 : yield* walkedWant({
@@ -303,6 +308,7 @@ const walkedWant = /* @__PURE__ */ Effect.fnUntraced(function* (given) {
303
308
  const looked = yield* lookedUp(input, packed);
304
309
  if (looked.absent !== void 0) return looked.absent;
305
310
  const most = input.most ?? 1e4;
311
+ const roots = input.roots ?? noRepoRoots;
306
312
  let left = packed.count;
307
313
  let deepLeft = looked.deep;
308
314
  const call = input.signal === void 0 ? {} : { signal: input.signal };
@@ -357,7 +363,7 @@ const walkedWant = /* @__PURE__ */ Effect.fnUntraced(function* (given) {
357
363
  yield* Effect.forEach(tagged, (oid) => Effect.flatMap(input.objects.read(input.listed, {
358
364
  oid,
359
365
  ...call
360
- }), (object) => object === void 0 ? Effect.void : Effect.map(stepsOf(object, readsTrees), follow)), {
366
+ }), (object) => object === void 0 ? Effect.void : Effect.map(stepsOf(object, readsTrees, roots), follow)), {
361
367
  concurrency: 16,
362
368
  discard: true
363
369
  });
@@ -371,7 +377,7 @@ const walkedWant = /* @__PURE__ */ Effect.fnUntraced(function* (given) {
371
377
  });
372
378
  let held = 0;
373
379
  for (const object of read.objects.values()) held += object.bytes.byteLength;
374
- yield* Effect.ensuring(Effect.forEach(read.objects.values(), (object) => Effect.map(stepsOfBytes(object, object.bytes, readsTrees), follow), { discard: true }), Effect.sync(() => allotment.shrink(held)));
380
+ yield* Effect.ensuring(Effect.forEach(read.objects.values(), (object) => Effect.map(stepsOfBytes(object, object.bytes, readsTrees, roots), follow), { discard: true }), Effect.sync(() => allotment.shrink(held)));
375
381
  asked = [...read.left];
376
382
  }
377
383
  }
@@ -1,6 +1,7 @@
1
1
  import "../contracts/calls-spent.mjs";
2
2
  import "../contracts/objects.mjs";
3
3
  import * as Effect from "effect/Effect";
4
+ import * as HttpClient from "effect/http/HttpClient";
4
5
  import { CallLimits } from "@ref0/infra";
5
6
  import * as Context from "effect/Context";
6
7
  import * as Layer from "effect/Layer";
@@ -50,9 +51,10 @@ export interface CallBudgetOptions {
50
51
  }
51
52
  declare const CallBudget_base: Context.ServiceClass<CallBudget, "@ref0/git/CallBudget", CallAllowance>;
52
53
  /**
53
- * A limit on the store and bucket calls an Effect makes, below the platform's on its request.
54
- * Each call Git makes in its scope counts into it as it starts: a store call as a subrequest, and
55
- * a bucket call as a bucket call and a subrequest, as `CallLimits` counts them.
54
+ * A limit on the store and bucket calls an Effect makes, and its outbound HTTP requests, below the
55
+ * platform's on its request. Each call Git makes in its scope counts into it as it starts: a store
56
+ * call or a request through a `charged` client as a subrequest, and a bucket call as a bucket call
57
+ * and a subrequest, as `CallLimits` counts them.
56
58
  *
57
59
  * A budget lives as long as the Layer that built it: provide one around one call or one step,
58
60
  * never in a runtime's Layer, where every request would share it until the runtime ends. Each
@@ -74,6 +76,26 @@ export declare class CallBudget extends /* @__PURE__ */ CallBudget_base {
74
76
  static readonly make: (limits: CallLimits.CallLimits['Service'], options?: CallBudgetOptions) => Effect.Effect<CallAllowance>;
75
77
  /** `make`'s budget, as a Layer: one new budget each time it's built. */
76
78
  static readonly layer: (limits: CallLimits.CallLimits['Service'], options?: CallBudgetOptions) => Layer.Layer<CallBudget>;
79
+ /**
80
+ * `http`, each request it sends charged first, as one subrequest, to the request and every
81
+ * budget in scope when it's sent: one that would pass a bound is refused before it's sent with
82
+ * the defect `CallsSpent`, as a store call is. A retry wrapped around the charged client is
83
+ * charged each try, as a platform counts each, so `http` is a host's client with no retry
84
+ * middleware of its own: one beneath the charge would send uncounted. A redirect the client
85
+ * follows itself, as `fetch` does by default, is charged once with the request it answers, up to
86
+ * the 20 hops `fetch` follows; one asked for with `redirect: 'manual'` and followed by its caller
87
+ * is charged each hop. With nothing in scope, as a host's own call outside a job, it charges
88
+ * nothing.
89
+ */
90
+ static readonly charged: (http: HttpClient.HttpClient) => HttpClient.HttpClient;
91
+ /**
92
+ * `effect`, run with `calls` store calls held back for what must follow it, such as the commit
93
+ * that records a send: charged before it starts, so a budget in scope that can't cover them and
94
+ * `effect`'s own calls refuses before `effect`'s first call goes, with the defect `CallsSpent`,
95
+ * as a store call is, and given back once it ends, for the calls they were held for. With
96
+ * nothing in scope, it holds nothing.
97
+ */
98
+ static readonly withReserved: (calls: number) => <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
77
99
  /**
78
100
  * Whether the budget in scope, or one it nests in, has spent a kind of call it limits, so the
79
101
  * next call of that kind is refused: a host's call answers `RESOURCE_EXHAUSTED`,
@@ -94,6 +116,12 @@ export interface CallScope {
94
116
  readonly hold?: RequestHold | undefined;
95
117
  /** Whether it runs after its request's deciding commit, as `afterCommit` marks it. */
96
118
  readonly afterCommit?: boolean;
119
+ /**
120
+ * The loggers and least level where the call began, the host's on `Git.layer`'s runtime: a
121
+ * run across a Promise starts with Effect's defaults, so a line it logs, such as an unreadable
122
+ * index's, would reach the console and not the host's Logger.
123
+ */
124
+ readonly logging?: Context.Context<never> | undefined;
97
125
  }
98
126
  /**
99
127
  * What one call or one HTTP request keeps until it ends, which `withAudienceMemo` opens around
@@ -1,9 +1,11 @@
1
1
  import { CallsSpent } from "../contracts/calls-spent.mjs";
2
2
  import * as Effect from "effect/Effect";
3
+ import * as HttpClient from "effect/http/HttpClient";
3
4
  import * as Option from "effect/Option";
4
5
  import * as Predicate from "effect/Predicate";
5
6
  import * as Context from "effect/Context";
6
7
  import * as Layer from "effect/Layer";
8
+ import * as References from "effect/References";
7
9
  // src/store/call-count.ts
8
10
  /**
9
11
  * The store calls a Git fetch's request makes before its count starts, which its `callLimits`
@@ -12,7 +14,7 @@ import * as Layer from "effect/Layer";
12
14
  * refs, its haves and its tags' peels with its pack's (#709). Measured locally, not at a colo, by
13
15
  * negotiation-calls.test.ts: a token's request refused at its bound made 1 call more than it
14
16
  * counted. The host's own `auth` and grants aren't Git's calls: a host whose run subrequests sets
15
- * `callLimits` lower by them. Its `resolve` and fetch rules are `hookCallsBefore`'s.
17
+ * `callLimits` lower by them. Its fetch rules are `hookCallsBefore`'s.
16
18
  */
17
19
  const requestCallsBefore = {
18
20
  bucket: 0,
@@ -20,8 +22,8 @@ const requestCallsBefore = {
20
22
  };
21
23
  /**
22
24
  * The calls one of the host's hooks makes before a Git request's count starts, beside
23
- * `requestCallsBefore`'s: `resolve`, on any, and the fetch rules, on a fetch. B1a's K read measured
24
- * it on Workers, 2 calls before the count with either hook against 1 with neither. A hook that
25
+ * `requestCallsBefore`'s: the fetch rules, on a fetch. B1a's K read measured it on Workers, 2
26
+ * calls before the count with a hook against 1 with none. A hook that
25
27
  * makes more sets `callLimits` lower by them.
26
28
  */
27
29
  const hookCallsBefore = {
@@ -194,9 +196,10 @@ const lessBefore = (limits, before = requestCallsBefore) => {
194
196
  return lessened;
195
197
  };
196
198
  /**
197
- * A limit on the store and bucket calls an Effect makes, below the platform's on its request.
198
- * Each call Git makes in its scope counts into it as it starts: a store call as a subrequest, and
199
- * a bucket call as a bucket call and a subrequest, as `CallLimits` counts them.
199
+ * A limit on the store and bucket calls an Effect makes, and its outbound HTTP requests, below the
200
+ * platform's on its request. Each call Git makes in its scope counts into it as it starts: a store
201
+ * call or a request through a `charged` client as a subrequest, and a bucket call as a bucket call
202
+ * and a subrequest, as `CallLimits` counts them.
200
203
  *
201
204
  * A budget lives as long as the Layer that built it: provide one around one call or one step,
202
205
  * never in a runtime's Layer, where every request would share it until the runtime ends. Each
@@ -222,6 +225,26 @@ var CallBudget = class CallBudget extends (/* @__PURE__ */ Context.Service()("@r
222
225
  /** `make`'s budget, as a Layer: one new budget each time it's built. */
223
226
  static layer = (limits, options = {}) => Layer.effect(CallBudget, CallBudget.make(limits, options));
224
227
  /**
228
+ * `http`, each request it sends charged first, as one subrequest, to the request and every
229
+ * budget in scope when it's sent: one that would pass a bound is refused before it's sent with
230
+ * the defect `CallsSpent`, as a store call is. A retry wrapped around the charged client is
231
+ * charged each try, as a platform counts each, so `http` is a host's client with no retry
232
+ * middleware of its own: one beneath the charge would send uncounted. A redirect the client
233
+ * follows itself, as `fetch` does by default, is charged once with the request it answers, up to
234
+ * the 20 hops `fetch` follows; one asked for with `redirect: 'manual'` and followed by its caller
235
+ * is charged each hop. With nothing in scope, as a host's own call outside a job, it charges
236
+ * nothing.
237
+ */
238
+ static charged = (http) => HttpClient.transform(http, (effect) => Effect.andThen(chargeCall("fetch"), effect));
239
+ /**
240
+ * `effect`, run with `calls` store calls held back for what must follow it, such as the commit
241
+ * that records a send: charged before it starts, so a budget in scope that can't cover them and
242
+ * `effect`'s own calls refuses before `effect`'s first call goes, with the defect `CallsSpent`,
243
+ * as a store call is, and given back once it ends, for the calls they were held for. With
244
+ * nothing in scope, it holds nothing.
245
+ */
246
+ static withReserved = (calls) => (effect) => Effect.flatMap(heldCall("store", calls), (given) => Effect.ensuring(effect, given));
247
+ /**
225
248
  * Whether the budget in scope, or one it nests in, has spent a kind of call it limits, so the
226
249
  * next call of that kind is refused: a host's call answers `RESOURCE_EXHAUSTED`,
227
250
  * `reason: 'call-budget'`.
@@ -323,21 +346,28 @@ const noScope = {
323
346
  calls: void 0,
324
347
  budget: void 0
325
348
  };
326
- /** The call scope in context: its parts `undefined` with neither a request's count nor a budget. */
349
+ /**
350
+ * The call scope in context: its parts `undefined` with neither a request's count nor a budget,
351
+ * and the runtime's loggers, so a run across a Promise logs where the call began.
352
+ */
327
353
  const callScope = Effect.map(Effect.all([
328
354
  requestCount,
329
355
  Effect.serviceOption(CallBudget),
330
356
  Effect.serviceOption(RequestHolding),
331
- AfterCommit
332
- ]), ([calls, budget, hold, after]) => calls === void 0 && Option.isNone(budget) && Option.isNone(hold) && !after ? noScope : {
357
+ AfterCommit,
358
+ References.CurrentLoggers,
359
+ References.MinimumLogLevel
360
+ ]), ([calls, budget, hold, after, loggers, minimum]) => ({
333
361
  calls,
334
362
  budget: Option.getOrUndefined(budget),
335
363
  hold: Option.getOrUndefined(hold),
336
- afterCommit: after
337
- });
364
+ afterCommit: after,
365
+ logging: Context.make(References.CurrentLoggers, loggers).pipe(Context.add(References.MinimumLogLevel, minimum))
366
+ }));
338
367
  /**
339
368
  * `effect`, run in `scope` and no other: with the request's count, the budget, the hold and
340
- * the `afterCommit` mark it holds, and with none it doesn't hold, whatever the context had. So a reader or a walk opened with no
369
+ * the `afterCommit` mark it holds, and with none it doesn't hold, whatever the context had, and
370
+ * with the loggers it carries, when it carries them. So a reader or a walk opened with no
341
371
  * budget never takes one provided around a later call, and a run handed no scope counts nothing.
342
372
  */
343
373
  const inCallScope = (effect, scope) => Effect.updateContext(effect, scopedContext(scope));
@@ -346,7 +376,8 @@ const scopedContext = (scope) => (context) => {
346
376
  const counted = scope.calls === void 0 ? Context.omit(RequestCount)(context) : Context.add(context, RequestCount, scope.calls);
347
377
  const budgeted = scope.budget === void 0 ? Context.omit(CallBudget)(counted) : Context.add(counted, CallBudget, scope.budget);
348
378
  const held = scope.hold === void 0 ? Context.omit(RequestHolding)(budgeted) : Context.add(budgeted, RequestHolding, scope.hold);
349
- return Context.add(held, AfterCommit, scope.afterCommit === true);
379
+ const marked = Context.add(held, AfterCommit, scope.afterCommit === true);
380
+ return scope.logging === void 0 ? marked : Context.merge(marked, scope.logging);
350
381
  };
351
382
  /**
352
383
  * One call of `kind`, counted into the request in scope and every `CallBudget` in scope, or
@@ -379,19 +410,19 @@ const chargeCalls = (kind, calls) => Effect.flatMap(Effect.all([
379
410
  return Effect.void;
380
411
  });
381
412
  /**
382
- * One call of `kind` held back for a call to come, charged now as `chargeCall` charges it, so
383
- * the calls before it stop one short: what it gives is that call given back, once, to the counts
384
- * it was charged to, right before the call it was held for (#647).
413
+ * `calls` calls of `kind` held back for calls to come, charged now as `chargeCalls` charges them,
414
+ * so the calls before them stop that many short: what it gives is those calls given back, once, to
415
+ * the counts they were charged to, right before the calls they were held for (#647).
385
416
  */
386
- const heldCall = (kind) => Effect.flatMap(Effect.all([requestCount, inScope]), ([request, budget]) => {
417
+ const heldCall = (kind, calls = 1) => Effect.flatMap(Effect.all([requestCount, inScope]), ([request, budget]) => {
387
418
  let held = true;
388
419
  const given = Effect.sync(() => {
389
420
  if (!held) return;
390
421
  held = false;
391
- if (request !== void 0) add(request, kind, -1);
392
- for (const made of countsOf(chainOf(budget))) add(made, kind, -1);
422
+ if (request !== void 0) add(request, kind, -calls);
423
+ for (const made of countsOf(chainOf(budget))) add(made, kind, -calls);
393
424
  });
394
- return Effect.as(chargeCall(kind), given);
425
+ return Effect.as(chargeCalls(kind, calls), given);
395
426
  });
396
427
  /** The budget that refused each `CallsSpent` a budget refused, which `spentBudget` reads. */
397
428
  const spentBudgets = /* @__PURE__ */ new WeakMap();
@@ -13,4 +13,10 @@ import "effect/Stream";
13
13
  export declare function storeCall<A>(run: () => Promise<A>): Effect.Effect<A, GitError>;
14
14
  export declare function storeCall<A, E, R>(run: Effect.Effect<A, E, R>, options?: {
15
15
  readonly resend?: boolean;
16
- }): Effect.Effect<A, GitError, R>;
16
+ }): Effect.Effect<A, GitError, R>;
17
+ /**
18
+ * The most store calls one try at a write makes through `storeCall`: its read, the commit it
19
+ * decides, and that commit sent again as often as a lost reply may send it. A caller that must
20
+ * keep room for a write, such as a step that records a send, holds this many for each try.
21
+ */
22
+ export declare const commitCallsMost: number;
@@ -136,6 +136,12 @@ const effectStoreCall = /* @__PURE__ */ Effect.fnUntraced(function* (run, resend
136
136
  yield* chargeResends(1);
137
137
  }
138
138
  });
139
+ /**
140
+ * The most store calls one try at a write makes through `storeCall`: its read, the commit it
141
+ * decides, and that commit sent again as often as a lost reply may send it. A caller that must
142
+ * keep room for a write, such as a step that records a send, holds this many for each try.
143
+ */
144
+ const commitCallsMost = 3;
139
145
  /** What a commit sent `commitResendsMost` times again, with no reply, throws: it may have landed. */
140
146
  var Unsettled = class extends Error {
141
147
  name = "Unsettled";
@@ -248,4 +254,4 @@ const endedEarly = (cause) => {
248
254
  cause
249
255
  });
250
256
  };
251
- export { Unsettled, afterWrites, answerSpent, bestEffort, brokenRead, clientWentAway, decodeDerivedRow, decodeRow, endedEarly, fetchLess, fromInfra, isLimitRefusal, pastCallLimit, readBody, resending, resultCall, routeEdge, storeCall, storeWatch, thrownError };
257
+ export { Unsettled, afterWrites, answerSpent, bestEffort, brokenRead, clientWentAway, commitCallsMost, decodeDerivedRow, decodeRow, endedEarly, fetchLess, fromInfra, isLimitRefusal, pastCallLimit, readBody, resending, resultCall, routeEdge, storeCall, storeWatch, thrownError };
@@ -118,6 +118,8 @@ const gitJob = (job, handler, options = {}) => {
118
118
  remakes.set(definition, made);
119
119
  return definition;
120
120
  };
121
+ /** `job`, `handler` and `options` as `JobParts`. */
122
+ const jobParts = (job, handler, options) => (take) => take(job, handler, options);
121
123
  /**
122
124
  * `jobs`, each `gitJob` made remade in `limits`, a server's, and any other as it is: what a server
123
125
  * registers, so each try counts its calls against the adapter's bound.
@@ -127,4 +129,4 @@ const jobsWithin = (limits, jobs) => jobs.map((job) => remakes.get(job)?.(limits
127
129
  const currentRepo = Effect.map(CurrentJob.current, jobRepo);
128
130
  /** `step` over the try's store, fenced by its claim and gated by the server's door, and its repo. */
129
131
  const repoTry = (step) => Effect.flatMap(Effect.all([CurrentJob.store, currentRepo]), ([store, repo]) => step(store, repo));
130
- export { currentRepo, gitJob, jobLimitsOf, jobsWithin, repoTry, stepTooLarge };
132
+ export { currentRepo, gitJob, jobLimitsOf, jobParts, jobsWithin, repoTry, stepTooLarge };
@@ -1,4 +1,4 @@
1
- import { InternalRepoId, maxWriteKeyLength } from "../contracts/ids.mjs";
1
+ import { InternalRepoId, Oid, maxWriteKeyLength } from "../contracts/ids.mjs";
2
2
  import { fail } from "../contracts/result.mjs";
3
3
  import { Pack } from "../contracts/store.mjs";
4
4
  import { utf8 } from "../protocol/bytes/text.mjs";
@@ -64,9 +64,6 @@ const KeptRepoInfo = /* @__PURE__ */ Schema.Struct({
64
64
  packs: Schema.optionalKey(Schema.Int),
65
65
  packBytes: Schema.optionalKey(Schema.Int),
66
66
  ownBytes: Schema.optionalKey(Schema.Int),
67
- looseObjects: Schema.optionalKey(Schema.Int),
68
- looseBytes: Schema.optionalKey(Schema.Int),
69
- leavingBytes: Schema.optionalKey(Schema.Int),
70
67
  pushedAt: Schema.optionalKey(Schema.Int),
71
68
  maintainedAt: Schema.optionalKey(Schema.Int)
72
69
  }),
@@ -170,6 +167,21 @@ const StoredRepo = /* @__PURE__ */ Schema.Struct({
170
167
  refIndexBuilding: Schema.optionalKey(RefIndexBuilding)
171
168
  });
172
169
  /**
170
+ * The most roots a repo keeps in its `repo/roots` row, 10,000: an import's last segment's boundary
171
+ * is what becomes the repo's roots when it lands, the row's only writer, so `receiveBoundaryMost`
172
+ * is this bound too. At 43 B an ID as JSON, its quotes and comma with it, the row is at most 430 KB.
173
+ */
174
+ const repoRootsMost = 1e4;
175
+ /** A root's ID as the row keeps it: 40 lowercase hex digits. */
176
+ const RootId = Oid.check(Schema.isPattern(/^[0-9a-f]{40}$/));
177
+ /**
178
+ * A repo's roots, `repo/roots` in its scope: the commits it holds without their parents, as Git's
179
+ * `shallow` file names them, at most `repoRootsMost`, which their only writer, an import's landing,
180
+ * holds them to. Every walk sees a root as having no parents (`RepoRoots`). A row of any other ID,
181
+ * or past the bound, doesn't decode, so its read is `DATA_LOSS`.
182
+ */
183
+ const RepoRootsRow = /* @__PURE__ */ Schema.Struct({ roots: Schema.Array(RootId).check(Schema.isMaxLength(repoRootsMost)) });
184
+ /**
173
185
  * A rename's record once it lost its new name to a repo made there first: the name it left, which
174
186
  * its entry still holds, since a rename leaves its old name only when it wins the new one, at a
175
187
  * revision past the tombstone a win would have left there, with the rename's receipt and its index row deleted.
@@ -243,6 +255,15 @@ const importJobName = "sync.import";
243
255
  */
244
256
  const StatsTime = /* @__PURE__ */ Schema.Struct({ at: Schema.Int });
245
257
  /**
258
+ * The repo's object rows, as `ObjectsChange.rows` counts them, in `stats`: how many it holds and
259
+ * their values' bytes, which `RepoStats.ownBytes` counts. Only the commits that move them write
260
+ * it, each at the version it read it at, so it's exact at every version (#2237).
261
+ */
262
+ const LooseTally = /* @__PURE__ */ Schema.Struct({
263
+ objects: Schema.Int,
264
+ bytes: Schema.Int
265
+ });
266
+ /**
246
267
  * A pack's row in `packs`, by its ID: `Pack` without its `id`, which is the row's. So it holds how
247
268
  * many objects the pack holds, its bytes and its `.graph`'s; and `holds`, the packs it holds
248
269
  * whole, on a pack a merge that kept every object wrote.
@@ -250,4 +271,4 @@ const StatsTime = /* @__PURE__ */ Schema.Struct({ at: Schema.Int });
250
271
  const PackRow = Pack.mapFields(Struct.omit(["id"]));
251
272
  /** A row's ID by its sequence number, zero-padded so the rows read in order. */
252
273
  const versionId = (sequence) => String(sequence).padStart(16, "0");
253
- export { CatalogueEntry, CreatedRow, ForkOf, ForkRow, KeptRepoInfo, PackRow, PrunedMark, ReachedMark, RefIndexBuilding, RenamedFrom, StatsTime, StoredRepo, callerKey, checkWriteKey, importJobName, keptKey, keyDigest, keyKept, keyLive, markHolds, mirrorJobName, takenBack, versionId };
274
+ export { CatalogueEntry, CreatedRow, ForkOf, ForkRow, KeptRepoInfo, LooseTally, PackRow, PrunedMark, ReachedMark, RefIndexBuilding, RenamedFrom, RepoRootsRow, StatsTime, StoredRepo, callerKey, checkWriteKey, importJobName, keptKey, keyDigest, keyKept, keyLive, markHolds, mirrorJobName, repoRootsMost, takenBack, versionId };
@@ -1,9 +1,10 @@
1
+ import { noRepoRoots } from "../protocol/objects/commit.mjs";
1
2
  import { checkChurn, decodeRecord, entryOf, project } from "./catalogue.mjs";
2
3
  import { afterCommit } from "./call-count.mjs";
3
4
  import { afterWrites, decodeRow, storeCall } from "./errors.mjs";
4
5
  import { listJobRow } from "./list-job.mjs";
5
- import { StatsTime } from "./records.mjs";
6
- import { maintainedKey, newChangeId, pushedKey, repoScope, selfKey } from "./scopes.mjs";
6
+ import { LooseTally, RepoRootsRow, StatsTime } from "./records.mjs";
7
+ import { looseKey, maintainedKey, newChangeId, pushedKey, repoScope, selfKey } from "./scopes.mjs";
7
8
  import * as Effect from "effect/Effect";
8
9
  // src/store/repo-record.ts
9
10
  /** A repo's record and its scope's rows, read at one version: `results[0]` is `self`. */
@@ -15,6 +16,12 @@ const readRecord = /* @__PURE__ */ Effect.fnUntraced(function* (store, internalI
15
16
  snapshot
16
17
  };
17
18
  });
19
+ /** The roots a read of `repoRootsKey` gave, `rows`: none when the repo has no row. */
20
+ const rootsOf = (rows) => {
21
+ const [row] = rows ?? [];
22
+ if (row === void 0) return Effect.succeed(noRepoRoots);
23
+ return Effect.map(decodeRow(RepoRootsRow, row, "The repo's roots"), ({ roots }) => new Set(roots));
24
+ };
18
25
  /**
19
26
  * The first of a repo write's two commits: its record, in its own scope, with `git.list` saved
20
27
  * beside it, so the catalogue's projection happens even if the second never does.
@@ -50,11 +57,15 @@ const writeRecord = /* @__PURE__ */ Effect.fnUntraced(function* (store, internal
50
57
  outcome
51
58
  };
52
59
  });
53
- /** The times in a repo's `stats` rows, as `statsRead` reads them. */
54
- const decodeTimes = /* @__PURE__ */ Effect.fnUntraced(function* (rows) {
60
+ /** A repo's `stats` rows, as `statsRead` reads them. */
61
+ const decodeStats = /* @__PURE__ */ Effect.fnUntraced(function* (rows) {
55
62
  const times = {};
56
63
  const privately = /* @__PURE__ */ new Map();
57
64
  for (const row of rows) {
65
+ if (row.id === looseKey.id) {
66
+ times.loose = yield* decodeRow(LooseTally, row, "The repo's object rows' tally");
67
+ continue;
68
+ }
58
69
  const { at } = yield* decodeRow(StatsTime, row, `The repo's '${row.id}' time`);
59
70
  if (row.id === pushedKey.id) times.pushed = at;
60
71
  else if (row.id === maintainedKey.id) times.maintained = at;
@@ -82,21 +93,34 @@ const timeRow = (key, held, now) => ({
82
93
  ...key,
83
94
  value: { at: Math.max(held ?? now, now) }
84
95
  });
85
- /** A repo's stats, from its record, its refs' count, its listed packs and its `stats` times. */
86
- const repoStats = (record, refs, packs, times) => {
87
- const packBytes = packs.reduce((sum, pack) => sum + pack.bytes, 0);
96
+ /**
97
+ * The `stats` row of a commit that moves the repo's object rows by `moved`, from `held`, the tally
98
+ * its read found: none for a commit that moves none, so a repo whose storage keeps no rows writes
99
+ * no tally.
100
+ */
101
+ const looseRows = (held, moved) => moved.objects === 0 && moved.bytes === 0 ? [] : [{
102
+ ...looseKey,
103
+ value: {
104
+ objects: (held?.objects ?? 0) + moved.objects,
105
+ bytes: (held?.bytes ?? 0) + moved.bytes
106
+ }
107
+ }];
108
+ /**
109
+ * A repo's stats, from its record, its refs' count, its listed packs, its `stats` rows and the
110
+ * bytes of the pack kept ready for a shallow clone, which no list names. Its object rows count in
111
+ * `ownBytes` alone, as `RepoStats` says.
112
+ */
113
+ const repoStats = (record, refs, packs, times, readyBytes) => {
114
+ const packBytes = packs.reduce((sum, pack) => sum + pack.bytes, readyBytes);
88
115
  const stats = {
89
116
  repo: record.name,
90
117
  refs,
91
118
  packs: packs.length,
92
119
  packBytes,
93
- ownBytes: packBytes,
94
- looseObjects: 0,
95
- looseBytes: 0,
96
- leavingBytes: 0
120
+ ownBytes: packBytes + (times.loose?.bytes ?? 0)
97
121
  };
98
122
  if (times.pushed !== void 0) stats.pushedAt = times.pushed;
99
123
  if (times.maintained !== void 0) stats.maintainedAt = times.maintained;
100
124
  return stats;
101
125
  };
102
- export { commitRecord, decodeTimes, readRecord, repoStats, seenTimes, timeRow, writeRecord };
126
+ export { commitRecord, decodeStats, looseRows, readRecord, repoStats, rootsOf, seenTimes, timeRow, writeRecord };
@@ -43,7 +43,7 @@ const collections = {
43
43
  publicCreated: "public-created",
44
44
  /** In `git/repos`: the server's own keys, by use: `cursor`, which seals every list's cursor. */
45
45
  keys: "keys",
46
- /** In a repo's scope: its own record, `self`. */
46
+ /** In a repo's scope: its own record, `self`, and its roots, `roots`. */
47
47
  repo: "repo",
48
48
  /** In a repo's scope: each ref's `RefRow`, by its full name. */
49
49
  refs: "refs",
@@ -123,6 +123,14 @@ const selfKey = {
123
123
  id: "self"
124
124
  };
125
125
  /**
126
+ * A repo's roots, its `RepoRootsRow`, read with every open whose reads walk parents. Only an
127
+ * import's landing writes it, before its first ref page publishes; a repo with no row has none.
128
+ */
129
+ const repoRootsKey = {
130
+ collection: collections.repo,
131
+ id: "roots"
132
+ };
133
+ /**
126
134
  * The repo's prune mark: a new ID each time a prune drops objects. A push reads it first and
127
135
  * again at its commit, and fails if it moved, so no ref names an object a prune dropped (Q270).
128
136
  */
@@ -156,6 +164,11 @@ const maintainedKey = {
156
164
  collection: collections.stats,
157
165
  id: "maintained"
158
166
  };
167
+ /** The repo's `LooseTally`: its object rows, which `stats.ownBytes` counts. */
168
+ const looseKey = {
169
+ collection: collections.stats,
170
+ id: "loose"
171
+ };
159
172
  /** A new repo's internal ID: `r_` and 12 random bytes. */
160
173
  const newInternalId = () => `r_${randomText(12)}`;
161
174
  /** The repo a scope is, or `undefined` for a scope that's no repo's, such as a prefix's. */
@@ -171,4 +184,4 @@ const jobRepo = (job) => {
171
184
  };
172
185
  /** A commit's own ID, for a change no caller's key names. */
173
186
  const newChangeId = () => randomText(16);
174
- export { catalogueScope, collections, forkId, jobRepo, maintainedKey, newChangeId, newInternalId, prunedKey, pushedKey, pushedUnder, reachedKey, repoScope, scopeRepo, selfKey, topicScope, topicsScope };
187
+ export { catalogueScope, collections, forkId, jobRepo, looseKey, maintainedKey, newChangeId, newInternalId, prunedKey, pushedKey, pushedUnder, reachedKey, repoRootsKey, repoScope, scopeRepo, selfKey, topicScope, topicsScope };
@@ -3,5 +3,5 @@ import "../contracts/actors.mjs";
3
3
  import "../contracts/sync.mjs";
4
4
  import "../core/parts.mjs";
5
5
  import "effect/http/HttpClient";
6
- import { JobDefinition } from "@ref0/infra";
6
+ import { Job } from "@ref0/infra";
7
7
  import "effect/Context";