@ref0/git 0.8.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 (94) hide show
  1. package/dist/contracts/calls-spent.d.mts +2 -12
  2. package/dist/contracts/calls-spent.mjs +4 -5
  3. package/dist/contracts/events.d.mts +70 -4
  4. package/dist/contracts/events.mjs +27 -3
  5. package/dist/contracts/git.d.mts +13 -3
  6. package/dist/contracts/objects.d.mts +18 -0
  7. package/dist/contracts/queue.d.mts +3 -2
  8. package/dist/contracts/queue.mjs +4 -2
  9. package/dist/core/ancestry.mjs +5 -4
  10. package/dist/core/index-job.mjs +23 -1
  11. package/dist/core/index-lost.d.mts +11 -0
  12. package/dist/core/index-lost.mjs +55 -0
  13. package/dist/core/objects/commit-writes.mjs +1 -1
  14. package/dist/core/objects/commits.mjs +10 -9
  15. package/dist/core/objects/merges.mjs +1 -1
  16. package/dist/core/objects/reading.mjs +28 -13
  17. package/dist/core/objects/trees.mjs +1 -1
  18. package/dist/core/parts.d.mts +7 -0
  19. package/dist/core/publish.mjs +9 -5
  20. package/dist/core/purge.mjs +16 -3
  21. package/dist/core/push.mjs +27 -11
  22. package/dist/core/repack.mjs +36 -14
  23. package/dist/core/view.d.mts +10 -1
  24. package/dist/core/view.mjs +15 -6
  25. package/dist/effect.d.mts +2 -3
  26. package/dist/effect.mjs +2 -3
  27. package/dist/engine/commits.mjs +4 -3
  28. package/dist/engine/merge-bases.mjs +5 -3
  29. package/dist/engine/merge.mjs +4 -3
  30. package/dist/engine/parts.d.mts +1 -0
  31. package/dist/engine/parts.mjs +1 -1
  32. package/dist/engine/walk.mjs +15 -11
  33. package/dist/http/core-parts.mjs +17 -8
  34. package/dist/index.d.mts +2 -2
  35. package/dist/lfs/objects.mjs +7 -4
  36. package/dist/lfs/upkeep.mjs +6 -5
  37. package/dist/lfs/upload-most.mjs +7 -1
  38. package/dist/protocol/bytes/streams.mjs +84 -2
  39. package/dist/protocol/diff/read.d.mts +1 -0
  40. package/dist/protocol/diff/read.mjs +5 -2
  41. package/dist/protocol/objects/commit.d.mts +7 -0
  42. package/dist/protocol/objects/commit.mjs +5 -1
  43. package/dist/queue/advance.mjs +39 -10
  44. package/dist/queue/host.d.mts +4 -0
  45. package/dist/queue/layer.mjs +4 -2
  46. package/dist/queue/limits.mjs +18 -2
  47. package/dist/queue/rows.mjs +2 -1
  48. package/dist/queue/trim.mjs +2 -2
  49. package/dist/rest/commits.d.mts +238 -238
  50. package/dist/rest/forks.d.mts +71 -71
  51. package/dist/rest/refs.d.mts +143 -143
  52. package/dist/rest/repos.d.mts +81 -81
  53. package/dist/rest/topics.d.mts +112 -112
  54. package/dist/rest/trees.d.mts +77 -77
  55. package/dist/rest/wire.d.mts +19 -1
  56. package/dist/rest/work.d.mts +39 -39
  57. package/dist/server/joined.d.mts +11 -5
  58. package/dist/server/joined.mjs +3 -2
  59. package/dist/server/registry.mjs +11 -5
  60. package/dist/server/server.mjs +16 -4
  61. package/dist/storage/index-bitmaps.mjs +16 -10
  62. package/dist/storage/index-build.mjs +61 -13
  63. package/dist/storage/index-graph.d.mts +1 -0
  64. package/dist/storage/index-graph.mjs +29 -5
  65. package/dist/storage/index-layers.d.mts +1 -0
  66. package/dist/storage/index-layers.mjs +5 -2
  67. package/dist/storage/index-reach.mjs +7 -5
  68. package/dist/storage/index-remap.mjs +5 -5
  69. package/dist/storage/index-visible.mjs +16 -5
  70. package/dist/storage/links.mjs +3 -3
  71. package/dist/storage/pack-order.d.mts +1 -0
  72. package/dist/storage/pack-order.mjs +18 -1
  73. package/dist/storage/prune-walk.mjs +5 -2
  74. package/dist/storage/prune.mjs +107 -37
  75. package/dist/storage/receive-bounds.mjs +3 -2
  76. package/dist/storage/visible.mjs +3 -2
  77. package/dist/storage/walk.d.mts +1 -0
  78. package/dist/storage/walk.mjs +9 -5
  79. package/dist/storage/wants.mjs +17 -11
  80. package/dist/store/call-count.d.mts +8 -0
  81. package/dist/store/call-count.mjs +15 -7
  82. package/dist/store/errors.d.mts +7 -1
  83. package/dist/store/errors.mjs +7 -1
  84. package/dist/store/job-try.mjs +3 -1
  85. package/dist/store/records.mjs +17 -2
  86. package/dist/store/repo-record.mjs +9 -2
  87. package/dist/store/scopes.mjs +10 -2
  88. package/dist/sync/bound.d.mts +1 -1
  89. package/dist/sync/import.mjs +1 -1
  90. package/dist/sync/layer.mjs +4 -7
  91. package/dist/sync/mirror.mjs +1 -1
  92. package/dist/topics/advance.mjs +4 -4
  93. package/dist/topics/layer.mjs +1 -1
  94. package/package.json +3 -3
@@ -1,9 +1,10 @@
1
1
  import { fail } from "../contracts/result.mjs";
2
2
  import { hexOf } from "../protocol/bytes/hex.mjs";
3
+ import { rootsOf } from "../store/repo-record.mjs";
3
4
  import { decodeRow } from "../store/errors.mjs";
4
5
  import { WholeRepo, wholeRef } from "../store/ref-rows.mjs";
5
6
  import { ReachedMark, markHolds } from "../store/records.mjs";
6
- import { collections, reachedKey, repoScope } from "../store/scopes.mjs";
7
+ import { collections, reachedKey, repoRootsKey, repoScope } from "../store/scopes.mjs";
7
8
  import { bucketDeleteMany, readWhole } from "./calls.mjs";
8
9
  import { putOnce } from "./index-build.mjs";
9
10
  import { isPackId, objectCollections, runKey } from "./layout.mjs";
@@ -70,7 +71,8 @@ const PassClasses = /* @__PURE__ */ Schema.Struct({
70
71
  * scratch pack, till the pass's last step drops them. `classes` names the classes object its
71
72
  * merges read, and `redos` counts the rewrites it dropped as pushes moved its refs onto what they
72
73
  * were about to drop: the third waits for the next period, as `pruneStep` says, and that period's
73
- * walks start again with none (#1660).
74
+ * walks start again with none (#1660). `periods` counts the periods in a row the pass has waited
75
+ * so, which a wait for any other reason ends, as `ObjectsStep.busy` says (#2233).
74
76
  */
75
77
  const PruneStarted = /* @__PURE__ */ Schema.Struct({
76
78
  at: Schema.Int,
@@ -80,7 +82,8 @@ const PruneStarted = /* @__PURE__ */ Schema.Struct({
80
82
  n: Schema.optional(WalkCarry)
81
83
  })),
82
84
  classes: Schema.optional(PassClasses),
83
- redos: Schema.optional(Schema.Int)
85
+ redos: Schema.optional(Schema.Int),
86
+ periods: Schema.optional(Schema.Int)
84
87
  });
85
88
  const pruneStartedKey = {
86
89
  collection: objectCollections.prune,
@@ -202,13 +205,14 @@ const bitsOf = (bits, packs) => {
202
205
  * `start` with `known` reached already, as D2's walk carries it. A new walk, with neither, drops
203
206
  * what a pass that died left under `scratch` first. With `more`, where it stopped, for the mark.
204
207
  */
205
- const walkOn = /* @__PURE__ */ Effect.fnUntraced(function* (input, scratch, start, rows, missing, calls, saved, known) {
208
+ const walkOn = /* @__PURE__ */ Effect.fnUntraced(function* (input, scratch, start, rows, missing, calls, roots, saved, known) {
206
209
  if (saved === void 0 && known === void 0) yield* dropRuns(input.bucket, scratch);
207
210
  const walked = yield* pruneWalk(input, scratch, start, missing, {
208
211
  rows: rows.length,
209
212
  calls,
210
213
  saved,
211
- known
214
+ known,
215
+ roots
212
216
  });
213
217
  return "more" in walked ? { more: walked.more } : {
214
218
  runs: walked.reached,
@@ -233,14 +237,29 @@ const refsHeld = /* @__PURE__ */ Effect.fnUntraced(function* (input, scratch, wa
233
237
  }, upkeepRuns);
234
238
  return held;
235
239
  }, Effect.scoped);
236
- /** Every ref's object, once each. */
240
+ /** Each object `rows`, ref rows, name, once each. */
241
+ const refIdsIn = (rows) => Effect.map(Effect.forEach(rows ?? [], (row) => wholeRef(pruneWhole, row)), (refs) => [...new Set(refs)]);
242
+ /**
243
+ * Every ref's object, once each, and the repo's roots in the same read: a walk from the refs
244
+ * follows no root's parents, so what only they reach is no ref's.
245
+ */
237
246
  const refsOf = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
247
+ const snapshot = yield* input.store.read({
248
+ scope: repoScope(input.listed.repo),
249
+ reads: [{ collection: collections.refs }, repoRootsKey]
250
+ });
251
+ return {
252
+ refs: yield* refIdsIn(snapshot.results[0]),
253
+ roots: yield* rootsOf(snapshot.results[1])
254
+ };
255
+ });
256
+ /** Every ref's object, once each, with no roots: what a listing checks its bits were read at. */
257
+ const refIdsOf = /* @__PURE__ */ Effect.fnUntraced(function* (input) {
238
258
  const snapshot = yield* input.store.read({
239
259
  scope: repoScope(input.listed.repo),
240
260
  reads: [{ collection: collections.refs }]
241
261
  });
242
- const refs = yield* Effect.forEach(snapshot.results[0] ?? [], (row) => wholeRef(pruneWhole, row));
243
- return [...new Set(refs)];
262
+ return yield* refIdsIn(snapshot.results[0]);
244
263
  });
245
264
  /** The objects of `packs` and `rows` that `reached` leaves out: where the needed walk starts. */
246
265
  const unreachedOf = (packs, rows, reached) => [...new Set([...oidsOf(packs), ...rows.map((row) => row.oid)].filter((oid) => !reached.has(oid)))];
@@ -409,7 +428,7 @@ const cruftListing = (landed) => Effect.fnUntraced(function* (input, merge) {
409
428
  * merge waits at its commit pass, and the pass catches up first.
410
429
  */
411
430
  const keptListing = (read, seen, rows, landed) => Effect.fnUntraced(function* (input, merge) {
412
- if ((yield* readsDigest(yield* refsOf(input), rows)) !== seen.reads || !sameIds(seen.packs, classedIds(input, read))) return void 0;
431
+ if ((yield* readsDigest(yield* refIdsOf(input), rows)) !== seen.reads || !sameIds(seen.packs, classedIds(input, read))) return void 0;
413
432
  const removed = yield* takenOf(input, merge);
414
433
  const { packs, quarantines, first } = yield* writtenOf(merge);
415
434
  const dropped = removed.filter((pack) => read.cruft.has(pack.id));
@@ -528,9 +547,43 @@ const emptiedStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, read, em
528
547
  if (dropped.length > 0) step.drops = true;
529
548
  return step;
530
549
  });
531
- /** `started` with `patch` laid over it, its `waits` ended. */
550
+ /** A mark at `started`'s start, with its `periods`, if any: what each new mark of the pass keeps. */
551
+ const periodsOf = (started) => started.periods === void 0 ? { at: started.at } : {
552
+ at: started.at,
553
+ periods: started.periods
554
+ };
555
+ /**
556
+ * The pass's mark with its count of periods pushes held it ended, when an underway pass's mark
557
+ * has one: what a wait for anything but pushes puts, its walks and its wait kept (#2233).
558
+ */
559
+ const countEnded = (read) => {
560
+ const { started } = read;
561
+ const last = read.pass?.at;
562
+ if (started?.periods === void 0 || last !== void 0 && started.at <= last) return void 0;
563
+ const value = { ...started };
564
+ delete value.periods;
565
+ return {
566
+ ...pruneStartedKey,
567
+ value
568
+ };
569
+ };
570
+ /** `step`, or a step of its own when there's none, putting `row` too. */
571
+ const alsoPuts = (step, row) => {
572
+ const base = step ?? {
573
+ change: { rows: noRows },
574
+ more: true
575
+ };
576
+ return {
577
+ ...base,
578
+ change: {
579
+ ...base.change,
580
+ put: [...base.change.put ?? [], row]
581
+ }
582
+ };
583
+ };
584
+ /** `started` with `patch` laid over it, its `waits` ended and its `periods` kept. */
532
585
  const remarked = (started, patch) => {
533
- const value = { at: started.at };
586
+ const value = periodsOf(started);
534
587
  const walks = "walks" in patch ? patch.walks : started.walks;
535
588
  const classes = "classes" in patch ? patch.classes : started.classes;
536
589
  const redos = "redos" in patch ? patch.redos : started.redos;
@@ -569,12 +622,12 @@ const passSteps = /* @__PURE__ */ Effect.fnUntraced(function* (input, read, pack
569
622
  },
570
623
  mark: { walks }
571
624
  });
572
- const refs = yield* refsOf(input);
625
+ const { refs, roots } = yield* refsOf(input);
573
626
  const digest = yield* readsDigest(refs, rowOids);
574
627
  const ids = classedIds(input, read);
575
628
  const carry = carried.r;
576
629
  if (carry === void 0 || "saved" in carry) {
577
- const walked = yield* walkOn(input, scratch, refs, rows, lost, calls, carry?.saved);
630
+ const walked = yield* walkOn(input, scratch, refs, rows, lost, calls, roots, carry?.saved);
578
631
  return saving({ r: "more" in walked ? {
579
632
  saved: walked.more,
580
633
  refs: carry?.refs
@@ -627,7 +680,7 @@ const passSteps = /* @__PURE__ */ Effect.fnUntraced(function* (input, read, pack
627
680
  });
628
681
  const caught = yield* Effect.scoped(Effect.map(sides, ({ reached }) => refs.filter((oid) => !reached.has(oid))));
629
682
  if (caught.length > 0) {
630
- const walked = yield* walkOn(input, scratch, caught, rows, lost, calls, void 0, reachedRuns);
683
+ const walked = yield* walkOn(input, scratch, caught, rows, lost, calls, roots, void 0, reachedRuns);
631
684
  return saving({
632
685
  ...carried,
633
686
  r: "more" in walked ? {
@@ -681,7 +734,7 @@ const passSteps = /* @__PURE__ */ Effect.fnUntraced(function* (input, read, pack
681
734
  const neededCarry = carried.n;
682
735
  if (packs.old.length > 0 && (neededCarry === void 0 || "saved" in neededCarry)) {
683
736
  const start = neededCarry === void 0 ? first.start : [];
684
- const walked = yield* walkOn(input, named, start, rows, () => void 0, calls, neededCarry?.saved, neededCarry === void 0 ? reachedRuns : void 0);
737
+ const walked = yield* walkOn(input, named, start, rows, () => void 0, calls, roots, neededCarry?.saved, neededCarry === void 0 ? reachedRuns : void 0);
685
738
  return saving({
686
739
  ...carried,
687
740
  n: "more" in walked ? { saved: walked.more } : { done: walked.runs }
@@ -694,7 +747,7 @@ const passSteps = /* @__PURE__ */ Effect.fnUntraced(function* (input, read, pack
694
747
  return first.start.filter((oid) => !needed.has(oid));
695
748
  }));
696
749
  if (neededDone !== void 0 && behind.length > 0) {
697
- const walked = yield* walkOn(input, named, behind, rows, () => void 0, calls, void 0, neededDone);
750
+ const walked = yield* walkOn(input, named, behind, rows, () => void 0, calls, roots, void 0, neededDone);
698
751
  return saving({
699
752
  ...carried,
700
753
  n: "more" in walked ? { saved: walked.more } : { done: walked.runs }
@@ -724,7 +777,10 @@ const passSteps = /* @__PURE__ */ Effect.fnUntraced(function* (input, read, pack
724
777
  }, rowOids, landed);
725
778
  return went(yield* resumeMerge(input, merge, most, calls, listing), "kept");
726
779
  }
727
- if (redos + 1 >= 3) return { waits: `pushes moved its refs onto what its rewrite was about to drop, 3 times in a row` };
780
+ if (redos + 1 >= 3) return {
781
+ waits: `pushes moved its refs onto what its rewrite was about to drop, 3 times in a row`,
782
+ busy: true
783
+ };
728
784
  return {
729
785
  step: droppedStep(merge),
730
786
  mark: {
@@ -831,8 +887,9 @@ const passDue = (input, prune, read, objectRows) => {
831
887
  * that died or failed, waits for the next period, as does one whose walk is past what one walk
832
888
  * holds or makes no step, and one whose rewrite pushes caught up with `redosMost` times: each
833
889
  * writes the wait to its mark and drops its merge under way, with a log line. A pass that waits
834
- * before its walk logs too, and writes nothing. `step` is `undefined` when no pass is due; `next`
835
- * is when the next one is, and `undefined` for a repo that holds no object.
890
+ * before its walk logs too, and writes nothing but its mark's end of a count of periods pushes
891
+ * held it, as every wait for anything but pushes does. `step` is `undefined` when no pass is
892
+ * due; `next` is when the next one is, and `undefined` for a repo that holds no object.
836
893
  */
837
894
  const pruneStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, prune, repack, read, objectRows, drops, holds, retried = false, calls) {
838
895
  const due = passDue(input, prune, read, objectRows);
@@ -848,11 +905,13 @@ const pruneStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, prune, rep
848
905
  const last = read.pass?.at;
849
906
  const markHeld = markHolds(read.mark);
850
907
  const merge = read.merges.prune;
908
+ const uncounted = countEnded(read);
909
+ const waitsElse = (step) => uncounted === void 0 ? step : alsoPuts(step, uncounted);
851
910
  if (holds.length > 0) {
852
911
  const after = input.at + pruneFloor;
853
912
  yield* Effect.logWarning(`git.repack's prune pass of repo ${input.listed.repo}, due ${iso(next)}, waits until ${iso(after)}: held by ${holds.join(", ")}, as an import's segments are reached by no ref till it publishes`);
854
913
  return {
855
- step: merge === void 0 ? void 0 : droppedStep(merge),
914
+ step: waitsElse(merge === void 0 ? void 0 : droppedStep(merge)),
856
915
  next: after
857
916
  };
858
917
  }
@@ -880,7 +939,7 @@ const pruneStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, prune, rep
880
939
  const most = (repack === false ? void 0 : repack.maxPackSize) ?? defaultRepack.maxPackSize;
881
940
  const until = input.at + pruneWait(prune);
882
941
  const later = (why) => Effect.as(Effect.logWarning(`git.repack's prune pass of repo ${input.listed.repo}, due ${iso(next)}, waits until ${iso(until)}: ${why}`), {
883
- step: void 0,
942
+ step: waitsElse(void 0),
884
943
  next: until
885
944
  });
886
945
  const { rows } = objectRows;
@@ -910,23 +969,34 @@ const pruneStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, prune, rep
910
969
  step: void 0,
911
970
  next: started.waits
912
971
  };
913
- const waits = (why) => {
972
+ const waits = (why, busy = false) => {
973
+ const periods = (started.periods ?? 0) + 1;
974
+ const value = busy ? {
975
+ at: started.at,
976
+ waits: until,
977
+ periods
978
+ } : {
979
+ at: started.at,
980
+ waits: until
981
+ };
914
982
  const mark = {
915
983
  ...pruneStartedKey,
916
- value: {
917
- at: started.at,
918
- waits: until
919
- }
984
+ value
920
985
  };
921
- const step = {
922
- change: merge === void 0 ? {
923
- put: [mark],
924
- rows: noRows
925
- } : {
926
- put: [mark],
927
- delete: [mergeKey(merge.pack)],
928
- rows: noRows
929
- },
986
+ const change = merge === void 0 ? {
987
+ put: [mark],
988
+ rows: noRows
989
+ } : {
990
+ put: [mark],
991
+ delete: [mergeKey(merge.pack)],
992
+ rows: noRows
993
+ };
994
+ const step = busy ? {
995
+ change,
996
+ more: true,
997
+ busy: periods
998
+ } : {
999
+ change,
930
1000
  more: true
931
1001
  };
932
1002
  return Effect.as(later(why), {
@@ -936,7 +1006,7 @@ const pruneStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, prune, rep
936
1006
  };
937
1007
  if (retried) return yield* waits("its last try died or failed with the pass under way");
938
1008
  const stepped = yield* passSteps(input, read, packs, rows, most, calls).pipe(Effect.catchTag("PruneWalkTooLarge", (refused) => fail("RESOURCE_EXHAUSTED", `The prune pass is past what one walk holds: ${refused.message}`, { context: { reason: "prune-walk-too-large" } })));
939
- if ("waits" in stepped) return yield* waits(stepped.waits);
1009
+ if ("waits" in stepped) return yield* waits(stepped.waits, "busy" in stepped);
940
1010
  const { change } = stepped.step;
941
1011
  const patch = "mark" in stepped ? stepped.mark : void 0;
942
1012
  const step = patch === void 0 ? stepped.step : {
@@ -953,7 +1023,7 @@ const pruneStep = /* @__PURE__ */ Effect.fnUntraced(function* (input, prune, rep
953
1023
  const rewalk = {
954
1024
  put: [{
955
1025
  ...pruneStartedKey,
956
- value: { at: started.at }
1026
+ value: periodsOf(started)
957
1027
  }],
958
1028
  rows: noRows
959
1029
  };
@@ -1,4 +1,5 @@
1
1
  import { millis } from "../contracts/promises.mjs";
2
+ import { repoRootsMost } from "../store/records.mjs";
2
3
  import { graphBytes } from "../protocol/packs/graph.mjs";
3
4
  import { packIndexBytes } from "../protocol/packs/idx.mjs";
4
5
  import { packPositionsBytes } from "../protocol/packs/pos.mjs";
@@ -66,9 +67,9 @@ const receiveTableMost = /* @__PURE__ */ Math.floor((2 ** 22 - 1) * 3 / 4);
66
67
  * The most boundary commits an import segment's receive takes, 10,000, as `readyShallowsMost`
67
68
  * bounds a shallow pack's: each is held as an ID in a set, with its parents the pack leaves out.
68
69
  * Past it the receive is refused `too-large` before its pack is read, and the import halves its
69
- * step.
70
+ * step. It's `repoRootsMost`, since a last segment's boundary becomes the repo's roots.
70
71
  */
71
- const receiveBoundaryMost = 1e4;
72
+ const receiveBoundaryMost = repoRootsMost;
72
73
  /**
73
74
  * The most parents of its boundary commits an import holds at once, 20,000, two for each of
74
75
  * `receiveBoundaryMost`, as a frontier of merges needs: halving a step doesn't narrow a frontier.
@@ -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
  }
@@ -88,6 +88,14 @@ export declare class CallBudget extends /* @__PURE__ */ CallBudget_base {
88
88
  * nothing.
89
89
  */
90
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>;
91
99
  /**
92
100
  * Whether the budget in scope, or one it nests in, has spent a kind of call it limits, so the
93
101
  * next call of that kind is refused: a host's call answers `RESOURCE_EXHAUSTED`,
@@ -237,6 +237,14 @@ var CallBudget = class CallBudget extends (/* @__PURE__ */ Context.Service()("@r
237
237
  */
238
238
  static charged = (http) => HttpClient.transform(http, (effect) => Effect.andThen(chargeCall("fetch"), effect));
239
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
+ /**
240
248
  * Whether the budget in scope, or one it nests in, has spent a kind of call it limits, so the
241
249
  * next call of that kind is refused: a host's call answers `RESOURCE_EXHAUSTED`,
242
250
  * `reason: 'call-budget'`.
@@ -402,19 +410,19 @@ const chargeCalls = (kind, calls) => Effect.flatMap(Effect.all([
402
410
  return Effect.void;
403
411
  });
404
412
  /**
405
- * One call of `kind` held back for a call to come, charged now as `chargeCall` charges it, so
406
- * the calls before it stop one short: what it gives is that call given back, once, to the counts
407
- * 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).
408
416
  */
409
- 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]) => {
410
418
  let held = true;
411
419
  const given = Effect.sync(() => {
412
420
  if (!held) return;
413
421
  held = false;
414
- if (request !== void 0) add(request, kind, -1);
415
- 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);
416
424
  });
417
- return Effect.as(chargeCall(kind), given);
425
+ return Effect.as(chargeCalls(kind, calls), given);
418
426
  });
419
427
  /** The budget that refused each `CallsSpent` a budget refused, which `spentBudget` reads. */
420
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";
@@ -167,6 +167,21 @@ const StoredRepo = /* @__PURE__ */ Schema.Struct({
167
167
  refIndexBuilding: Schema.optionalKey(RefIndexBuilding)
168
168
  });
169
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
+ /**
170
185
  * A rename's record once it lost its new name to a repo made there first: the name it left, which
171
186
  * its entry still holds, since a rename leaves its old name only when it wins the new one, at a
172
187
  * revision past the tombstone a win would have left there, with the rename's receipt and its index row deleted.
@@ -256,4 +271,4 @@ const LooseTally = /* @__PURE__ */ Schema.Struct({
256
271
  const PackRow = Pack.mapFields(Struct.omit(["id"]));
257
272
  /** A row's ID by its sequence number, zero-padded so the rows read in order. */
258
273
  const versionId = (sequence) => String(sequence).padStart(16, "0");
259
- export { CatalogueEntry, CreatedRow, ForkOf, ForkRow, KeptRepoInfo, LooseTally, 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,8 +1,9 @@
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 { LooseTally, StatsTime } from "./records.mjs";
6
+ import { LooseTally, RepoRootsRow, StatsTime } from "./records.mjs";
6
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
@@ -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.
@@ -116,4 +123,4 @@ const repoStats = (record, refs, packs, times, readyBytes) => {
116
123
  if (times.maintained !== void 0) stats.maintainedAt = times.maintained;
117
124
  return stats;
118
125
  };
119
- export { commitRecord, decodeStats, looseRows, readRecord, repoStats, seenTimes, timeRow, writeRecord };
126
+ export { commitRecord, decodeStats, looseRows, readRecord, repoStats, rootsOf, seenTimes, timeRow, writeRecord };