@ref0/git 0.0.0 → 0.3.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.
- package/dist/LICENSE +202 -0
- package/dist/access/private-refs.d.mts +27 -0
- package/dist/access/private-refs.mjs +173 -0
- package/dist/access.d.mts +2 -0
- package/dist/access.mjs +1 -0
- package/dist/auth/access-jwt.d.mts +21 -0
- package/dist/auth/access-jwt.mjs +102 -0
- package/dist/auth/acting.mjs +15 -0
- package/dist/auth/authorize.d.mts +5 -0
- package/dist/auth/authorize.mjs +292 -0
- package/dist/auth/credentials.mjs +57 -0
- package/dist/auth/fences.d.mts +5 -0
- package/dist/auth/fences.mjs +65 -0
- package/dist/auth/grants.mjs +61 -0
- package/dist/auth/helpers.d.mts +17 -0
- package/dist/auth/helpers.mjs +25 -0
- package/dist/auth/host-function.d.mts +4 -0
- package/dist/auth/host-function.mjs +69 -0
- package/dist/auth/identify.d.mts +6 -0
- package/dist/auth/identify.mjs +97 -0
- package/dist/auth/token-rows.mjs +100 -0
- package/dist/auth/token-text.mjs +66 -0
- package/dist/auth/tokens.d.mts +10 -0
- package/dist/auth/tokens.mjs +347 -0
- package/dist/auth.d.mts +7 -0
- package/dist/auth.mjs +6 -0
- package/dist/client/answer.mjs +141 -0
- package/dist/client/client.d.mts +23 -0
- package/dist/client/client.mjs +50 -0
- package/dist/client/git-http.mjs +201 -0
- package/dist/client/helper-node.mjs +19 -0
- package/dist/client/local.mjs +170 -0
- package/dist/client/negotiate.mjs +170 -0
- package/dist/client/push-upload.mjs +53 -0
- package/dist/client/remote-helper.mjs +129 -0
- package/dist/client/remote.mjs +398 -0
- package/dist/client/run-remote-helper.d.mts +35 -0
- package/dist/client/run-remote-helper.mjs +259 -0
- package/dist/client/scrub.d.mts +18 -0
- package/dist/client/scrub.mjs +38 -0
- package/dist/client/transport.d.mts +2 -0
- package/dist/client/transport.mjs +211 -0
- package/dist/contracts/access.d.mts +87 -0
- package/dist/contracts/actors.d.mts +144 -0
- package/dist/contracts/blobs.d.mts +38 -0
- package/dist/contracts/calls-spent.d.mts +11 -0
- package/dist/contracts/calls-spent.mjs +151 -0
- package/dist/contracts/client.d.mts +90 -0
- package/dist/contracts/commits.d.mts +126 -0
- package/dist/contracts/engine.d.mts +134 -0
- package/dist/contracts/events.d.mts +276 -0
- package/dist/contracts/files.d.mts +75 -0
- package/dist/contracts/forks.d.mts +78 -0
- package/dist/contracts/grants.d.mts +60 -0
- package/dist/contracts/handlers.d.mts +11 -0
- package/dist/contracts/ids.d.mts +15 -0
- package/dist/contracts/ids.mjs +15 -0
- package/dist/contracts/lfs.d.mts +27 -0
- package/dist/contracts/merges.d.mts +33 -0
- package/dist/contracts/objects.d.mts +645 -0
- package/dist/contracts/objects.mjs +54 -0
- package/dist/contracts/operations.d.mts +133 -0
- package/dist/contracts/promises.d.mts +38 -0
- package/dist/contracts/promises.mjs +13 -0
- package/dist/contracts/push-uploads.d.mts +44 -0
- package/dist/contracts/queue.d.mts +402 -0
- package/dist/contracts/refs.d.mts +95 -0
- package/dist/contracts/remote.d.mts +50 -0
- package/dist/contracts/repos.d.mts +153 -0
- package/dist/contracts/result.d.mts +133 -0
- package/dist/contracts/result.mjs +34 -0
- package/dist/contracts/rules.d.mts +159 -0
- package/dist/contracts/server.d.mts +272 -0
- package/dist/contracts/services.d.mts +36 -0
- package/dist/contracts/services.mjs +13 -0
- package/dist/contracts/signin.d.mts +126 -0
- package/dist/contracts/store.d.mts +41 -0
- package/dist/contracts/sync.d.mts +210 -0
- package/dist/contracts/sync.mjs +8 -0
- package/dist/contracts/tags.d.mts +50 -0
- package/dist/contracts/tags.mjs +6 -0
- package/dist/contracts/tokens.d.mts +87 -0
- package/dist/contracts/tokens.mjs +15 -0
- package/dist/contracts/topics.d.mts +180 -0
- package/dist/contracts/trees.d.mts +84 -0
- package/dist/contracts/work.d.mts +31 -0
- package/dist/core/access.d.mts +22 -0
- package/dist/core/access.mjs +262 -0
- package/dist/core/ancestry.mjs +235 -0
- package/dist/core/call-names.d.mts +1 -0
- package/dist/core/call-names.mjs +93 -0
- package/dist/core/clock.mjs +18 -0
- package/dist/core/events/deliver.mjs +475 -0
- package/dist/core/events/stream.d.mts +19 -0
- package/dist/core/events/stream.mjs +297 -0
- package/dist/core/forks.mjs +1027 -0
- package/dist/core/hooks/post-receive.mjs +212 -0
- package/dist/core/hooks/pre-receive.d.mts +5 -0
- package/dist/core/hooks/pre-receive.mjs +34 -0
- package/dist/core/index-job.mjs +198 -0
- package/dist/core/names.mjs +30 -0
- package/dist/core/objects/blobs.mjs +60 -0
- package/dist/core/objects/commit-writes.mjs +185 -0
- package/dist/core/objects/commits.mjs +172 -0
- package/dist/core/objects/files.mjs +211 -0
- package/dist/core/objects/lines.mjs +42 -0
- package/dist/core/objects/merges.mjs +83 -0
- package/dist/core/objects/peel.mjs +166 -0
- package/dist/core/objects/reading.mjs +284 -0
- package/dist/core/objects/tags.mjs +96 -0
- package/dist/core/objects/tree-edits.mjs +266 -0
- package/dist/core/objects/trees.mjs +229 -0
- package/dist/core/objects/writing.mjs +266 -0
- package/dist/core/own-writes.mjs +94 -0
- package/dist/core/promise.mjs +64 -0
- package/dist/core/publish.mjs +142 -0
- package/dist/core/push-decide.mjs +206 -0
- package/dist/core/push.mjs +1070 -0
- package/dist/core/receipts.d.mts +7 -0
- package/dist/core/receipts.mjs +234 -0
- package/dist/core/ref-conflicts.mjs +27 -0
- package/dist/core/refs.mjs +359 -0
- package/dist/core/repack.mjs +521 -0
- package/dist/core/repos.mjs +752 -0
- package/dist/core/rules/changes.mjs +57 -0
- package/dist/core/rules/check.mjs +101 -0
- package/dist/core/rules/commit-changes.mjs +216 -0
- package/dist/core/rules/context.d.mts +9 -0
- package/dist/core/rules/context.mjs +120 -0
- package/dist/core/rules/define.d.mts +5 -0
- package/dist/core/rules/define.mjs +13 -0
- package/dist/core/rules/facts.mjs +13 -0
- package/dist/core/rules/fetch.d.mts +5 -0
- package/dist/core/rules/fetch.mjs +59 -0
- package/dist/core/rules/file-globs.mjs +55 -0
- package/dist/core/rules/files.mjs +142 -0
- package/dist/core/rules/patterns.mjs +23 -0
- package/dist/core/rules/protect.d.mts +9 -0
- package/dist/core/rules/protect.mjs +116 -0
- package/dist/core/seam.d.mts +26 -0
- package/dist/core/seam.mjs +54 -0
- package/dist/core/sight.mjs +99 -0
- package/dist/core/tokens.mjs +95 -0
- package/dist/core/view.d.mts +9 -0
- package/dist/core/view.mjs +221 -0
- package/dist/core/work.mjs +92 -0
- package/dist/effect.d.mts +20 -0
- package/dist/effect.mjs +18 -0
- package/dist/engine/allotted-xdiff.d.mts +4 -0
- package/dist/engine/allotted-xdiff.mjs +80 -0
- package/dist/engine/attribute-patterns.mjs +163 -0
- package/dist/engine/attributes.mjs +226 -0
- package/dist/engine/combined.mjs +653 -0
- package/dist/engine/commits.mjs +90 -0
- package/dist/engine/content.d.mts +4 -0
- package/dist/engine/content.mjs +221 -0
- package/dist/engine/diff.mjs +49 -0
- package/dist/engine/engine.d.mts +25 -0
- package/dist/engine/engine.mjs +49 -0
- package/dist/engine/failures.d.mts +4 -0
- package/dist/engine/failures.mjs +23 -0
- package/dist/engine/line-count.mjs +23 -0
- package/dist/engine/merge-base-walk.d.mts +2 -0
- package/dist/engine/merge-base-walk.mjs +265 -0
- package/dist/engine/merge-bases.mjs +27 -0
- package/dist/engine/merge-renames.mjs +165 -0
- package/dist/engine/merge.mjs +1125 -0
- package/dist/engine/parts.d.mts +8 -0
- package/dist/engine/parts.mjs +9 -0
- package/dist/engine/reads.d.mts +5 -0
- package/dist/engine/reads.mjs +105 -0
- package/dist/engine/walk.mjs +328 -0
- package/dist/engine/xdiff/NOTICE.md +63 -0
- package/dist/engine/xdiff/compiled.d.mts +7 -0
- package/dist/engine/xdiff/compiled.mjs +9 -0
- package/dist/engine/xdiff/embedded.mjs +4 -0
- package/dist/engine/xdiff/node.d.mts +7 -0
- package/dist/engine/xdiff/node.mjs +10 -0
- package/dist/engine/xdiff/upstream/LGPL-2.1 +511 -0
- package/dist/engine/xdiff/xdiff.wasm +0 -0
- package/dist/engine/xdiff.d.mts +34 -0
- package/dist/engine/xdiff.mjs +380 -0
- package/dist/engine.d.mts +3 -0
- package/dist/engine.mjs +3 -0
- package/dist/extend.d.mts +4 -0
- package/dist/extend.mjs +3 -0
- package/dist/http/answers.mjs +74 -0
- package/dist/http/bodies.mjs +143 -0
- package/dist/http/core-parts.mjs +252 -0
- package/dist/http/fetch-depth.mjs +26 -0
- package/dist/http/handler.mjs +94 -0
- package/dist/http/node.d.mts +70 -0
- package/dist/http/node.mjs +178 -0
- package/dist/http/paths.d.mts +9 -0
- package/dist/http/paths.mjs +118 -0
- package/dist/http/push-uploads.mjs +286 -0
- package/dist/http/receive-pack.mjs +235 -0
- package/dist/http/upload-pack.mjs +229 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.mjs +16 -0
- package/dist/lfs/calls.mjs +16 -0
- package/dist/lfs/locks.mjs +161 -0
- package/dist/lfs/objects.mjs +370 -0
- package/dist/lfs/pointers.mjs +141 -0
- package/dist/lfs/repo.mjs +42 -0
- package/dist/lfs/rows.mjs +108 -0
- package/dist/lfs/service.mjs +34 -0
- package/dist/lfs/upkeep.mjs +162 -0
- package/dist/lfs/wire.mjs +102 -0
- package/dist/node.d.mts +3 -0
- package/dist/node.mjs +3 -0
- package/dist/protocol/bytes/buffers.d.mts +38 -0
- package/dist/protocol/bytes/buffers.mjs +62 -0
- package/dist/protocol/bytes/crc32.d.mts +4 -0
- package/dist/protocol/bytes/crc32.mjs +14 -0
- package/dist/protocol/bytes/deflate.d.mts +78 -0
- package/dist/protocol/bytes/deflate.mjs +175 -0
- package/dist/protocol/bytes/errors.d.mts +20 -0
- package/dist/protocol/bytes/errors.mjs +19 -0
- package/dist/protocol/bytes/hex.mjs +16 -0
- package/dist/protocol/bytes/hmac-sha256.mjs +91 -0
- package/dist/protocol/bytes/inflate.d.mts +40 -0
- package/dist/protocol/bytes/inflate.mjs +109 -0
- package/dist/protocol/bytes/joined.d.mts +2 -0
- package/dist/protocol/bytes/joined.mjs +25 -0
- package/dist/protocol/bytes/sha1-hasher.d.mts +20 -0
- package/dist/protocol/bytes/sha1-hasher.mjs +72 -0
- package/dist/protocol/bytes/sha1.d.mts +35 -0
- package/dist/protocol/bytes/sha1.mjs +409 -0
- package/dist/protocol/bytes/sha256.mjs +156 -0
- package/dist/protocol/bytes/streams.mjs +11 -0
- package/dist/protocol/bytes/text.mjs +19 -0
- package/dist/protocol/diff/diff-raw.d.mts +29 -0
- package/dist/protocol/diff/diff-raw.mjs +73 -0
- package/dist/protocol/diff/patch.mjs +92 -0
- package/dist/protocol/diff/paths.mjs +67 -0
- package/dist/protocol/diff/read.d.mts +62 -0
- package/dist/protocol/diff/read.mjs +342 -0
- package/dist/protocol/diff/rename-similarity.mjs +428 -0
- package/dist/protocol/diff/text.mjs +12 -0
- package/dist/protocol/diff/tree-diff.d.mts +41 -0
- package/dist/protocol/diff/tree-diff.mjs +607 -0
- package/dist/protocol/framing/band.d.mts +10 -0
- package/dist/protocol/framing/band.mjs +16 -0
- package/dist/protocol/framing/pkt-line.d.mts +48 -0
- package/dist/protocol/framing/pkt-line.mjs +92 -0
- package/dist/protocol/objects/checked-blobs.mjs +127 -0
- package/dist/protocol/objects/commit.d.mts +25 -0
- package/dist/protocol/objects/commit.mjs +138 -0
- package/dist/protocol/objects/fsck-gitmodules.mjs +296 -0
- package/dist/protocol/objects/fsck-names.mjs +189 -0
- package/dist/protocol/objects/fsck.mjs +297 -0
- package/dist/protocol/objects/headers.mjs +109 -0
- package/dist/protocol/objects/held.mjs +56 -0
- package/dist/protocol/objects/iconv.mjs +145 -0
- package/dist/protocol/objects/ident.mjs +111 -0
- package/dist/protocol/objects/lfs-pointer.d.mts +8 -0
- package/dist/protocol/objects/lfs-pointer.mjs +63 -0
- package/dist/protocol/objects/links-raw.mjs +89 -0
- package/dist/protocol/objects/object-rules.mjs +75 -0
- package/dist/protocol/objects/object.d.mts +16 -0
- package/dist/protocol/objects/object.mjs +29 -0
- package/dist/protocol/objects/tag.d.mts +21 -0
- package/dist/protocol/objects/tag.mjs +96 -0
- package/dist/protocol/objects/tree.d.mts +43 -0
- package/dist/protocol/objects/tree.mjs +162 -0
- package/dist/protocol/objects/utf8-verify.mjs +71 -0
- package/dist/protocol/packs/delta.d.mts +57 -0
- package/dist/protocol/packs/delta.mjs +229 -0
- package/dist/protocol/packs/graph.mjs +78 -0
- package/dist/protocol/packs/idx.d.mts +54 -0
- package/dist/protocol/packs/idx.mjs +274 -0
- package/dist/protocol/packs/indexer.d.mts +167 -0
- package/dist/protocol/packs/indexer.mjs +507 -0
- package/dist/protocol/packs/parts.d.mts +40 -0
- package/dist/protocol/packs/parts.mjs +89 -0
- package/dist/protocol/packs/pos.mjs +51 -0
- package/dist/protocol/packs/reader.d.mts +180 -0
- package/dist/protocol/packs/reader.mjs +414 -0
- package/dist/protocol/packs/rev.d.mts +32 -0
- package/dist/protocol/packs/rev.mjs +99 -0
- package/dist/protocol/packs/step.d.mts +10 -0
- package/dist/protocol/packs/step.mjs +12 -0
- package/dist/protocol/packs/write-error.d.mts +12 -0
- package/dist/protocol/packs/write-error.mjs +27 -0
- package/dist/protocol/packs/writer.d.mts +157 -0
- package/dist/protocol/packs/writer.mjs +353 -0
- package/dist/protocol/wire/advertisement.d.mts +72 -0
- package/dist/protocol/wire/advertisement.mjs +161 -0
- package/dist/protocol/wire/fetch.d.mts +155 -0
- package/dist/protocol/wire/fetch.mjs +458 -0
- package/dist/protocol/wire/lines.mjs +107 -0
- package/dist/protocol/wire/push-uploads.mjs +43 -0
- package/dist/protocol/wire/receive-pack.d.mts +71 -0
- package/dist/protocol/wire/receive-pack.mjs +157 -0
- package/dist/protocol/wire/report-status.d.mts +47 -0
- package/dist/protocol/wire/report-status.mjs +119 -0
- package/dist/protocol/wire/v2.d.mts +90 -0
- package/dist/protocol/wire/v2.mjs +185 -0
- package/dist/protocol.d.mts +31 -0
- package/dist/protocol.mjs +31 -0
- package/dist/queue/advance.mjs +1037 -0
- package/dist/queue/callers.mjs +134 -0
- package/dist/queue/calls.mjs +1154 -0
- package/dist/queue/commit.mjs +85 -0
- package/dist/queue/host.d.mts +15 -0
- package/dist/queue/host.mjs +88 -0
- package/dist/queue/ids.d.mts +5 -0
- package/dist/queue/ids.mjs +21 -0
- package/dist/queue/lanes.mjs +86 -0
- package/dist/queue/limits.mjs +99 -0
- package/dist/queue/pages.mjs +76 -0
- package/dist/queue/push-option.mjs +62 -0
- package/dist/queue/rows.mjs +206 -0
- package/dist/queue/schedule.mjs +132 -0
- package/dist/queue/search.mjs +315 -0
- package/dist/queue/state.mjs +325 -0
- package/dist/queue/steps.mjs +317 -0
- package/dist/remote-helper.d.mts +3 -0
- package/dist/remote-helper.mjs +3 -0
- package/dist/rest/api.d.mts +23 -0
- package/dist/rest/api.mjs +27 -0
- package/dist/rest/blobs.d.mts +58 -0
- package/dist/rest/blobs.mjs +41 -0
- package/dist/rest/caller.d.mts +102 -0
- package/dist/rest/caller.mjs +18 -0
- package/dist/rest/client.d.mts +18 -0
- package/dist/rest/client.mjs +587 -0
- package/dist/rest/commits.d.mts +435 -0
- package/dist/rest/commits.mjs +140 -0
- package/dist/rest/errors.d.mts +44 -0
- package/dist/rest/errors.mjs +186 -0
- package/dist/rest/events.d.mts +38 -0
- package/dist/rest/events.mjs +74 -0
- package/dist/rest/files.d.mts +179 -0
- package/dist/rest/files.mjs +92 -0
- package/dist/rest/forks.d.mts +205 -0
- package/dist/rest/forks.mjs +51 -0
- package/dist/rest/handler.d.mts +18 -0
- package/dist/rest/handler.mjs +129 -0
- package/dist/rest/handlers.d.mts +8 -0
- package/dist/rest/handlers.mjs +592 -0
- package/dist/rest/listen.d.mts +24 -0
- package/dist/rest/listen.mjs +142 -0
- package/dist/rest/me.d.mts +55 -0
- package/dist/rest/me.mjs +21 -0
- package/dist/rest/merges.d.mts +90 -0
- package/dist/rest/merges.mjs +39 -0
- package/dist/rest/paths.mjs +86 -0
- package/dist/rest/queue.d.mts +486 -0
- package/dist/rest/queue.mjs +228 -0
- package/dist/rest/refs.d.mts +232 -0
- package/dist/rest/refs.mjs +86 -0
- package/dist/rest/repos.d.mts +223 -0
- package/dist/rest/repos.mjs +93 -0
- package/dist/rest/tags.d.mts +153 -0
- package/dist/rest/tags.mjs +72 -0
- package/dist/rest/tokens.d.mts +297 -0
- package/dist/rest/tokens.mjs +88 -0
- package/dist/rest/topics.d.mts +257 -0
- package/dist/rest/topics.mjs +116 -0
- package/dist/rest/trees.d.mts +158 -0
- package/dist/rest/trees.mjs +118 -0
- package/dist/rest/wire.mjs +57 -0
- package/dist/rest/work.d.mts +107 -0
- package/dist/rest/work.mjs +77 -0
- package/dist/rest.d.mts +8 -0
- package/dist/rest.mjs +5 -0
- package/dist/server/extension.d.mts +17 -0
- package/dist/server/extension.mjs +93 -0
- package/dist/server/lifecycle.d.mts +3 -0
- package/dist/server/lifecycle.mjs +89 -0
- package/dist/server/routes.d.mts +28 -0
- package/dist/server/routes.mjs +60 -0
- package/dist/server/server.d.mts +8 -0
- package/dist/server/server.mjs +615 -0
- package/dist/signin/codes.mjs +47 -0
- package/dist/signin/context.d.mts +9 -0
- package/dist/signin/context.mjs +121 -0
- package/dist/signin/device.mjs +122 -0
- package/dist/signin/forms.mjs +157 -0
- package/dist/signin/grants.d.mts +5 -0
- package/dist/signin/grants.mjs +257 -0
- package/dist/signin/route.mjs +68 -0
- package/dist/signin/web.mjs +125 -0
- package/dist/signin/wire.d.mts +42 -0
- package/dist/signin/wire.mjs +43 -0
- package/dist/storage/allotted.mjs +102 -0
- package/dist/storage/bits.mjs +41 -0
- package/dist/storage/budget.mjs +96 -0
- package/dist/storage/calls.d.mts +18 -0
- package/dist/storage/calls.mjs +273 -0
- package/dist/storage/clean-up.mjs +124 -0
- package/dist/storage/distinct-ids.mjs +39 -0
- package/dist/storage/ewah.mjs +97 -0
- package/dist/storage/fetch.d.mts +15 -0
- package/dist/storage/fetch.mjs +998 -0
- package/dist/storage/fsck.mjs +77 -0
- package/dist/storage/held-memo.mjs +188 -0
- package/dist/storage/index-bitmaps.d.mts +4 -0
- package/dist/storage/index-bitmaps.mjs +654 -0
- package/dist/storage/index-build.d.mts +15 -0
- package/dist/storage/index-build.mjs +1447 -0
- package/dist/storage/index-fetch.d.mts +10 -0
- package/dist/storage/index-fetch.mjs +677 -0
- package/dist/storage/index-files.mjs +232 -0
- package/dist/storage/index-graph.d.mts +3 -0
- package/dist/storage/index-graph.mjs +1049 -0
- package/dist/storage/index-layers.mjs +317 -0
- package/dist/storage/index-reach.mjs +216 -0
- package/dist/storage/index-remap.d.mts +8 -0
- package/dist/storage/index-remap.mjs +592 -0
- package/dist/storage/layout.mjs +69 -0
- package/dist/storage/lfs-pointers.d.mts +21 -0
- package/dist/storage/lfs-pointers.mjs +175 -0
- package/dist/storage/link-join.mjs +106 -0
- package/dist/storage/links.mjs +105 -0
- package/dist/storage/loose.d.mts +15 -0
- package/dist/storage/loose.mjs +121 -0
- package/dist/storage/memory-budget.d.mts +8 -0
- package/dist/storage/memory-budget.mjs +546 -0
- package/dist/storage/merge.mjs +416 -0
- package/dist/storage/object-rows.d.mts +6 -0
- package/dist/storage/object-rows.mjs +211 -0
- package/dist/storage/pack-order.d.mts +8 -0
- package/dist/storage/pack-order.mjs +781 -0
- package/dist/storage/pack-ranges.d.mts +5 -0
- package/dist/storage/pack-ranges.mjs +284 -0
- package/dist/storage/pack-reads.d.mts +11 -0
- package/dist/storage/pack-reads.mjs +1007 -0
- package/dist/storage/pack-receive.d.mts +11 -0
- package/dist/storage/pack-receive.mjs +449 -0
- package/dist/storage/packs.d.mts +56 -0
- package/dist/storage/packs.mjs +603 -0
- package/dist/storage/prune.mjs +506 -0
- package/dist/storage/push-allotment.mjs +109 -0
- package/dist/storage/push-uploads.mjs +152 -0
- package/dist/storage/pushed-commits.mjs +136 -0
- package/dist/storage/quarantine.mjs +98 -0
- package/dist/storage/raw-ids.mjs +44 -0
- package/dist/storage/ready.d.mts +19 -0
- package/dist/storage/ready.mjs +328 -0
- package/dist/storage/receive-links.mjs +297 -0
- package/dist/storage/repack-job.mjs +48 -0
- package/dist/storage/repack.d.mts +31 -0
- package/dist/storage/repack.mjs +182 -0
- package/dist/storage/roots.mjs +42 -0
- package/dist/storage/rows.d.mts +4 -0
- package/dist/storage/rows.mjs +71 -0
- package/dist/storage/send-list.d.mts +8 -0
- package/dist/storage/send-list.mjs +319 -0
- package/dist/storage/shallow.d.mts +4 -0
- package/dist/storage/shallow.mjs +128 -0
- package/dist/storage/stream-whole.mjs +236 -0
- package/dist/storage/unpack.mjs +238 -0
- package/dist/storage/visible.mjs +137 -0
- package/dist/storage/walk.d.mts +8 -0
- package/dist/storage/walk.mjs +176 -0
- package/dist/storage/wants.mjs +362 -0
- package/dist/store/call-count.d.mts +47 -0
- package/dist/store/call-count.mjs +207 -0
- package/dist/store/catalogue.d.mts +7 -0
- package/dist/store/catalogue.mjs +643 -0
- package/dist/store/closed.d.mts +21 -0
- package/dist/store/closed.mjs +34 -0
- package/dist/store/crossing.mjs +69 -0
- package/dist/store/cursor-seal.d.mts +2 -0
- package/dist/store/cursor-seal.mjs +88 -0
- package/dist/store/errors.d.mts +12 -0
- package/dist/store/errors.mjs +135 -0
- package/dist/store/git-store.mjs +75 -0
- package/dist/store/list-job.mjs +35 -0
- package/dist/store/outbox.d.mts +7 -0
- package/dist/store/outbox.mjs +297 -0
- package/dist/store/promises.d.mts +5 -0
- package/dist/store/promises.mjs +258 -0
- package/dist/store/queue-jobs.mjs +43 -0
- package/dist/store/random.mjs +28 -0
- package/dist/store/records.d.mts +4 -0
- package/dist/store/records.mjs +192 -0
- package/dist/store/ref-rows.d.mts +4 -0
- package/dist/store/ref-rows.mjs +30 -0
- package/dist/store/repo-record.mjs +100 -0
- package/dist/store/reservations.mjs +82 -0
- package/dist/store/scopes.mjs +170 -0
- package/dist/store/settle.mjs +63 -0
- package/dist/store/topic-jobs.mjs +62 -0
- package/dist/sync/bound.d.mts +7 -0
- package/dist/sync/bound.mjs +34 -0
- package/dist/sync/github.d.mts +12 -0
- package/dist/sync/github.mjs +297 -0
- package/dist/sync/import.d.mts +8 -0
- package/dist/sync/import.mjs +154 -0
- package/dist/sync/jobs.d.mts +9 -0
- package/dist/sync/jobs.mjs +83 -0
- package/dist/sync/mirror.d.mts +9 -0
- package/dist/sync/mirror.mjs +227 -0
- package/dist/sync/publish.d.mts +5 -0
- package/dist/sync/publish.mjs +117 -0
- package/dist/sync/records.mjs +73 -0
- package/dist/sync/smart-http.d.mts +8 -0
- package/dist/sync/smart-http.mjs +23 -0
- package/dist/sync/step.mjs +334 -0
- package/dist/sync/tries.mjs +126 -0
- package/dist/sync.d.mts +8 -0
- package/dist/sync.mjs +8 -0
- package/dist/topics/advance.mjs +555 -0
- package/dist/topics/calls.mjs +346 -0
- package/dist/topics/directory.mjs +107 -0
- package/dist/topics/host.d.mts +11 -0
- package/dist/topics/host.mjs +71 -0
- package/dist/topics/members.mjs +177 -0
- package/dist/topics/rows.mjs +99 -0
- package/dist/topics/topic.mjs +141 -0
- package/package.json +86 -5
|
@@ -0,0 +1,1049 @@
|
|
|
1
|
+
import { BufferError, BufferMeter } from "../protocol/bytes/buffers.mjs";
|
|
2
|
+
import { hexOf } from "../protocol/bytes/hex.mjs";
|
|
3
|
+
import { Sha1 } from "../protocol/bytes/sha1.mjs";
|
|
4
|
+
import { graphMagic } from "../protocol/packs/graph.mjs";
|
|
5
|
+
import { PackTransportError, boundedSource } from "../protocol/packs/reader.mjs";
|
|
6
|
+
import { gitError } from "../store/errors.mjs";
|
|
7
|
+
import { bucketCall } from "./calls.mjs";
|
|
8
|
+
import { startPut } from "./merge.mjs";
|
|
9
|
+
import { readExactly } from "./pack-ranges.mjs";
|
|
10
|
+
import { compareIds, orderById } from "./raw-ids.mjs";
|
|
11
|
+
import * as Effect from "effect/Effect";
|
|
12
|
+
import * as Exit from "effect/Exit";
|
|
13
|
+
// src/storage/index-graph.ts
|
|
14
|
+
/**
|
|
15
|
+
* The reachability index's commit graph, `index/<repo>/<build>.graph`: every commit the repo's packs
|
|
16
|
+
* hold, numbered in ID order, with its parents as graph numbers and its generation. A repack
|
|
17
|
+
* leaves it alone, since nothing in it is an object position. Built by merging the packs' own
|
|
18
|
+
* `.graph` files, each streamed in one read, so no commit is read from a pack. ref0's own format,
|
|
19
|
+
* big-endian:
|
|
20
|
+
*
|
|
21
|
+
* - `R0CG`, then version 1, then the commits C, then the octopus entries E;
|
|
22
|
+
* - the fanout: for each first byte, how many IDs are at or below it, 4 bytes each;
|
|
23
|
+
* - each commit's ID, ascending, 20 bytes;
|
|
24
|
+
* - each commit's first parent, second parent and generation, 4 bytes each. A parent it lacks is
|
|
25
|
+
* `none`. A commit of more than two parents has `octopusFlag` and its list's start in the
|
|
26
|
+
* octopus table as its second;
|
|
27
|
+
* - the octopus table: each such commit's parents after its first, the last with `lastFlag`;
|
|
28
|
+
* - the SHA-1 of every byte before it.
|
|
29
|
+
*
|
|
30
|
+
* An index kept up by layers has one such file a layer, each holding the commits of the packs
|
|
31
|
+
* pushed since the layer before it, less those a layer below holds: a commit pushed again is
|
|
32
|
+
* counted, bounded and numbered once, in the lowest layer that holds it. A layer's commits are numbered after every layer below it,
|
|
33
|
+
* from its `first`, and its parents are numbers among all the layers, so a parent may be below
|
|
34
|
+
* `first`. `openGraphLayers` reads the layers as one graph.
|
|
35
|
+
*
|
|
36
|
+
* The build holds 16 bytes a commit, its parents, generations and a walk's stack, charged to its
|
|
37
|
+
* allotment, a bounded table of parents still to number, and each input's read. A repo past
|
|
38
|
+
* `most`, or with a commit of more than `mostParents` parents, is refused, and keeps the bounded
|
|
39
|
+
* walk.
|
|
40
|
+
*/
|
|
41
|
+
const lost = (message) => gitError("DATA_LOSS", message);
|
|
42
|
+
const magic = [
|
|
43
|
+
82,
|
|
44
|
+
48,
|
|
45
|
+
67,
|
|
46
|
+
71
|
|
47
|
+
];
|
|
48
|
+
/** A parent the repo lacks: a shallow commit's. */
|
|
49
|
+
const none = 2147483647;
|
|
50
|
+
/** An ID the graph doesn't hold. */
|
|
51
|
+
const absent = 4294967295;
|
|
52
|
+
/** A second parent's flag: the rest is the commit's list in the octopus table. */
|
|
53
|
+
const octopusFlag = 2147483648;
|
|
54
|
+
/** An octopus table entry's flag: its commit's last parent. */
|
|
55
|
+
const lastFlag = 2147483648;
|
|
56
|
+
/** Graph numbers stay below `none` and its flags. */
|
|
57
|
+
const mostCommits = 2 ** 30;
|
|
58
|
+
/**
|
|
59
|
+
* Most parents of one commit the build numbers: a commit of more refuses the build, as a history
|
|
60
|
+
* past its memory does, and the repo keeps the bounded walk.
|
|
61
|
+
*/
|
|
62
|
+
const mostParents = 4096;
|
|
63
|
+
/** A wide commit's parents are skipped in pieces of this many bytes. */
|
|
64
|
+
const skipBytes = 64e3;
|
|
65
|
+
/** Parents a pass numbers at most, 24 bytes each: about 1.5 MiB. */
|
|
66
|
+
const graphRefs = 65536;
|
|
67
|
+
/** What a pack's `.graph` read holds: one transport piece. */
|
|
68
|
+
const graphReadBytes = 1048576;
|
|
69
|
+
/** What the writer gathers before each write to the bucket. */
|
|
70
|
+
const writeBytes = 65536;
|
|
71
|
+
/** What the writer holds: the piece it gathers, the one it wrote, and its words' scratch. */
|
|
72
|
+
const writerBytes = 3 * writeBytes;
|
|
73
|
+
const asIs = (value) => value;
|
|
74
|
+
/** How many bytes an index graph of `commits` and `octopus` entries takes. */
|
|
75
|
+
const indexGraphBytes = (commits, octopus) => 1040 + commits * 32 + octopus * 4 + 20;
|
|
76
|
+
/** A file's bytes from one streamed read, taken a few at a time, hashed as they're taken. */
|
|
77
|
+
const taker = (read) => {
|
|
78
|
+
const sha = new Sha1();
|
|
79
|
+
let piece = /* @__PURE__ */ new Uint8Array(0);
|
|
80
|
+
let at = 0;
|
|
81
|
+
/** The next `count` bytes, copied, or `undefined` when the file ends first. */
|
|
82
|
+
const take = (count, hashed = true) => Effect.gen(function* () {
|
|
83
|
+
const out = new Uint8Array(count);
|
|
84
|
+
let filled = 0;
|
|
85
|
+
while (filled < count) {
|
|
86
|
+
if (at === piece.length) {
|
|
87
|
+
const next = yield* read;
|
|
88
|
+
if (next === void 0) return void 0;
|
|
89
|
+
piece = next;
|
|
90
|
+
at = 0;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const length = Math.min(count - filled, piece.length - at);
|
|
94
|
+
out.set(piece.subarray(at, at + length), filled);
|
|
95
|
+
at += length;
|
|
96
|
+
filled += length;
|
|
97
|
+
}
|
|
98
|
+
if (hashed) sha.update(out);
|
|
99
|
+
return out;
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
take,
|
|
103
|
+
ended: Effect.gen(function* () {
|
|
104
|
+
while (at === piece.length) {
|
|
105
|
+
const next = yield* read;
|
|
106
|
+
if (next === void 0) return true;
|
|
107
|
+
piece = next;
|
|
108
|
+
at = 0;
|
|
109
|
+
}
|
|
110
|
+
return false;
|
|
111
|
+
}),
|
|
112
|
+
sha
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const word = (bytes, at) => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(at);
|
|
116
|
+
const same = (a, b) => a.length === b.length && a.every((byte, at) => byte === b[at]);
|
|
117
|
+
/** One `.graph`, a pack's or the region's, streamed: its commits in ID order, its trailer checked. */
|
|
118
|
+
const openPackGraph = (bucket, key) => Effect.gen(function* () {
|
|
119
|
+
const body = yield* bucketCall((signal) => bucket.read(key, void 0, { signal }));
|
|
120
|
+
if (body === void 0) return yield* Effect.fail(lost(`${key} is missing`));
|
|
121
|
+
const source = boundedSource(body, /* @__PURE__ */ new Uint8Array(0), new BufferMeter(graphReadBytes));
|
|
122
|
+
const read = source.read.pipe(Effect.mapError((error) => error instanceof PackTransportError ? gitError("UNAVAILABLE", `${key}'s read failed`, {
|
|
123
|
+
cause: error.cause,
|
|
124
|
+
hint: "Try again"
|
|
125
|
+
}) : error instanceof BufferError ? lost(`${key} came in a piece too large: ${error.message}`) : error));
|
|
126
|
+
const bytes = taker(read);
|
|
127
|
+
const broken = (why) => Effect.fail(lost(`${key} ${why}`));
|
|
128
|
+
const head = yield* bytes.take(12);
|
|
129
|
+
if (head === void 0 || graphMagic.some((byte, at) => head[at] !== byte)) return yield* broken("doesn't start as a .graph");
|
|
130
|
+
if (word(head, 4) !== 1) return yield* broken(`is format ${word(head, 4)}`);
|
|
131
|
+
let left = word(head, 8);
|
|
132
|
+
let last;
|
|
133
|
+
let done = false;
|
|
134
|
+
return {
|
|
135
|
+
next: Effect.gen(function* () {
|
|
136
|
+
if (done) return void 0;
|
|
137
|
+
if (left === 0) {
|
|
138
|
+
done = true;
|
|
139
|
+
const trailer = yield* bytes.take(20, false);
|
|
140
|
+
if (trailer === void 0 || !same(trailer, bytes.sha.digest())) return yield* broken("'s trailer isn't its SHA-1");
|
|
141
|
+
if (!(yield* bytes.ended)) return yield* broken("has bytes past its trailer");
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const entry = yield* bytes.take(24);
|
|
145
|
+
if (entry === void 0) return yield* broken("ends inside a commit");
|
|
146
|
+
const id = entry.subarray(0, 20);
|
|
147
|
+
const count = word(entry, 20);
|
|
148
|
+
if (last !== void 0 && compareIds(last, 0, id, 0) >= 0) return yield* broken("is out of order");
|
|
149
|
+
left -= 1;
|
|
150
|
+
last = id;
|
|
151
|
+
if (count > 4096) {
|
|
152
|
+
for (let skip = count * 20; skip > 0; skip -= skipBytes) if ((yield* bytes.take(Math.min(skip, skipBytes))) === void 0) return yield* broken("ends inside a commit");
|
|
153
|
+
return {
|
|
154
|
+
id,
|
|
155
|
+
parents: /* @__PURE__ */ new Uint8Array(0),
|
|
156
|
+
count
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
const parents = yield* bytes.take(count * 20);
|
|
160
|
+
if (parents === void 0) return yield* broken("ends inside a commit");
|
|
161
|
+
return {
|
|
162
|
+
id,
|
|
163
|
+
parents,
|
|
164
|
+
count
|
|
165
|
+
};
|
|
166
|
+
}),
|
|
167
|
+
cancel: source.cancel
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
/** Each commit of `graphs` in ID order, each ID once, to `each`, its graph number counted. */
|
|
171
|
+
const eachCommit = (bucket, graphs, each) => Effect.gen(function* () {
|
|
172
|
+
const sources = yield* Effect.forEach(graphs, (key) => openPackGraph(bucket, key));
|
|
173
|
+
yield* Effect.addFinalizer(() => Effect.forEach(sources, (source) => source.cancel));
|
|
174
|
+
const heads = [];
|
|
175
|
+
for (const source of sources) heads.push(yield* source.next);
|
|
176
|
+
for (let number = 0;; number += 1) {
|
|
177
|
+
let least;
|
|
178
|
+
for (const head of heads) if (head !== void 0 && (least === void 0 || compareIds(head.id, 0, least.id, 0) < 0)) least = head;
|
|
179
|
+
if (least === void 0) return number;
|
|
180
|
+
for (const [at, head] of heads.entries()) if (head !== void 0 && compareIds(head.id, 0, least.id, 0) === 0) heads[at] = yield* sources[at]?.next ?? Effect.succeed(void 0);
|
|
181
|
+
const step = each(number, least);
|
|
182
|
+
if (step !== void 0) yield* step;
|
|
183
|
+
}
|
|
184
|
+
}).pipe(Effect.scoped);
|
|
185
|
+
/**
|
|
186
|
+
* The merge numbers `eachCommit` gives `graphs`' commits that `below` holds, ascending, looked up
|
|
187
|
+
* `refs` at a time: a layer leaves them out. Its lookup's IDs and numbers, 24 bytes a ref, and the
|
|
188
|
+
* list, 4 bytes a held commit, are charged to `allotment`; `bytes` is what to give back.
|
|
189
|
+
*/
|
|
190
|
+
const heldBelow = (bucket, graphs, below, refs, allotment) => Effect.gen(function* () {
|
|
191
|
+
yield* allotment.grow(refs * 24);
|
|
192
|
+
const ids = new Uint8Array(refs * 20);
|
|
193
|
+
const numbers = new Uint32Array(refs);
|
|
194
|
+
let size = 0;
|
|
195
|
+
let held = /* @__PURE__ */ new Uint32Array(0);
|
|
196
|
+
let count = 0;
|
|
197
|
+
const lookup = Effect.gen(function* () {
|
|
198
|
+
const found = yield* below.numbersOf(ids, size);
|
|
199
|
+
for (let at = 0; at < size; at += 1) {
|
|
200
|
+
const number = found[at] ?? 4294967295;
|
|
201
|
+
if (number === 4294967295) continue;
|
|
202
|
+
if (number >= below.first) return yield* Effect.fail(lost(`The layers below named commit ${number}, past their ${below.first}`));
|
|
203
|
+
if (count === held.length) {
|
|
204
|
+
const grown = new Uint32Array(Math.max(1024, held.length * 2));
|
|
205
|
+
yield* allotment.grow((grown.length - held.length) * 4);
|
|
206
|
+
grown.set(held);
|
|
207
|
+
held = grown;
|
|
208
|
+
}
|
|
209
|
+
held[count] = numbers[at] ?? 0;
|
|
210
|
+
count += 1;
|
|
211
|
+
}
|
|
212
|
+
size = 0;
|
|
213
|
+
});
|
|
214
|
+
yield* eachCommit(bucket, graphs, (number, commit) => {
|
|
215
|
+
ids.set(commit.id, size * 20);
|
|
216
|
+
numbers[size] = number;
|
|
217
|
+
size += 1;
|
|
218
|
+
return size === refs ? lookup : void 0;
|
|
219
|
+
});
|
|
220
|
+
if (size > 0) yield* lookup;
|
|
221
|
+
return {
|
|
222
|
+
held: held.subarray(0, count),
|
|
223
|
+
bytes: refs * 24 + held.length * 4
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
/** `graphs`' commits as `eachCommit` gives them, less the merge numbers `held` names, numbered without them. */
|
|
227
|
+
const ownCommits = (bucket, graphs, held, each) => Effect.gen(function* () {
|
|
228
|
+
let skipped = 0;
|
|
229
|
+
return (yield* eachCommit(bucket, graphs, (number, commit) => {
|
|
230
|
+
if (held[skipped] !== number) return each(number - skipped, commit);
|
|
231
|
+
skipped += 1;
|
|
232
|
+
})) - skipped;
|
|
233
|
+
});
|
|
234
|
+
/** Parents still to number: each one's ID, and where its number goes. */
|
|
235
|
+
var ParentRefs = class {
|
|
236
|
+
ids;
|
|
237
|
+
targets;
|
|
238
|
+
size = 0;
|
|
239
|
+
/** Room for `refs` parents, and one commit's whole list past them, so any commit fits. */
|
|
240
|
+
constructor(refs) {
|
|
241
|
+
this.ids = new Uint8Array((refs + mostParents) * 20);
|
|
242
|
+
this.targets = new Uint32Array(refs + mostParents);
|
|
243
|
+
}
|
|
244
|
+
add(parents, at, target) {
|
|
245
|
+
this.ids.set(parents.subarray(at, at + 20), this.size * 20);
|
|
246
|
+
this.targets[this.size] = target;
|
|
247
|
+
this.size += 1;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
/** A target's encoding: a first or second parent's slot, or an octopus table entry. */
|
|
251
|
+
const firstSlot = (commit) => commit * 2;
|
|
252
|
+
const octopusTarget = (entry) => (octopusFlag | entry) >>> 0;
|
|
253
|
+
/** Bytes gathered into writes of `writeBytes`, each hashed. */
|
|
254
|
+
const gathered = (write) => {
|
|
255
|
+
const sha = new Sha1();
|
|
256
|
+
let buffer = new Uint8Array(writeBytes);
|
|
257
|
+
let filled = 0;
|
|
258
|
+
const flush = Effect.suspend(() => {
|
|
259
|
+
if (filled === 0) return Effect.void;
|
|
260
|
+
const bytes = buffer.subarray(0, filled);
|
|
261
|
+
sha.update(bytes);
|
|
262
|
+
buffer = new Uint8Array(writeBytes);
|
|
263
|
+
filled = 0;
|
|
264
|
+
return write(bytes);
|
|
265
|
+
});
|
|
266
|
+
const push = (bytes) => Effect.gen(function* () {
|
|
267
|
+
let at = 0;
|
|
268
|
+
while (at < bytes.length) {
|
|
269
|
+
const length = Math.min(bytes.length - at, writeBytes - filled);
|
|
270
|
+
buffer.set(bytes.subarray(at, at + length), filled);
|
|
271
|
+
filled += length;
|
|
272
|
+
at += length;
|
|
273
|
+
if (filled === writeBytes) yield* flush;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
const scratch = new Uint8Array(writeBytes);
|
|
277
|
+
const scratchView = new DataView(scratch.buffer);
|
|
278
|
+
const words = (values, map = asIs) => Effect.gen(function* () {
|
|
279
|
+
for (let from = 0; from < values.length; from += writeBytes / 4) {
|
|
280
|
+
const count = Math.min(writeBytes / 4, values.length - from);
|
|
281
|
+
for (let at = 0; at < count; at += 1) scratchView.setUint32(at * 4, map(values[from + at] ?? 0, from + at));
|
|
282
|
+
yield* push(scratch.subarray(0, count * 4));
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
return {
|
|
286
|
+
push,
|
|
287
|
+
words,
|
|
288
|
+
seal: Effect.gen(function* () {
|
|
289
|
+
yield* flush;
|
|
290
|
+
yield* write(sha.digest());
|
|
291
|
+
})
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* The put of an index graph of `commits` and `octopus` entries at `key`, started with its header
|
|
296
|
+
* and its fanout, from `counts`, how many IDs each first byte has, summed in place. It's aborted
|
|
297
|
+
* when its scope fails.
|
|
298
|
+
*/
|
|
299
|
+
const startGraph = (bucket, key, commits, octopus, counts) => Effect.gen(function* () {
|
|
300
|
+
const put = yield* startPut(bucket, key, { size: indexGraphBytes(commits, octopus) });
|
|
301
|
+
yield* Effect.addFinalizer((exit) => Exit.isFailure(exit) ? put.abort : Effect.void);
|
|
302
|
+
const out = gathered(put.write);
|
|
303
|
+
const head = /* @__PURE__ */ new Uint8Array(16);
|
|
304
|
+
head.set(magic);
|
|
305
|
+
const view = new DataView(head.buffer);
|
|
306
|
+
view.setUint32(4, 1);
|
|
307
|
+
view.setUint32(8, commits);
|
|
308
|
+
view.setUint32(12, octopus);
|
|
309
|
+
yield* out.push(head);
|
|
310
|
+
for (let first = 1; first < 256; first += 1) counts[first] = (counts[first] ?? 0) + (counts[first - 1] ?? 0);
|
|
311
|
+
yield* out.words(counts);
|
|
312
|
+
return {
|
|
313
|
+
out,
|
|
314
|
+
finish: Effect.andThen(out.seal, put.finish)
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
/** The refusal of a repo whose history is past what the build may hold. */
|
|
318
|
+
const graphTooLarge = (commits, bytes, most) => gitError("RESOURCE_EXHAUSTED", `The repo's ${commits} commits need ${bytes} bytes to index, past the build's ${most}; fetches go on with the bounded walk`);
|
|
319
|
+
/** The refusal of a repo with a commit, `id`, of more parents than the build numbers at once. */
|
|
320
|
+
const graphTooWide = (id, parents) => gitError("RESOURCE_EXHAUSTED", `The repo's commit ${hexOf(id)} has ${parents} parents, past the ${mostParents} the build numbers; fetches go on with the bounded walk`);
|
|
321
|
+
/**
|
|
322
|
+
* `input.graphs`' commits merged into the index graph at `input.key`. The first pass counts, the
|
|
323
|
+
* second writes the IDs, and each pass numbers the parents the one before it gathered, as many as
|
|
324
|
+
* `graphRefs` hold; then the generations, and the rest of the file.
|
|
325
|
+
*
|
|
326
|
+
* With `input.below`, it writes a layer: the commits a layer below holds are left out first, so
|
|
327
|
+
* the count, the bound and the numbers are this layer's own; its commits are numbered from
|
|
328
|
+
* `below.first`, and the parents a pass finds none of this layer's commits for, a commit left out
|
|
329
|
+
* among them, are looked up below in one batch.
|
|
330
|
+
*/
|
|
331
|
+
const writeIndexGraph = (input) => Effect.gen(function* () {
|
|
332
|
+
const { bucket, graphs, allotment, below } = input;
|
|
333
|
+
const refs = input.refs ?? 65536;
|
|
334
|
+
const base = below?.first ?? 0;
|
|
335
|
+
const missBytes = below === void 0 ? 0 : (refs + mostParents) * 32;
|
|
336
|
+
const refsBytes = 2 * (refs + mostParents) * 24 + writerBytes + graphs.length * graphReadBytes + missBytes;
|
|
337
|
+
const fanout = /* @__PURE__ */ new Uint32Array(256);
|
|
338
|
+
let commits = 0;
|
|
339
|
+
let octopus = 0;
|
|
340
|
+
let widest = 0;
|
|
341
|
+
let widestId = /* @__PURE__ */ new Uint8Array(20);
|
|
342
|
+
let firsts = /* @__PURE__ */ new Uint32Array(0);
|
|
343
|
+
let seconds = /* @__PURE__ */ new Uint32Array(0);
|
|
344
|
+
let table = /* @__PURE__ */ new Uint32Array(0);
|
|
345
|
+
let lasts = /* @__PURE__ */ new Uint8Array(0);
|
|
346
|
+
yield* allotment.grow(refsBytes);
|
|
347
|
+
let gathering = new ParentRefs(refs);
|
|
348
|
+
let pending;
|
|
349
|
+
let from = 0;
|
|
350
|
+
let started;
|
|
351
|
+
const missRoom = below === void 0 ? 0 : refs + mostParents;
|
|
352
|
+
const misses = new Uint32Array(missRoom);
|
|
353
|
+
const missIds = new Uint8Array(missRoom * 20);
|
|
354
|
+
const own = below === void 0 ? {
|
|
355
|
+
held: /* @__PURE__ */ new Uint32Array(0),
|
|
356
|
+
bytes: 0
|
|
357
|
+
} : yield* heldBelow(bucket, graphs, below, refs, allotment);
|
|
358
|
+
for (let pass = 0;; pass += 1) {
|
|
359
|
+
const resolving = pending;
|
|
360
|
+
const order = resolving === void 0 ? void 0 : orderById(resolving.ids, resolving.size);
|
|
361
|
+
let resolved = 0;
|
|
362
|
+
let missed = 0;
|
|
363
|
+
let end = -1;
|
|
364
|
+
let octopusAt = 0;
|
|
365
|
+
const numbered = (target, number) => {
|
|
366
|
+
if ((target & 2147483648) !== 0) {
|
|
367
|
+
const entry = target & 2147483647;
|
|
368
|
+
table[entry] = number;
|
|
369
|
+
} else if (target % 2 === 0) firsts[target / 2] = number;
|
|
370
|
+
else seconds[(target - 1) / 2] = number;
|
|
371
|
+
};
|
|
372
|
+
const resolveUpTo = (id, number) => {
|
|
373
|
+
if (resolving === void 0 || order === void 0) return;
|
|
374
|
+
while (resolved < order.length) {
|
|
375
|
+
const ref = order[resolved] ?? 0;
|
|
376
|
+
const compared = id === void 0 ? -1 : compareIds(resolving.ids, ref * 20, id, 0);
|
|
377
|
+
if (compared > 0) return;
|
|
378
|
+
if (compared === 0) numbered(resolving.targets[ref] ?? 0, base + number);
|
|
379
|
+
else if (below === void 0) numbered(resolving.targets[ref] ?? 0, none);
|
|
380
|
+
else {
|
|
381
|
+
misses[missed] = ref;
|
|
382
|
+
missed += 1;
|
|
383
|
+
}
|
|
384
|
+
resolved += 1;
|
|
385
|
+
}
|
|
386
|
+
};
|
|
387
|
+
const counted = yield* ownCommits(bucket, graphs, own.held, (number, commit) => {
|
|
388
|
+
const parents = commit.count;
|
|
389
|
+
const start = octopusAt;
|
|
390
|
+
if (parents > 2) octopusAt += parents - 1;
|
|
391
|
+
if (pass === 0) {
|
|
392
|
+
fanout[commit.id[0] ?? 0] = (fanout[commit.id[0] ?? 0] ?? 0) + 1;
|
|
393
|
+
if (parents > 2) octopus += parents - 1;
|
|
394
|
+
if (parents > widest) {
|
|
395
|
+
widest = parents;
|
|
396
|
+
widestId = commit.id.slice();
|
|
397
|
+
}
|
|
398
|
+
} else if (parents > 2) {
|
|
399
|
+
seconds[number] = octopusTarget(start);
|
|
400
|
+
lasts[start + parents - 2] = 1;
|
|
401
|
+
}
|
|
402
|
+
resolveUpTo(commit.id, number);
|
|
403
|
+
if (number >= from && end < 0 && parents <= 4096) {
|
|
404
|
+
if (gathering.size > 0 && gathering.size + parents > refs) end = number;
|
|
405
|
+
else for (let parent = 0; parent < parents; parent += 1) {
|
|
406
|
+
const target = parent === 0 ? firstSlot(number) : parents === 2 ? firstSlot(number) + 1 : octopusTarget(start + parent - 1);
|
|
407
|
+
gathering.add(commit.parents, parent * 20, target);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return pass === 1 && started !== void 0 ? started.out.push(commit.id) : void 0;
|
|
411
|
+
});
|
|
412
|
+
resolveUpTo(void 0, none);
|
|
413
|
+
if (below !== void 0 && resolving !== void 0 && missed > 0) {
|
|
414
|
+
for (let at = 0; at < missed; at += 1) {
|
|
415
|
+
const ref = misses[at] ?? 0;
|
|
416
|
+
missIds.set(resolving.ids.subarray(ref * 20, ref * 20 + 20), at * 20);
|
|
417
|
+
}
|
|
418
|
+
const found = yield* below.numbersOf(missIds, missed);
|
|
419
|
+
for (let at = 0; at < missed; at += 1) {
|
|
420
|
+
const number = found[at] ?? 4294967295;
|
|
421
|
+
if (number !== 4294967295 && number >= base) return yield* Effect.fail(lost(`The layers below named commit ${number}, past their ${base}`));
|
|
422
|
+
numbered(resolving.targets[misses[at] ?? 0] ?? 0, number === 4294967295 ? none : number);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (pass === 0) {
|
|
426
|
+
commits = counted;
|
|
427
|
+
const bytes = commits * 16 + octopus * 5;
|
|
428
|
+
if (bytes > input.most || base + commits >= mostCommits) return {
|
|
429
|
+
kind: "refused",
|
|
430
|
+
commits,
|
|
431
|
+
refusal: graphTooLarge(commits, bytes, input.most)
|
|
432
|
+
};
|
|
433
|
+
if (widest > 4096) return {
|
|
434
|
+
kind: "refused",
|
|
435
|
+
commits,
|
|
436
|
+
refusal: graphTooWide(widestId, widest)
|
|
437
|
+
};
|
|
438
|
+
yield* allotment.grow(bytes);
|
|
439
|
+
firsts = new Uint32Array(commits).fill(none);
|
|
440
|
+
seconds = new Uint32Array(commits).fill(none);
|
|
441
|
+
table = new Uint32Array(octopus).fill(none);
|
|
442
|
+
lasts = new Uint8Array(octopus);
|
|
443
|
+
started = yield* startGraph(bucket, input.key, commits, octopus, fanout);
|
|
444
|
+
} else if (counted !== commits) return yield* Effect.fail(lost("The repo's commit graphs changed while the index read them"));
|
|
445
|
+
pending = gathering.size === 0 ? void 0 : gathering;
|
|
446
|
+
gathering = new ParentRefs(refs);
|
|
447
|
+
from = end < 0 ? commits : end;
|
|
448
|
+
if (pass >= 1 && pending === void 0 && from >= commits) break;
|
|
449
|
+
}
|
|
450
|
+
if (started === void 0) return yield* Effect.die(/* @__PURE__ */ new Error("no put"));
|
|
451
|
+
const writer = started.out;
|
|
452
|
+
const lower = below === void 0 ? {
|
|
453
|
+
generationOf: () => 0,
|
|
454
|
+
bytes: 0
|
|
455
|
+
} : yield* generationsBelow(below, refs, allotment, firsts, seconds, table);
|
|
456
|
+
const generations = yield* generationsOf(firsts, seconds, table, lasts, base, lower.generationOf);
|
|
457
|
+
const row = /* @__PURE__ */ new Uint32Array(3);
|
|
458
|
+
for (let number = 0; number < commits; number += 1) {
|
|
459
|
+
row[0] = firsts[number] ?? 2147483647;
|
|
460
|
+
row[1] = seconds[number] ?? 2147483647;
|
|
461
|
+
row[2] = generations[number] ?? 0;
|
|
462
|
+
yield* writer.words(row);
|
|
463
|
+
}
|
|
464
|
+
yield* writer.words(table, (entry, at) => lasts[at] === 1 ? (entry | lastFlag) >>> 0 : entry);
|
|
465
|
+
yield* started.finish;
|
|
466
|
+
allotment.shrink(refsBytes + commits * 16 + octopus * 5 + lower.bytes + own.bytes);
|
|
467
|
+
return {
|
|
468
|
+
kind: "written",
|
|
469
|
+
commits,
|
|
470
|
+
octopus,
|
|
471
|
+
bytes: indexGraphBytes(commits, octopus)
|
|
472
|
+
};
|
|
473
|
+
}).pipe(Effect.scoped);
|
|
474
|
+
/** Each parent of commit `number`, as graph numbers, `none` for one the repo lacks. */
|
|
475
|
+
const parentsOf = (firsts, seconds, table, lasts, number, visit) => {
|
|
476
|
+
const first = firsts[number] ?? 2147483647;
|
|
477
|
+
if (first !== 2147483647 && !visit(first)) return;
|
|
478
|
+
const second = seconds[number] ?? 2147483647;
|
|
479
|
+
if (second === 2147483647) return;
|
|
480
|
+
if ((second & 2147483648) === 0) {
|
|
481
|
+
visit(second);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
for (let entry = second & 2147483647; entry < table.length; entry += 1) {
|
|
485
|
+
if (!visit(table[entry] ?? 2147483647)) return;
|
|
486
|
+
if (lasts[entry] === 1) return;
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
/**
|
|
490
|
+
* Each commit's generation: 1 for a root, else one more than its parents' most, by a walk with
|
|
491
|
+
* its own stack, so a long history needs no recursion. A cycle is `DATA_LOSS`. A layer's commits
|
|
492
|
+
* are numbered from `first`, and a parent below it has `generationBelow`'s generation.
|
|
493
|
+
*/
|
|
494
|
+
const generationsOf = (firsts, seconds, table, lasts, first, generationBelow) => Effect.suspend(() => {
|
|
495
|
+
const commits = firsts.length;
|
|
496
|
+
const generations = new Uint32Array(commits);
|
|
497
|
+
const walking = 4294967295;
|
|
498
|
+
const stack = new Uint32Array(commits);
|
|
499
|
+
for (let root = 0; root < commits; root += 1) {
|
|
500
|
+
if (generations[root] !== 0) continue;
|
|
501
|
+
let depth = 0;
|
|
502
|
+
stack[depth] = root;
|
|
503
|
+
depth += 1;
|
|
504
|
+
generations[root] = walking;
|
|
505
|
+
while (depth > 0) {
|
|
506
|
+
const top = stack[depth - 1] ?? 0;
|
|
507
|
+
let next = -1;
|
|
508
|
+
let cycle = false;
|
|
509
|
+
let most = 0;
|
|
510
|
+
parentsOf(firsts, seconds, table, lasts, top, (parent) => {
|
|
511
|
+
if (parent === 2147483647) return true;
|
|
512
|
+
if (parent < first) {
|
|
513
|
+
most = Math.max(most, generationBelow(parent));
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
const generation = generations[parent - first] ?? 0;
|
|
517
|
+
if (generation === walking) {
|
|
518
|
+
cycle = true;
|
|
519
|
+
return false;
|
|
520
|
+
}
|
|
521
|
+
if (generation === 0) {
|
|
522
|
+
next = parent - first;
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
most = Math.max(most, generation);
|
|
526
|
+
return true;
|
|
527
|
+
});
|
|
528
|
+
if (cycle) return Effect.fail(lost(`The repo's history has a cycle at commit ${top}`));
|
|
529
|
+
if (next >= 0) {
|
|
530
|
+
generations[next] = walking;
|
|
531
|
+
stack[depth] = next;
|
|
532
|
+
depth += 1;
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
generations[top] = most + 1;
|
|
536
|
+
depth -= 1;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return Effect.succeed(generations);
|
|
540
|
+
});
|
|
541
|
+
/**
|
|
542
|
+
* The generations of the parents a layer's rows name below it: each such number once, sorted,
|
|
543
|
+
* with its generation, asked of `below` `refs` at a time. It holds an entry for each parent below,
|
|
544
|
+
* never one for each commit below, charged to `allotment`; `bytes` is what to give back.
|
|
545
|
+
*/
|
|
546
|
+
const generationsBelow = (below, refs, allotment, firsts, seconds, table) => Effect.gen(function* () {
|
|
547
|
+
const each = (visit) => {
|
|
548
|
+
for (const words of [
|
|
549
|
+
firsts,
|
|
550
|
+
seconds,
|
|
551
|
+
table
|
|
552
|
+
]) for (const number of words) if (number < below.first) visit(number);
|
|
553
|
+
};
|
|
554
|
+
let count = 0;
|
|
555
|
+
each(() => {
|
|
556
|
+
count += 1;
|
|
557
|
+
});
|
|
558
|
+
const bytes = count * 8 + refs * 12;
|
|
559
|
+
yield* allotment.grow(bytes);
|
|
560
|
+
const numbers = new Uint32Array(count);
|
|
561
|
+
let filled = 0;
|
|
562
|
+
each((number) => {
|
|
563
|
+
numbers[filled] = number;
|
|
564
|
+
filled += 1;
|
|
565
|
+
});
|
|
566
|
+
numbers.sort();
|
|
567
|
+
let distinct = 0;
|
|
568
|
+
for (const number of numbers) if (distinct === 0 || numbers[distinct - 1] !== number) {
|
|
569
|
+
numbers[distinct] = number;
|
|
570
|
+
distinct += 1;
|
|
571
|
+
}
|
|
572
|
+
const held = numbers.subarray(0, distinct);
|
|
573
|
+
const generations = new Uint32Array(distinct);
|
|
574
|
+
for (let from = 0; from < distinct; from += refs) {
|
|
575
|
+
const batch = Array.from(held.subarray(from, Math.min(distinct, from + refs)));
|
|
576
|
+
const found = yield* below.generationsOf(batch);
|
|
577
|
+
if (found.length !== batch.length || found.includes(0)) return yield* Effect.fail(lost("The layers below didn't give their commits' generations"));
|
|
578
|
+
generations.set(found, from);
|
|
579
|
+
}
|
|
580
|
+
/** The generation of `number`, a parent below, by a binary search of the held numbers. */
|
|
581
|
+
const generationOf = (number) => {
|
|
582
|
+
let low = 0;
|
|
583
|
+
let high = distinct;
|
|
584
|
+
while (low < high) {
|
|
585
|
+
const middle = low + high >>> 1;
|
|
586
|
+
if ((held[middle] ?? 0) < number) low = middle + 1;
|
|
587
|
+
else high = middle;
|
|
588
|
+
}
|
|
589
|
+
return held[low] === number ? generations[low] ?? 0 : 0;
|
|
590
|
+
};
|
|
591
|
+
return {
|
|
592
|
+
generationOf,
|
|
593
|
+
bytes
|
|
594
|
+
};
|
|
595
|
+
});
|
|
596
|
+
/** Commits a chunked read of the graph takes at a time: 640 KiB of IDs. */
|
|
597
|
+
const graphChunk = 32768;
|
|
598
|
+
/** The index graph at `key`, opened: its header and fanout. A layer's commits start at `first`. */
|
|
599
|
+
const openIndexGraph = (bucket, key, first = 0) => Effect.gen(function* () {
|
|
600
|
+
const head = yield* readExactly(bucket, key, 0, 1040);
|
|
601
|
+
if (magic.some((byte, at) => head[at] !== byte) || word(head, 4) !== 1) return yield* Effect.fail(lost(`${key} isn't a version 1 graph`));
|
|
602
|
+
const commits = word(head, 8);
|
|
603
|
+
const octopus = word(head, 12);
|
|
604
|
+
const fanout = Uint32Array.from({ length: 256 }, (_, at) => word(head, 16 + at * 4));
|
|
605
|
+
if (fanout[255] !== commits || fanout.some((count, at) => count < (fanout[at - 1] ?? 0))) return yield* Effect.fail(lost(`${key}'s fanout lists ${fanout[255]}, not ${commits}`));
|
|
606
|
+
yield* readExactly(bucket, key, indexGraphBytes(commits, octopus) - 20, 20);
|
|
607
|
+
const ids = 1040;
|
|
608
|
+
const rows = ids + commits * 20;
|
|
609
|
+
const table = rows + commits * 12;
|
|
610
|
+
const end = first + commits;
|
|
611
|
+
const within = (number) => number >= first && number < end ? Effect.void : Effect.die(/* @__PURE__ */ new Error(`commit ${number} is outside ${key}'s ${first} to ${end - 1}`));
|
|
612
|
+
const rowFails = (one, two) => one !== 2147483647 && one >= end || two !== 2147483647 && ((two & 2147483648) === 0 ? two >= end : (two & 2147483647) >= octopus);
|
|
613
|
+
const lacks = (number) => lost(`${key}'s row ${number} names a commit it lacks`);
|
|
614
|
+
const numberOf = (id) => Effect.gen(function* () {
|
|
615
|
+
const byte = id[0] ?? 0;
|
|
616
|
+
const low = byte === 0 ? 0 : fanout[byte - 1] ?? 0;
|
|
617
|
+
const high = fanout[byte] ?? 0;
|
|
618
|
+
if (high <= low) return void 0;
|
|
619
|
+
const bucketIds = yield* readExactly(bucket, key, ids + low * 20, (high - low) * 20);
|
|
620
|
+
for (let at = 0; at < high - low; at += 1) if (compareIds(bucketIds, at * 20, id, 0) === 0) return first + low + at;
|
|
621
|
+
});
|
|
622
|
+
const idOf = (number) => Effect.andThen(within(number), readExactly(bucket, key, ids + (number - first) * 20, 20));
|
|
623
|
+
const entryOf = (number) => Effect.gen(function* () {
|
|
624
|
+
yield* within(number);
|
|
625
|
+
const row = yield* readExactly(bucket, key, rows + (number - first) * 12, 12);
|
|
626
|
+
const parents = [];
|
|
627
|
+
const one = word(row, 0);
|
|
628
|
+
const second = word(row, 4);
|
|
629
|
+
if (rowFails(one, second)) return yield* Effect.fail(lacks(number));
|
|
630
|
+
if (one !== 2147483647) parents.push(one);
|
|
631
|
+
if (second !== 2147483647 && (second & 2147483648) === 0) parents.push(second);
|
|
632
|
+
else if (second !== 2147483647) {
|
|
633
|
+
for (const parent of yield* listOf(second & 2147483647, lacks(number))) if (parent !== 2147483647) parents.push(parent);
|
|
634
|
+
}
|
|
635
|
+
return {
|
|
636
|
+
parents,
|
|
637
|
+
generation: word(row, 8)
|
|
638
|
+
};
|
|
639
|
+
});
|
|
640
|
+
/**
|
|
641
|
+
* The octopus list at `start` as the file holds it: each parent, `none` kept, its last flag
|
|
642
|
+
* dropped. One read covers any list, since none is longer than `mostParents`.
|
|
643
|
+
*/
|
|
644
|
+
const listOf = (start, failure) => Effect.gen(function* () {
|
|
645
|
+
const length = Math.min(mostParents, octopus - start);
|
|
646
|
+
const bytes = yield* readExactly(bucket, key, table + start * 4, length * 4);
|
|
647
|
+
const parents = [];
|
|
648
|
+
for (let at = 0; at < length; at += 1) {
|
|
649
|
+
const read = word(bytes, at * 4);
|
|
650
|
+
const parent = (read & 2147483647) >>> 0;
|
|
651
|
+
if (parent !== 2147483647 && parent >= end) return yield* Effect.fail(failure);
|
|
652
|
+
parents.push(parent);
|
|
653
|
+
if ((read & 2147483648) !== 0) return Uint32Array.from(parents);
|
|
654
|
+
}
|
|
655
|
+
return yield* Effect.fail(failure);
|
|
656
|
+
});
|
|
657
|
+
/** Rows `from` to `from + count - 1` of the file, 3 words each, each checked. */
|
|
658
|
+
const rowsAt = (from, count) => Effect.gen(function* () {
|
|
659
|
+
const bytes = yield* readExactly(bucket, key, rows + from * 12, count * 12);
|
|
660
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
661
|
+
const out = new Uint32Array(count * 3);
|
|
662
|
+
for (let at = 0; at < count * 3; at += 1) out[at] = view.getUint32(at * 4);
|
|
663
|
+
for (let at = 0; at < count; at += 1) if (rowFails(out[at * 3] ?? 0, out[at * 3 + 1] ?? 0)) return yield* Effect.fail(lacks(first + from + at));
|
|
664
|
+
return out;
|
|
665
|
+
});
|
|
666
|
+
const readRows = Effect.gen(function* () {
|
|
667
|
+
const out = new Uint32Array(commits * 3);
|
|
668
|
+
for (let from = 0; from < commits; from += graphChunk) {
|
|
669
|
+
const count = Math.min(graphChunk, commits - from);
|
|
670
|
+
out.set(yield* rowsAt(from, count), from * 3);
|
|
671
|
+
}
|
|
672
|
+
return out;
|
|
673
|
+
});
|
|
674
|
+
const commitsAt = (number, count) => Effect.gen(function* () {
|
|
675
|
+
yield* within(number);
|
|
676
|
+
yield* within(number + count - 1);
|
|
677
|
+
const from = number - first;
|
|
678
|
+
return {
|
|
679
|
+
ids: yield* readExactly(bucket, key, ids + from * 20, count * 20),
|
|
680
|
+
rows: yield* rowsAt(from, count)
|
|
681
|
+
};
|
|
682
|
+
});
|
|
683
|
+
const numbersOf = (wanted, count) => Effect.gen(function* () {
|
|
684
|
+
const order = orderById(wanted, count);
|
|
685
|
+
const out = new Uint32Array(count).fill(absent);
|
|
686
|
+
let next = 0;
|
|
687
|
+
for (let from = 0; from < commits && next < count; from += graphChunk) {
|
|
688
|
+
const length = Math.min(graphChunk, commits - from);
|
|
689
|
+
const chunk = yield* readExactly(bucket, key, ids + from * 20, length * 20);
|
|
690
|
+
let at = 0;
|
|
691
|
+
while (next < count && at < length) {
|
|
692
|
+
const each = order[next] ?? 0;
|
|
693
|
+
const compared = compareIds(wanted, each * 20, chunk, at * 20);
|
|
694
|
+
if (compared < 0) next += 1;
|
|
695
|
+
else if (compared > 0) at += 1;
|
|
696
|
+
else {
|
|
697
|
+
out[each] = first + from + at;
|
|
698
|
+
next += 1;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return out;
|
|
703
|
+
});
|
|
704
|
+
/**
|
|
705
|
+
* Each of `numbers`' `width` bytes in the table at `start`, from the chunks that hold them, to
|
|
706
|
+
* `visit` with its place in `numbers`, the chunk and where in it they are.
|
|
707
|
+
*/
|
|
708
|
+
const eachAt = (numbers, start, width, visit) => Effect.gen(function* () {
|
|
709
|
+
const order = [...numbers.keys()].sort((a, b) => (numbers[a] ?? 0) - (numbers[b] ?? 0));
|
|
710
|
+
let next = 0;
|
|
711
|
+
while (next < order.length) {
|
|
712
|
+
const number = numbers[order[next] ?? 0] ?? 0;
|
|
713
|
+
yield* within(number);
|
|
714
|
+
const local = number - first;
|
|
715
|
+
const from = local - local % graphChunk;
|
|
716
|
+
const length = Math.min(graphChunk, commits - from);
|
|
717
|
+
const chunk = yield* readExactly(bucket, key, start + from * width, length * width);
|
|
718
|
+
for (; next < order.length; next += 1) {
|
|
719
|
+
const place = order[next] ?? 0;
|
|
720
|
+
const at = (numbers[place] ?? 0) - first - from;
|
|
721
|
+
if (at >= length) break;
|
|
722
|
+
visit(place, chunk, at * width);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
const idsAt = (numbers) => {
|
|
727
|
+
const out = new Uint8Array(numbers.length * 20);
|
|
728
|
+
return Effect.as(eachAt(numbers, ids, 20, (place, chunk, at) => out.set(chunk.subarray(at, at + 20), place * 20)), out);
|
|
729
|
+
};
|
|
730
|
+
const generationsAt = (numbers) => {
|
|
731
|
+
const out = new Uint32Array(numbers.length);
|
|
732
|
+
return Effect.as(eachAt(numbers, rows, 12, (place, chunk, at) => {
|
|
733
|
+
out[place] = word(chunk, at + 8);
|
|
734
|
+
}), out);
|
|
735
|
+
};
|
|
736
|
+
return {
|
|
737
|
+
first,
|
|
738
|
+
commits,
|
|
739
|
+
octopus,
|
|
740
|
+
numberOf,
|
|
741
|
+
idOf,
|
|
742
|
+
entryOf,
|
|
743
|
+
rows: readRows,
|
|
744
|
+
rowsAt: (from, count) => Effect.andThen(Effect.andThen(within(from), count === 0 ? Effect.void : within(from + count - 1)), rowsAt(from - first, count)),
|
|
745
|
+
numbersOf,
|
|
746
|
+
idsAt,
|
|
747
|
+
generationsAt,
|
|
748
|
+
commitsAt,
|
|
749
|
+
octopusAt: (start) => start < octopus ? listOf(start, lost(`${key}'s octopus list at ${start} names a commit it lacks`)) : Effect.die(/* @__PURE__ */ new Error(`octopus entry ${start} is past ${key}'s ${octopus}`))
|
|
750
|
+
};
|
|
751
|
+
});
|
|
752
|
+
/**
|
|
753
|
+
* `graphs`, in layer order, read as one graph: each opened with its own `first`, the `first` of
|
|
754
|
+
* the one before it plus its commits. It holds nothing past what the layers' own reads hold.
|
|
755
|
+
*/
|
|
756
|
+
const openGraphLayers = (graphs) => {
|
|
757
|
+
const starts = [0];
|
|
758
|
+
for (const graph of graphs) starts.push((starts[starts.length - 1] ?? 0) + graph.commits);
|
|
759
|
+
const commits = starts[graphs.length] ?? 0;
|
|
760
|
+
const startOf = (upTo) => starts[Math.max(0, Math.min(upTo, graphs.length))] ?? 0;
|
|
761
|
+
const numbersAmong = (upTo) => (ids, count) => Effect.gen(function* () {
|
|
762
|
+
const out = new Uint32Array(count).fill(absent);
|
|
763
|
+
let left = count;
|
|
764
|
+
for (const graph of graphs.slice(0, upTo)) {
|
|
765
|
+
if (left === 0) break;
|
|
766
|
+
const found = yield* graph.numbersOf(ids, count);
|
|
767
|
+
for (let at = 0; at < count; at += 1) if (out[at] === 4294967295 && found[at] !== 4294967295) {
|
|
768
|
+
out[at] = found[at] ?? 4294967295;
|
|
769
|
+
left -= 1;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
return out;
|
|
773
|
+
});
|
|
774
|
+
/**
|
|
775
|
+
* `numbers`, each below the first `upTo` layers' end, split by the layer that holds them: each
|
|
776
|
+
* layer's part to `read`, with where in `numbers` each of the part was.
|
|
777
|
+
*/
|
|
778
|
+
const routed = (numbers, upTo, read) => Effect.gen(function* () {
|
|
779
|
+
const past = numbers.find((number) => !(number >= 0 && number < startOf(upTo)));
|
|
780
|
+
if (past !== void 0) return yield* Effect.die(/* @__PURE__ */ new Error(`commit ${past} is past the layers' ${startOf(upTo)}`));
|
|
781
|
+
for (const [layer, graph] of graphs.slice(0, upTo).entries()) {
|
|
782
|
+
const [low, high] = [startOf(layer), startOf(layer + 1)];
|
|
783
|
+
const places = [...numbers.keys()].filter((place) => (numbers[place] ?? 0) >= low && (numbers[place] ?? 0) < high);
|
|
784
|
+
if (places.length > 0) yield* read(graph, places.map((place) => numbers[place] ?? 0), places);
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
const idsAt = (numbers) => {
|
|
788
|
+
const out = new Uint8Array(numbers.length * 20);
|
|
789
|
+
const read = routed(numbers, graphs.length, (graph, part, places) => Effect.map(graph.idsAt(part), (found) => {
|
|
790
|
+
for (const [at, place] of places.entries()) out.set(found.subarray(at * 20, at * 20 + 20), place * 20);
|
|
791
|
+
}));
|
|
792
|
+
return Effect.as(read, out);
|
|
793
|
+
};
|
|
794
|
+
const generationsAmong = (upTo) => (numbers) => {
|
|
795
|
+
const out = new Uint32Array(numbers.length);
|
|
796
|
+
const read = routed(numbers, upTo, (graph, part, places) => Effect.map(graph.generationsAt(part), (found) => {
|
|
797
|
+
for (const [at, place] of places.entries()) out[place] = found[at] ?? 0;
|
|
798
|
+
}));
|
|
799
|
+
return Effect.as(read, out);
|
|
800
|
+
};
|
|
801
|
+
const entryOf = (number) => Effect.suspend(() => {
|
|
802
|
+
const layer = graphs.findIndex((_, at) => number < startOf(at + 1));
|
|
803
|
+
const graph = number >= 0 ? graphs[layer] : void 0;
|
|
804
|
+
return graph === void 0 ? Effect.die(/* @__PURE__ */ new Error(`commit ${number} is past the layers' ${commits}`)) : graph.entryOf(number);
|
|
805
|
+
});
|
|
806
|
+
const rows = Effect.gen(function* () {
|
|
807
|
+
const out = new Uint32Array(commits * 3);
|
|
808
|
+
for (const [layer, graph] of graphs.entries()) out.set(yield* graph.rows, startOf(layer) * 3);
|
|
809
|
+
return out;
|
|
810
|
+
});
|
|
811
|
+
return {
|
|
812
|
+
commits,
|
|
813
|
+
numbersOf: numbersAmong(graphs.length),
|
|
814
|
+
entryOf,
|
|
815
|
+
idsAt,
|
|
816
|
+
rows,
|
|
817
|
+
below: (upTo) => ({
|
|
818
|
+
first: startOf(upTo),
|
|
819
|
+
numbersOf: numbersAmong(upTo),
|
|
820
|
+
generationsOf: generationsAmong(upTo)
|
|
821
|
+
})
|
|
822
|
+
};
|
|
823
|
+
};
|
|
824
|
+
/** A layer's commits in ID order, a chunk of them held at a time. */
|
|
825
|
+
const layerCursor = (graph) => {
|
|
826
|
+
const empty = {
|
|
827
|
+
ids: /* @__PURE__ */ new Uint8Array(0),
|
|
828
|
+
rows: /* @__PURE__ */ new Uint32Array(0)
|
|
829
|
+
};
|
|
830
|
+
let held = empty;
|
|
831
|
+
let from = 0;
|
|
832
|
+
let length = 0;
|
|
833
|
+
let at = 0;
|
|
834
|
+
/** The commit at the head, its chunk read, or `undefined` once the layer has none left. */
|
|
835
|
+
const head = Effect.gen(function* () {
|
|
836
|
+
if (at === length) {
|
|
837
|
+
from += length;
|
|
838
|
+
at = 0;
|
|
839
|
+
length = Math.max(0, Math.min(graphChunk, graph.commits - from));
|
|
840
|
+
held = empty;
|
|
841
|
+
if (length === 0) return void 0;
|
|
842
|
+
held = yield* graph.commitsAt(graph.first + from, length);
|
|
843
|
+
}
|
|
844
|
+
return {
|
|
845
|
+
graph,
|
|
846
|
+
ids: held.ids,
|
|
847
|
+
offset: at * 20,
|
|
848
|
+
rows: held.rows,
|
|
849
|
+
row: at * 3,
|
|
850
|
+
number: graph.first + from + at
|
|
851
|
+
};
|
|
852
|
+
});
|
|
853
|
+
const advance = () => {
|
|
854
|
+
at += 1;
|
|
855
|
+
};
|
|
856
|
+
return {
|
|
857
|
+
head,
|
|
858
|
+
advance
|
|
859
|
+
};
|
|
860
|
+
};
|
|
861
|
+
/**
|
|
862
|
+
* Each commit of `graphs` in ID order, each ID once, to `each`: its merged number, the oldest
|
|
863
|
+
* layer's copy of it, and every layer's. It answers how many it gave.
|
|
864
|
+
*/
|
|
865
|
+
const eachMerged = (graphs, each) => Effect.gen(function* () {
|
|
866
|
+
const cursors = graphs.map(layerCursor);
|
|
867
|
+
for (let number = 0;; number += 1) {
|
|
868
|
+
const heads = [];
|
|
869
|
+
for (const cursor of cursors) {
|
|
870
|
+
const head = yield* cursor.head;
|
|
871
|
+
if (head !== void 0) heads.push({
|
|
872
|
+
head,
|
|
873
|
+
advance: cursor.advance
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
let least;
|
|
877
|
+
for (const { head } of heads) if (least === void 0 || compareIds(head.ids, head.offset, least.ids, least.offset) < 0) least = head;
|
|
878
|
+
if (least === void 0) return number;
|
|
879
|
+
const taken = least;
|
|
880
|
+
const holding = heads.filter(({ head }) => compareIds(head.ids, head.offset, taken.ids, taken.offset) === 0);
|
|
881
|
+
const step = each(number, taken, holding.map(({ head }) => head));
|
|
882
|
+
if (step !== void 0) yield* step;
|
|
883
|
+
for (const { advance } of holding) advance();
|
|
884
|
+
}
|
|
885
|
+
});
|
|
886
|
+
/** The octopus list of `head`'s commit, when it has one. */
|
|
887
|
+
const octopusOf = (head) => {
|
|
888
|
+
const second = head.rows[head.row + 1] ?? 2147483647;
|
|
889
|
+
return second !== 2147483647 && (second & 2147483648) !== 0 ? head.graph.octopusAt(second & 2147483647) : void 0;
|
|
890
|
+
};
|
|
891
|
+
/**
|
|
892
|
+
* What a merge of `layers` layers holds besides its map of 4 bytes a commit: each layer's chunk
|
|
893
|
+
* of IDs and rows, its rows as read and as words, an octopus list as read and as words, and the
|
|
894
|
+
* writer.
|
|
895
|
+
*/
|
|
896
|
+
const mergeHeldBytes = (layers) => layers * graphChunk * 44 + mostParents * 8 + writerBytes;
|
|
897
|
+
/**
|
|
898
|
+
* `input.graphs`, layers of one index, merged into one index graph at `input.key`, numbered from 0
|
|
899
|
+
* as `writeIndexGraph` numbers a whole one: every commit once in ID order, an ID two layers hold
|
|
900
|
+
* taken from the oldest, its parents renumbered, its octopus list carried and its generation kept.
|
|
901
|
+
* The first pass numbers the commits and counts them, the next three write the IDs, the rows and
|
|
902
|
+
* the octopus table. It holds each layer commit's merged number, 4 bytes each, and
|
|
903
|
+
* `mergeHeldBytes`, charged to `input.allotment`, and never a layer whole.
|
|
904
|
+
*/
|
|
905
|
+
const mergeIndexGraphs = (input) => Effect.gen(function* () {
|
|
906
|
+
const { bucket, graphs, key, allotment } = input;
|
|
907
|
+
let total = 0;
|
|
908
|
+
for (const graph of graphs) {
|
|
909
|
+
if (graph.first !== total) return yield* Effect.die(/* @__PURE__ */ new Error(`a layer starts at ${graph.first}, not ${total}`));
|
|
910
|
+
total += graph.commits;
|
|
911
|
+
}
|
|
912
|
+
const bytes = total * 4 + mergeHeldBytes(graphs.length);
|
|
913
|
+
yield* allotment.grow(bytes);
|
|
914
|
+
const merged = new Uint32Array(total);
|
|
915
|
+
const counts = /* @__PURE__ */ new Uint32Array(256);
|
|
916
|
+
let octopus = 0;
|
|
917
|
+
const commits = yield* eachMerged(graphs, (number, taken, holders) => {
|
|
918
|
+
for (const head of holders) merged[head.number] = number;
|
|
919
|
+
const byte = taken.ids[taken.offset] ?? 0;
|
|
920
|
+
counts[byte] = (counts[byte] ?? 0) + 1;
|
|
921
|
+
const list = octopusOf(taken);
|
|
922
|
+
return list === void 0 ? void 0 : Effect.map(list, (parents) => {
|
|
923
|
+
octopus += parents.length;
|
|
924
|
+
});
|
|
925
|
+
});
|
|
926
|
+
if (commits >= mostCommits) return yield* Effect.fail(gitError("RESOURCE_EXHAUSTED", `The index layers' ${commits} commits are past the ${mostCommits} a graph numbers`));
|
|
927
|
+
const started = yield* startGraph(bucket, key, commits, octopus, counts);
|
|
928
|
+
if ((yield* eachMerged(graphs, (_, taken) => started.out.push(taken.ids.subarray(taken.offset, taken.offset + 20)))) !== commits) return yield* Effect.fail(lost("The index layers changed while they were merged"));
|
|
929
|
+
const renumbered = (parent) => parent === 2147483647 ? none : merged[parent] ?? 2147483647;
|
|
930
|
+
const row = /* @__PURE__ */ new Uint32Array(3);
|
|
931
|
+
let tableAt = 0;
|
|
932
|
+
yield* eachMerged(graphs, (_, taken) => Effect.gen(function* () {
|
|
933
|
+
const list = octopusOf(taken);
|
|
934
|
+
row[0] = renumbered(taken.rows[taken.row] ?? 2147483647);
|
|
935
|
+
row[2] = taken.rows[taken.row + 2] ?? 0;
|
|
936
|
+
if (list === void 0) row[1] = renumbered(taken.rows[taken.row + 1] ?? 2147483647);
|
|
937
|
+
else {
|
|
938
|
+
row[1] = octopusTarget(tableAt);
|
|
939
|
+
tableAt += (yield* list).length;
|
|
940
|
+
}
|
|
941
|
+
yield* started.out.words(row);
|
|
942
|
+
}));
|
|
943
|
+
if (octopus > 0) yield* eachMerged(graphs, (_, taken) => {
|
|
944
|
+
const list = octopusOf(taken);
|
|
945
|
+
return list === void 0 ? void 0 : Effect.flatMap(list, (parents) => started.out.words(parents, (parent, at) => at === parents.length - 1 ? (renumbered(parent) | lastFlag) >>> 0 : renumbered(parent)));
|
|
946
|
+
});
|
|
947
|
+
yield* started.finish;
|
|
948
|
+
allotment.shrink(bytes);
|
|
949
|
+
return { commits };
|
|
950
|
+
}).pipe(Effect.scoped);
|
|
951
|
+
/**
|
|
952
|
+
* The `.graph` rows a commit walk reads over `graphs`, one layer's chunk of `graphChunk` commits at
|
|
953
|
+
* a time, keyed by the chunk's first number, `kept` of them kept, the least recently used let go
|
|
954
|
+
* first, and `checked` before each read. A commit's parents are its row's two, or an octopus's from
|
|
955
|
+
* its entry. What the kept chunks hold is the caller's to charge: `kept` × `graphChunk` × 12 B.
|
|
956
|
+
*/
|
|
957
|
+
const graphRows = (graphs, graph, kept, checked) => {
|
|
958
|
+
const rowChunks = /* @__PURE__ */ new Map();
|
|
959
|
+
const rowOf = (number) => Effect.gen(function* () {
|
|
960
|
+
const layer = graphs.find((each) => number >= each.first && number < each.first + each.commits);
|
|
961
|
+
if (layer === void 0) return yield* Effect.fail(lost(`Commit ${number} is past the graph's ${graph.commits}`));
|
|
962
|
+
const start = number - (number - layer.first) % graphChunk;
|
|
963
|
+
let rows = rowChunks.get(start);
|
|
964
|
+
if (rows === void 0) {
|
|
965
|
+
if (rowChunks.size >= kept) {
|
|
966
|
+
const [first] = rowChunks.keys();
|
|
967
|
+
if (first !== void 0) rowChunks.delete(first);
|
|
968
|
+
}
|
|
969
|
+
yield* checked;
|
|
970
|
+
rows = yield* layer.rowsAt(start, Math.min(graphChunk, layer.first + layer.commits - start));
|
|
971
|
+
} else rowChunks.delete(start);
|
|
972
|
+
rowChunks.set(start, rows);
|
|
973
|
+
const at = (number - start) * 3;
|
|
974
|
+
return [
|
|
975
|
+
rows[at] ?? 2147483647,
|
|
976
|
+
rows[at + 1] ?? 2147483647,
|
|
977
|
+
rows[at + 2] ?? 0
|
|
978
|
+
];
|
|
979
|
+
});
|
|
980
|
+
const parentsOf = (number) => Effect.gen(function* () {
|
|
981
|
+
const [first, second, generation] = yield* rowOf(number);
|
|
982
|
+
if (second !== 2147483647 && (second & 2147483648) !== 0) {
|
|
983
|
+
yield* checked;
|
|
984
|
+
return {
|
|
985
|
+
parents: (yield* graph.entryOf(number)).parents,
|
|
986
|
+
generation
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
const parents = [];
|
|
990
|
+
if (first !== 2147483647) parents.push(first);
|
|
991
|
+
if (second !== 2147483647) parents.push(second);
|
|
992
|
+
return {
|
|
993
|
+
parents,
|
|
994
|
+
generation
|
|
995
|
+
};
|
|
996
|
+
});
|
|
997
|
+
return {
|
|
998
|
+
rowOf,
|
|
999
|
+
parentsOf
|
|
1000
|
+
};
|
|
1001
|
+
};
|
|
1002
|
+
/** Commit numbers by generation, highest first: the walk Git's `everybody_uninteresting` keeps. */
|
|
1003
|
+
var ByGeneration = class {
|
|
1004
|
+
#numbers = [];
|
|
1005
|
+
#generations = [];
|
|
1006
|
+
get size() {
|
|
1007
|
+
return this.#numbers.length;
|
|
1008
|
+
}
|
|
1009
|
+
push(number, generation) {
|
|
1010
|
+
const numbers = this.#numbers;
|
|
1011
|
+
const generations = this.#generations;
|
|
1012
|
+
let at = numbers.length;
|
|
1013
|
+
numbers.push(number);
|
|
1014
|
+
generations.push(generation);
|
|
1015
|
+
while (at > 0) {
|
|
1016
|
+
const up = at - 1 >> 1;
|
|
1017
|
+
if ((generations[up] ?? 0) >= generation) break;
|
|
1018
|
+
numbers[at] = numbers[up] ?? 0;
|
|
1019
|
+
generations[at] = generations[up] ?? 0;
|
|
1020
|
+
at = up;
|
|
1021
|
+
}
|
|
1022
|
+
numbers[at] = number;
|
|
1023
|
+
generations[at] = generation;
|
|
1024
|
+
}
|
|
1025
|
+
pop() {
|
|
1026
|
+
const numbers = this.#numbers;
|
|
1027
|
+
const generations = this.#generations;
|
|
1028
|
+
const top = numbers[0] ?? 0;
|
|
1029
|
+
const number = numbers.pop() ?? 0;
|
|
1030
|
+
const generation = generations.pop() ?? 0;
|
|
1031
|
+
const size = numbers.length;
|
|
1032
|
+
if (size === 0) return top;
|
|
1033
|
+
let at = 0;
|
|
1034
|
+
for (;;) {
|
|
1035
|
+
const left = at * 2 + 1;
|
|
1036
|
+
if (left >= size) break;
|
|
1037
|
+
const right = left + 1;
|
|
1038
|
+
const larger = right < size && (generations[right] ?? 0) > (generations[left] ?? 0) ? right : left;
|
|
1039
|
+
if ((generations[larger] ?? 0) <= generation) break;
|
|
1040
|
+
numbers[at] = numbers[larger] ?? 0;
|
|
1041
|
+
generations[at] = generations[larger] ?? 0;
|
|
1042
|
+
at = larger;
|
|
1043
|
+
}
|
|
1044
|
+
numbers[at] = number;
|
|
1045
|
+
generations[at] = generation;
|
|
1046
|
+
return top;
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
export { ByGeneration, absent, gathered, graphChunk, graphReadBytes, graphRefs, graphRows, graphTooLarge, graphTooWide, indexGraphBytes, lastFlag, mergeHeldBytes, mergeIndexGraphs, mostParents, none, octopusFlag, openGraphLayers, openIndexGraph, writeIndexGraph };
|