@ref0/git 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access/private-refs.mjs +0 -2
- package/dist/auth/authorize.mjs +31 -24
- package/dist/auth/bridge.mjs +8 -8
- package/dist/auth/fences.d.mts +0 -1
- package/dist/auth/fences.mjs +1 -1
- package/dist/auth/grants.d.mts +0 -1
- package/dist/auth/grants.mjs +2 -2
- package/dist/auth/host-function.d.mts +1 -7
- package/dist/auth/host-function.mjs +38 -38
- package/dist/auth/identify.d.mts +0 -1
- package/dist/auth/identify.mjs +1 -1
- package/dist/auth/policy.d.mts +7 -4
- package/dist/auth/policy.mjs +13 -10
- package/dist/auth/token-rows.mjs +2 -5
- package/dist/auth/tokens-layer.d.mts +0 -2
- package/dist/auth/tokens-public.d.mts +3 -3
- package/dist/auth/tokens-public.mjs +4 -2
- package/dist/auth/tokens.d.mts +6 -1
- package/dist/auth/tokens.mjs +7 -1
- package/dist/client/client.d.mts +22 -15
- package/dist/client/client.mjs +31 -27
- package/dist/client/git-http.mjs +22 -5
- package/dist/client/local.mjs +1 -1
- package/dist/client/namespace.d.mts +2 -0
- package/dist/client/push-upload.d.mts +1 -0
- package/dist/client/push-upload.mjs +169 -2
- package/dist/client/remote-helper.mjs +2 -4
- package/dist/client/remote.mjs +37 -15
- package/dist/client/run-remote-helper.mjs +4 -4
- package/dist/client/transport.mjs +26 -19
- package/dist/contracts/actors.d.mts +57 -28
- package/dist/contracts/actors.mjs +38 -2
- package/dist/contracts/authorize.d.mts +21 -15
- package/dist/contracts/callers.mjs +40 -0
- package/dist/contracts/calls-spent.d.mts +2 -12
- package/dist/contracts/calls-spent.mjs +4 -5
- package/dist/contracts/client.d.mts +16 -9
- package/dist/contracts/events.d.mts +82 -14
- package/dist/contracts/events.mjs +35 -9
- package/dist/contracts/files.d.mts +42 -42
- package/dist/contracts/forks.d.mts +0 -24
- package/dist/contracts/git-hooks.d.mts +217 -0
- package/dist/contracts/git-hooks.mjs +3 -1
- package/dist/contracts/git.d.mts +13 -3
- package/dist/contracts/grants.d.mts +46 -27
- package/dist/contracts/lfs.d.mts +17 -4
- package/dist/contracts/merges.d.mts +7 -7
- package/dist/contracts/objects.d.mts +38 -4
- package/dist/contracts/opaque.mjs +19 -1
- package/dist/contracts/operations.d.mts +8 -1
- package/dist/contracts/operations.mjs +209 -0
- package/dist/contracts/queue.d.mts +6 -5
- package/dist/contracts/queue.mjs +9 -20
- package/dist/contracts/remote.d.mts +13 -4
- package/dist/contracts/remote.mjs +3 -3
- package/dist/contracts/repos.d.mts +11 -40
- package/dist/contracts/repos.mjs +11 -10
- package/dist/contracts/result.d.mts +28 -11
- package/dist/contracts/result.mjs +32 -2
- package/dist/contracts/rules.d.mts +706 -46
- package/dist/contracts/rules.mjs +81 -2
- package/dist/contracts/server.d.mts +5 -275
- package/dist/contracts/services.d.mts +0 -3
- package/dist/contracts/services.mjs +1 -3
- package/dist/contracts/signin.d.mts +2 -2
- package/dist/contracts/signin.mjs +4 -5
- package/dist/contracts/sync.d.mts +1 -4
- package/dist/contracts/tokens.d.mts +29 -17
- package/dist/contracts/tokens.mjs +14 -3
- package/dist/contracts/topics.d.mts +38 -11
- package/dist/contracts/topics.mjs +8 -2
- package/dist/core/access.d.mts +0 -2
- package/dist/core/access.mjs +15 -4
- package/dist/core/ancestry.mjs +5 -4
- package/dist/core/events/deliver.mjs +19 -1
- package/dist/core/forks.mjs +30 -11
- package/dist/core/hooks/groups.d.mts +0 -1
- package/dist/core/hooks/groups.mjs +8 -9
- package/dist/core/index-job.mjs +23 -1
- package/dist/core/index-lost.d.mts +11 -0
- package/dist/core/index-lost.mjs +55 -0
- package/dist/core/loose-tally.mjs +46 -0
- package/dist/core/objects/commit-writes.mjs +1 -1
- package/dist/core/objects/commits.mjs +10 -9
- package/dist/core/objects/merges.mjs +1 -1
- package/dist/core/objects/reading.mjs +28 -13
- package/dist/core/objects/trees.mjs +1 -1
- package/dist/core/objects/writing.mjs +1 -0
- package/dist/core/parts.d.mts +7 -0
- package/dist/core/promise.mjs +1 -15
- package/dist/core/publish.mjs +9 -5
- package/dist/core/purge.mjs +30 -12
- package/dist/core/push.mjs +39 -16
- package/dist/core/ref-view.mjs +14 -6
- package/dist/core/repack.mjs +54 -27
- package/dist/core/repo-info.mjs +8 -6
- package/dist/core/repos.mjs +1 -0
- package/dist/core/rules/check.mjs +10 -10
- package/dist/core/rules/context.d.mts +3 -1
- package/dist/core/rules/context.mjs +16 -13
- package/dist/core/rules/fetch.mjs +17 -23
- package/dist/core/tokens.mjs +2 -1
- package/dist/core/view.d.mts +10 -1
- package/dist/core/view.mjs +15 -6
- package/dist/effect.d.mts +3 -6
- package/dist/effect.mjs +3 -6
- package/dist/engine/commits.mjs +23 -50
- package/dist/engine/failures.d.mts +1 -2
- package/dist/engine/failures.mjs +1 -3
- package/dist/engine/merge-base-walk.mjs +57 -142
- package/dist/engine/merge-bases.mjs +9 -7
- package/dist/engine/merge.mjs +20 -17
- package/dist/engine/parts.d.mts +1 -0
- package/dist/engine/parts.mjs +1 -1
- package/dist/engine/walk.mjs +15 -11
- package/dist/extend.d.mts +1 -2
- package/dist/extend.mjs +1 -2
- package/dist/http/core-parts.mjs +18 -10
- package/dist/http/handler.mjs +11 -31
- package/dist/http/parts.d.mts +0 -1
- package/dist/index.d.mts +29 -22
- package/dist/index.mjs +5 -2
- package/dist/lfs/base.d.mts +6 -3
- package/dist/lfs/base.mjs +2 -1
- package/dist/lfs/layer.d.mts +4 -3
- package/dist/lfs/layer.mjs +23 -9
- package/dist/lfs/objects.mjs +93 -41
- package/dist/lfs/pointers.mjs +69 -18
- package/dist/lfs/purge.mjs +6 -2
- package/dist/lfs/rows.mjs +24 -7
- package/dist/lfs/service.d.mts +6 -3
- package/dist/lfs/service.mjs +8 -2
- package/dist/lfs/upkeep.mjs +47 -28
- package/dist/lfs/upload-most.mjs +47 -0
- package/dist/lfs/uploaded.mjs +59 -0
- package/dist/protocol/bytes/sha256-hasher.mjs +51 -0
- package/dist/protocol/bytes/streams.mjs +84 -2
- package/dist/protocol/bytes/text.mjs +6 -1
- package/dist/protocol/diff/read.d.mts +1 -0
- package/dist/protocol/diff/read.mjs +5 -2
- package/dist/protocol/objects/commit.d.mts +7 -0
- package/dist/protocol/objects/commit.mjs +5 -1
- package/dist/protocol/objects/fsck.mjs +6 -3
- package/dist/queue/advance.mjs +77 -18
- package/dist/queue/calls.mjs +4 -14
- package/dist/queue/host.d.mts +4 -0
- package/dist/queue/lanes.mjs +1 -1
- package/dist/queue/layer.mjs +4 -2
- package/dist/queue/limits.mjs +18 -2
- package/dist/queue/rows.mjs +10 -1
- package/dist/queue/schedule.mjs +1 -1
- package/dist/queue/search.mjs +3 -4
- package/dist/queue/trim.mjs +2 -2
- package/dist/rest/client-namespace.d.mts +2 -0
- package/dist/rest/client.d.mts +32 -8
- package/dist/rest/client.mjs +308 -382
- package/dist/rest/commits.d.mts +150 -150
- package/dist/rest/files.d.mts +18 -18
- package/dist/rest/forks.d.mts +77 -89
- package/dist/rest/handlers.mjs +2 -1
- package/dist/rest/listen.d.mts +8 -6
- package/dist/rest/listen.mjs +31 -75
- package/dist/rest/me.d.mts +2 -2
- package/dist/rest/merges.d.mts +7 -7
- package/dist/rest/refs.d.mts +27 -27
- package/dist/rest/repos.d.mts +40 -52
- package/dist/rest/tokens.d.mts +12 -12
- package/dist/rest/topics.d.mts +13 -13
- package/dist/rest/trees.d.mts +66 -66
- package/dist/rest/wire.d.mts +20 -2
- package/dist/rest/work.d.mts +39 -39
- package/dist/rest.d.mts +1 -7
- package/dist/rest.mjs +1 -5
- package/dist/server/git-layer.d.mts +10 -2
- package/dist/server/git-layer.mjs +29 -10
- package/dist/server/joined.d.mts +12 -6
- package/dist/server/joined.mjs +3 -2
- package/dist/server/registry.mjs +11 -5
- package/dist/server/server.d.mts +0 -1
- package/dist/server/server.mjs +42 -49
- package/dist/signin/context.d.mts +0 -1
- package/dist/signin/context.mjs +5 -9
- package/dist/storage/clean-up.mjs +3 -1
- package/dist/storage/fsck.mjs +12 -2
- package/dist/storage/graph-rebuild.mjs +262 -0
- package/dist/storage/index-bitmaps.mjs +16 -10
- package/dist/storage/index-build.mjs +160 -24
- package/dist/storage/index-graph.d.mts +1 -0
- package/dist/storage/index-graph.mjs +29 -5
- package/dist/storage/index-layers.d.mts +1 -0
- package/dist/storage/index-layers.mjs +5 -2
- package/dist/storage/index-reach.mjs +7 -5
- package/dist/storage/index-remap.mjs +5 -5
- package/dist/storage/index-visible.mjs +16 -5
- package/dist/storage/lfs-pointers.d.mts +5 -5
- package/dist/storage/lfs-pointers.mjs +37 -11
- package/dist/storage/links.mjs +3 -3
- package/dist/storage/loose.mjs +4 -1
- package/dist/storage/memory-budget.mjs +1 -1
- package/dist/storage/merge-fence.mjs +81 -19
- package/dist/storage/merge-most.mjs +1 -0
- package/dist/storage/merge-row.mjs +16 -4
- package/dist/storage/merge-stream.mjs +9 -6
- package/dist/storage/object-rows.mjs +17 -1
- package/dist/storage/pack-order.d.mts +1 -0
- package/dist/storage/pack-order.mjs +18 -1
- package/dist/storage/pack-receive.mjs +10 -6
- package/dist/storage/packs.mjs +58 -27
- package/dist/storage/prune-walk.mjs +5 -2
- package/dist/storage/prune.mjs +168 -70
- package/dist/storage/ready.d.mts +1 -1
- package/dist/storage/ready.mjs +12 -3
- package/dist/storage/receive-bounds.mjs +3 -2
- package/dist/storage/receive-state.mjs +1 -1
- package/dist/storage/repack-contained.mjs +22 -14
- package/dist/storage/repack.d.mts +1 -1
- package/dist/storage/repack.mjs +3 -2
- package/dist/storage/unpack.mjs +7 -0
- package/dist/storage/visible.mjs +3 -2
- package/dist/storage/walk.d.mts +1 -0
- package/dist/storage/walk.mjs +9 -5
- package/dist/storage/wants.mjs +17 -11
- package/dist/store/call-count.d.mts +31 -3
- package/dist/store/call-count.mjs +51 -20
- package/dist/store/errors.d.mts +7 -1
- package/dist/store/errors.mjs +7 -1
- package/dist/store/job-try.mjs +3 -1
- package/dist/store/records.mjs +26 -5
- package/dist/store/repo-record.mjs +36 -12
- package/dist/store/scopes.mjs +15 -2
- package/dist/sync/bound.d.mts +1 -1
- package/dist/sync/import.mjs +15 -3
- package/dist/sync/layer.d.mts +5 -1
- package/dist/sync/layer.mjs +11 -9
- package/dist/sync/mirror.mjs +1 -1
- package/dist/sync/step.mjs +15 -15
- package/dist/topics/advance.mjs +11 -10
- package/dist/topics/layer.mjs +1 -1
- package/dist/topics/members.mjs +38 -9
- package/package.json +3 -3
- package/dist/engine/merge-base-walk.d.mts +0 -3
- package/dist/server/routes.d.mts +0 -32
- package/dist/server/routes.mjs +0 -69
- package/dist/sync/bridge.d.mts +0 -6
- package/dist/sync/bridge.mjs +0 -29
package/dist/lfs/upkeep.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bucketDo } from "../storage/calls.mjs";
|
|
2
2
|
import { decodeRow } from "../store/errors.mjs";
|
|
3
|
-
import { EndingRow, ListedRow, StagingRow, UploadRow, endingKey, lfsCollections, listedRead, objectKey,
|
|
3
|
+
import { EndingRow, ListedRow, StagingRow, UploadRow, endingKey, lfsCollections, listedRead, objectKey, uploadOid } from "./rows.mjs";
|
|
4
|
+
import { uploadedSweepOf, uploadedSweepRead } from "./uploaded.mjs";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
6
|
// src/lfs/upkeep.ts
|
|
6
7
|
/**
|
|
@@ -13,7 +14,7 @@ import * as Effect from "effect/Effect";
|
|
|
13
14
|
* lists it again, and an upload after gets a key of its own. A delete that lands late, after a try
|
|
14
15
|
* that sent it timed out, reaches only bytes no listing names. A key is deleted before the row
|
|
15
16
|
* that names it is dropped, so a crash between leaves the row, and the next step deletes the key
|
|
16
|
-
* again.
|
|
17
|
+
* again. Own uploads go once their days are past, as receipts do.
|
|
17
18
|
*/
|
|
18
19
|
/** The most rows of each kind a step ends. */
|
|
19
20
|
const upkeepPage = 500;
|
|
@@ -21,28 +22,34 @@ const upkeepPage = 500;
|
|
|
21
22
|
* LFS's registration's upkeep over its `rows` and `bucket`'s objects: `bucket` charges each call, and
|
|
22
23
|
* `signed` says the host signs LFS's links, so its uploads have upload rows to end.
|
|
23
24
|
*/
|
|
24
|
-
const lfsUpkeep = (rows, bucket, signed) => ({ repo, at }) => upkeepStep({
|
|
25
|
+
const lfsUpkeep = (rows, bucket, signed) => ({ repo, at, deleted }) => upkeepStep({
|
|
25
26
|
rows,
|
|
26
27
|
bucket,
|
|
27
28
|
signed,
|
|
28
29
|
repo,
|
|
29
|
-
at
|
|
30
|
+
at,
|
|
31
|
+
deleted
|
|
30
32
|
});
|
|
31
33
|
const did = { more: true };
|
|
32
34
|
const earliest = (a, b) => a === void 0 ? b : b === void 0 ? a : Math.min(a, b);
|
|
33
35
|
/**
|
|
34
|
-
* One step: the ending rows, else the due staging rows, else the due upload rows
|
|
35
|
-
* and answers `more`; with nothing due, it answers when
|
|
36
|
+
* One step: the ending rows, else the due staging rows, else the due upload rows, else the own
|
|
37
|
+
* uploads past their days. Each does a page and answers `more`; with nothing due, it answers when
|
|
38
|
+
* the soonest row is.
|
|
36
39
|
*/
|
|
37
40
|
const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
38
|
-
const snapshot = yield* upkeep.rows.read(upkeep.repo, [
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
const snapshot = yield* upkeep.rows.read(upkeep.repo, [
|
|
42
|
+
{
|
|
43
|
+
collection: lfsCollections.ending,
|
|
44
|
+
limit: upkeepPage
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
collection: lfsCollections.staging,
|
|
48
|
+
limit: upkeepPage
|
|
49
|
+
},
|
|
50
|
+
uploadedSweepRead
|
|
51
|
+
]);
|
|
52
|
+
const [ending = [], staging = [], uploaded = []] = snapshot.results;
|
|
46
53
|
const endings = yield* Effect.forEach(ending, (row) => Effect.map(decodeRow(EndingRow, row, `LFS ending row ${row.id}`), (decoded) => ({
|
|
47
54
|
id: row.id,
|
|
48
55
|
...decoded
|
|
@@ -55,8 +62,13 @@ const upkeepStep = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
|
55
62
|
const dueStages = stages.filter((stage) => stage.removeAt <= upkeep.at);
|
|
56
63
|
if (dueStages.length > 0) return yield* endStages(upkeep, snapshot.version, dueStages);
|
|
57
64
|
const uploads = yield* dueUploads(upkeep);
|
|
58
|
-
if (uploads.
|
|
59
|
-
const
|
|
65
|
+
if (uploads.ids.length > 0) return yield* endUploads(upkeep, uploads.ids);
|
|
66
|
+
const sweep = upkeep.deleted ? void 0 : uploadedSweepOf(uploaded, upkeep.at);
|
|
67
|
+
if (sweep !== void 0 && sweep.delete.length > 0) {
|
|
68
|
+
yield* upkeep.rows.commit(upkeep.repo, snapshot.version, { delete: sweep.delete });
|
|
69
|
+
return did;
|
|
70
|
+
}
|
|
71
|
+
const due = stages.map((stage) => stage.removeAt).reduce(earliest, earliest(uploads.next, sweep?.due));
|
|
60
72
|
return due === void 0 ? { more: false } : {
|
|
61
73
|
more: false,
|
|
62
74
|
due
|
|
@@ -86,9 +98,9 @@ const endStages = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, version,
|
|
|
86
98
|
})) });
|
|
87
99
|
return did;
|
|
88
100
|
});
|
|
89
|
-
/** Up to a page of the upload rows that are due, and when the soonest of the rest is. */
|
|
101
|
+
/** Up to a page of the upload rows that are due, by ID, and when the soonest of the rest is. */
|
|
90
102
|
const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
91
|
-
const
|
|
103
|
+
const ids = [];
|
|
92
104
|
let next;
|
|
93
105
|
let after;
|
|
94
106
|
for (;;) {
|
|
@@ -103,11 +115,11 @@ const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
|
103
115
|
for (const row of rows) {
|
|
104
116
|
const upload = yield* uploadOf(row);
|
|
105
117
|
if (upload.removeAt > upkeep.at) next = earliest(next, upload.removeAt);
|
|
106
|
-
else if (
|
|
118
|
+
else if (ids.length < upkeepPage) ids.push(row.id);
|
|
107
119
|
}
|
|
108
120
|
after = rows.at(-1)?.id;
|
|
109
121
|
if (rows.length < upkeepPage || after === void 0) return {
|
|
110
|
-
|
|
122
|
+
ids,
|
|
111
123
|
next
|
|
112
124
|
};
|
|
113
125
|
}
|
|
@@ -115,20 +127,24 @@ const dueUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep) {
|
|
|
115
127
|
const uploadOf = (row) => decodeRow(UploadRow, row, `LFS object ${row.id}'s upload`);
|
|
116
128
|
const listedOf = (row) => decodeRow(ListedRow, row, `LFS object ${row.id}`);
|
|
117
129
|
/**
|
|
118
|
-
* Drops each due upload row, read again at one version. On a signed bucket, an object
|
|
119
|
-
* unlisted, or listed at another key,
|
|
120
|
-
* Worker's bytes are at staging keys, which their own rows end.
|
|
130
|
+
* Drops each due upload row, by its ID, read again at one version. On a signed bucket, an object
|
|
131
|
+
* still unlisted, or listed at another key, as another uploader's bytes are, gets its ending row in
|
|
132
|
+
* the same commit, then its bytes go; a Worker's bytes are at staging keys, which their own rows end.
|
|
121
133
|
*/
|
|
122
|
-
const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep,
|
|
123
|
-
const snapshot = yield* upkeep.rows.read(upkeep.repo,
|
|
134
|
+
const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, ids) {
|
|
135
|
+
const snapshot = yield* upkeep.rows.read(upkeep.repo, ids.flatMap((id) => [{
|
|
136
|
+
collection: lfsCollections.uploads,
|
|
137
|
+
id
|
|
138
|
+
}, listedRead(uploadOid(id))]));
|
|
124
139
|
const dropped = [];
|
|
125
140
|
const ended = [];
|
|
126
|
-
for (const [index,
|
|
141
|
+
for (const [index, id] of ids.entries()) {
|
|
142
|
+
const oid = uploadOid(id);
|
|
127
143
|
const uploadRow = snapshot.results[index * 2]?.[0];
|
|
128
144
|
const listedRow = snapshot.results[index * 2 + 1]?.[0];
|
|
129
145
|
const upload = uploadRow === void 0 ? void 0 : yield* uploadOf(uploadRow);
|
|
130
146
|
if (upload === void 0 || upload.removeAt > upkeep.at) continue;
|
|
131
|
-
dropped.push(
|
|
147
|
+
dropped.push(id);
|
|
132
148
|
const key = objectKey(upkeep.repo, oid, upload.generation);
|
|
133
149
|
const listed = listedRow === void 0 ? void 0 : yield* listedOf(listedRow);
|
|
134
150
|
if (upkeep.signed && listed?.key !== key) ended.push({
|
|
@@ -143,7 +159,10 @@ const endUploads = /* @__PURE__ */ Effect.fnUntraced(function* (upkeep, oids) {
|
|
|
143
159
|
id,
|
|
144
160
|
value: { key }
|
|
145
161
|
})),
|
|
146
|
-
delete: dropped.map(
|
|
162
|
+
delete: dropped.map((id) => ({
|
|
163
|
+
collection: lfsCollections.uploads,
|
|
164
|
+
id
|
|
165
|
+
}))
|
|
147
166
|
});
|
|
148
167
|
if (!committed.ok || ended.length === 0) return did;
|
|
149
168
|
return yield* endObjects(upkeep, committed.version, ended);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { largestObject } from "./rows.mjs";
|
|
2
|
+
// src/lfs/upload-most.ts
|
|
3
|
+
/**
|
|
4
|
+
* The largest Git LFS upload through the server, `workerUploadMost`, for a bucket that signs no
|
|
5
|
+
* links: the least of what the platform's body cap passes on, what its CPU cap lets the upload
|
|
6
|
+
* hash and store, and `largestObject`. A larger one is refused before a byte streams, at the
|
|
7
|
+
* batch, so git-lfs never starts it.
|
|
8
|
+
*/
|
|
9
|
+
/** The share of a request's CPU an upload may spend: the rest is its rows', its put's and the runtime's. */
|
|
10
|
+
const cpuShare = .8;
|
|
11
|
+
/**
|
|
12
|
+
* The bytes an upload through a Worker gathers from its body's chunks before each goes on to its
|
|
13
|
+
* hash and its put, since a client's body reaches a Worker in chunks of at most 4,096 B, each
|
|
14
|
+
* paid for once over (run 46342279485, #2296): one piece an upload, held as it streams.
|
|
15
|
+
*/
|
|
16
|
+
const uploadPieceBytes = 1024 ** 2;
|
|
17
|
+
/** The bytes `cpuMs` of CPU hashes and stores, at `uploadMsPerMiB` within `cpuShare` of it. */
|
|
18
|
+
const cpuBytes = (cpuMs) => Math.floor(cpuShare * cpuMs / 64 * 1024 ** 2);
|
|
19
|
+
/** The largest upload `caps` let finish: `largestObject` where neither binds below it. */
|
|
20
|
+
const uploadMostOf = (caps) => {
|
|
21
|
+
const bounds = [{
|
|
22
|
+
bytes: largestObject,
|
|
23
|
+
by: "object"
|
|
24
|
+
}];
|
|
25
|
+
if (caps.bodyCap !== void 0) bounds.push({
|
|
26
|
+
bytes: caps.bodyCap,
|
|
27
|
+
by: "body"
|
|
28
|
+
});
|
|
29
|
+
if (caps.cpuMs !== void 0) bounds.push({
|
|
30
|
+
bytes: cpuBytes(caps.cpuMs),
|
|
31
|
+
by: "cpu"
|
|
32
|
+
});
|
|
33
|
+
return bounds.reduce((least, bound) => bound.bytes < least.bytes ? bound : least);
|
|
34
|
+
};
|
|
35
|
+
/** Why `caps` aren't caps: each must be a whole number of bytes or milliseconds above 0. */
|
|
36
|
+
const capsRefusal = (caps) => {
|
|
37
|
+
for (const [name, value] of Object.entries(caps)) if (value !== void 0 && !(Number.isSafeInteger(value) && value > 0)) return `An LFS upload's ${name} is a whole number above 0, not ${String(value)}`;
|
|
38
|
+
};
|
|
39
|
+
/** What each cap that sets the largest upload is, as a refusal names it. */
|
|
40
|
+
const setBy = {
|
|
41
|
+
body: "the largest body its platform passes on",
|
|
42
|
+
cpu: "what its CPU cap lets it hash and store",
|
|
43
|
+
object: "R2's largest single put"
|
|
44
|
+
};
|
|
45
|
+
/** Why an upload of more than `most` is refused, and what takes it. */
|
|
46
|
+
const pastMost = (most) => `An upload through this server is at most ${most.bytes} bytes, ${setBy[most.by]}: a bucket that signs its links takes a larger one straight`;
|
|
47
|
+
export { capsRefusal, cpuShare, pastMost, uploadMostOf, uploadPieceBytes };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { dayMs, dayOf, sweepOf } from "../core/receipts.mjs";
|
|
2
|
+
import { decodeRow } from "../store/errors.mjs";
|
|
3
|
+
import { lfsCollections, uploadedKept } from "./rows.mjs";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
// src/lfs/uploaded.ts
|
|
7
|
+
/**
|
|
8
|
+
* A caller's own upload: an object whose bytes it sent, checked against the oid, which its pushes'
|
|
9
|
+
* pointers may name for `uploadedKept` after, though no ref it sees reaches the object yet. So a
|
|
10
|
+
* caller who sees only some refs proves it holds an object's bytes by sending them, and the
|
|
11
|
+
* pointer rule never takes a hidden object's oid alone as proof (#1943). Only the caller's writer,
|
|
12
|
+
* `ownWriter`'s SHA-256 of its actor's ID, names it, so the row's ID is one length; an anonymous
|
|
13
|
+
* caller keeps none.
|
|
14
|
+
*/
|
|
15
|
+
const UploadedRow = /* @__PURE__ */ Schema.Struct({ at: Schema.Int });
|
|
16
|
+
/** An own upload's ID: its day, padded so the oldest read first, its writer and its oid. */
|
|
17
|
+
const uploadedId = (at, writer, oid) => `${dayOf(at)}:${writer}:${oid}`;
|
|
18
|
+
/** The row a verified upload of `oid` by `writer` at `at` puts, in its commit. */
|
|
19
|
+
const uploadedRow = (writer, oid, at) => ({
|
|
20
|
+
collection: lfsCollections.uploaded,
|
|
21
|
+
id: uploadedId(at, writer, oid),
|
|
22
|
+
value: { at }
|
|
23
|
+
});
|
|
24
|
+
/**
|
|
25
|
+
* Which of `oids` `writer` uploaded to `repo` within `uploadedKept` before `at`: one read of each
|
|
26
|
+
* one's rows from today and yesterday, at most `sweepPage` oids a read.
|
|
27
|
+
*/
|
|
28
|
+
const uploadedOf = /* @__PURE__ */ Effect.fnUntraced(function* (rows, repo, writer, oids, at) {
|
|
29
|
+
const days = [at, at - dayMs];
|
|
30
|
+
const own = /* @__PURE__ */ new Set();
|
|
31
|
+
for (let from = 0; from < oids.length; from += 500) {
|
|
32
|
+
const chunk = oids.slice(from, from + 500);
|
|
33
|
+
const reads = chunk.flatMap((oid) => days.map((day) => ({
|
|
34
|
+
collection: lfsCollections.uploaded,
|
|
35
|
+
id: uploadedId(day, writer, oid)
|
|
36
|
+
})));
|
|
37
|
+
const snapshot = yield* rows.read(repo, reads);
|
|
38
|
+
for (const [index, found] of snapshot.results.entries()) {
|
|
39
|
+
const oid = chunk[Math.floor(index / days.length)];
|
|
40
|
+
for (const row of found) {
|
|
41
|
+
const upload = yield* decodeRow(UploadedRow, row, `LFS upload '${row.id}'`);
|
|
42
|
+
if (oid !== void 0 && at < upload.at + uploadedKept) own.add(oid);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return own;
|
|
47
|
+
});
|
|
48
|
+
/** What LFS's upkeep reads to sweep own uploads: the oldest first. */
|
|
49
|
+
const uploadedSweepRead = {
|
|
50
|
+
collection: lfsCollections.uploaded,
|
|
51
|
+
limit: 500
|
|
52
|
+
};
|
|
53
|
+
const uploadedKey = (id) => [{
|
|
54
|
+
collection: lfsCollections.uploaded,
|
|
55
|
+
id
|
|
56
|
+
}];
|
|
57
|
+
/** A sweep of own uploads, of `rows` read by `uploadedSweepRead`: those whose days are past at `at`. */
|
|
58
|
+
const uploadedSweepOf = (rows, at) => sweepOf(rows, at, uploadedKey);
|
|
59
|
+
export { UploadedRow, uploadedOf, uploadedRow, uploadedSweepOf, uploadedSweepRead };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { hexOf } from "./hex.mjs";
|
|
2
|
+
import { Sha256 } from "./sha256.mjs";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Exit from "effect/Exit";
|
|
5
|
+
// src/protocol/bytes/sha256-hasher.ts
|
|
6
|
+
const platform = globalThis;
|
|
7
|
+
/** This runtime's hashes. */
|
|
8
|
+
const runtime = {
|
|
9
|
+
DigestStream: platform.crypto?.DigestStream,
|
|
10
|
+
createHash: platform.process?.getBuiltinModule?.("node:crypto").createHash
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A `Sha256Hasher` through the first hash `on` has: `DigestStream`, whose writes are each awaited
|
|
14
|
+
* so that it holds none of the body's bytes, then `createHash`, then `Sha256`. Its sum is read once.
|
|
15
|
+
*
|
|
16
|
+
* A `DigestStream`'s writer is held only while one of its Effects runs, and let go however that
|
|
17
|
+
* ends: a hasher dropped between them, as by an upload whose put failed, locks nothing. One
|
|
18
|
+
* interrupted at a write or its sum is aborted, without waiting, and is done.
|
|
19
|
+
*/
|
|
20
|
+
const sha256HasherOn = (on) => {
|
|
21
|
+
if (on.DigestStream !== void 0) {
|
|
22
|
+
const stream = new on.DigestStream("SHA-256");
|
|
23
|
+
stream.digest.catch(() => void 0);
|
|
24
|
+
/** `use` on the stream's writer, taken for it alone, the stream aborted if it's interrupted. */
|
|
25
|
+
const held = (use) => Effect.acquireUseRelease(Effect.sync(() => stream.getWriter()), (writer) => Effect.promise(() => use(writer)), (writer, exit) => Effect.sync(() => {
|
|
26
|
+
writer.releaseLock();
|
|
27
|
+
if (Exit.hasInterrupts(exit)) stream.abort().catch(() => void 0);
|
|
28
|
+
}));
|
|
29
|
+
return {
|
|
30
|
+
write: (bytes) => held((writer) => writer.write(bytes)),
|
|
31
|
+
hex: held((writer) => writer.close().then(() => stream.digest.then((sum) => hexOf(new Uint8Array(sum)))))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (on.createHash !== void 0) {
|
|
35
|
+
const hash = on.createHash("sha256");
|
|
36
|
+
return {
|
|
37
|
+
write: (bytes) => Effect.sync(() => {
|
|
38
|
+
hash.update(bytes);
|
|
39
|
+
}),
|
|
40
|
+
hex: Effect.sync(() => hash.digest("hex"))
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const sha = new Sha256();
|
|
44
|
+
return {
|
|
45
|
+
write: (bytes) => Effect.sync(() => sha.update(bytes)),
|
|
46
|
+
hex: Effect.sync(() => sha.hex())
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/** A `Sha256Hasher` through this runtime's own hash, or `Sha256` where it has none. */
|
|
50
|
+
const nativeSha256Hasher = () => sha256HasherOn(runtime);
|
|
51
|
+
export { nativeSha256Hasher, sha256HasherOn };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// src/protocol/bytes/streams.ts
|
|
2
|
+
/** Refuses a `piece` under 1 byte, or not a whole number, since its stream would never reach the end. */
|
|
3
|
+
const wholePiece = (piece) => {
|
|
4
|
+
if (!Number.isSafeInteger(piece) || piece < 1) throw new RangeError(`a stream's pieces hold a whole number of bytes, at least 1, not ${piece}`);
|
|
5
|
+
};
|
|
2
6
|
/**
|
|
3
7
|
* `bytes` as a stream read once, in pieces of at most `piece` bytes: one piece by default. Each
|
|
4
8
|
* smaller piece is a copy, made when its reader asks for it, so a reader that holds a piece's
|
|
@@ -6,7 +10,7 @@
|
|
|
6
10
|
* byte, or not a whole number, is refused, since it would never reach the end.
|
|
7
11
|
*/
|
|
8
12
|
const streamOf = (bytes, piece = Math.max(1, bytes.length)) => {
|
|
9
|
-
|
|
13
|
+
wholePiece(piece);
|
|
10
14
|
if (piece >= bytes.length) return new ReadableStream({ start: (controller) => {
|
|
11
15
|
controller.enqueue(bytes);
|
|
12
16
|
controller.close();
|
|
@@ -18,4 +22,82 @@ const streamOf = (bytes, piece = Math.max(1, bytes.length)) => {
|
|
|
18
22
|
if (at >= bytes.length) controller.close();
|
|
19
23
|
} });
|
|
20
24
|
};
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* `body` gathered into pieces, each `pieceAt(given)` bytes, `given` the bytes it has handed on,
|
|
27
|
+
* its last smaller, each copied from its chunks as they come, so code that pays for each chunk pays
|
|
28
|
+
* once a piece: a client's body reaches a deployed Worker in chunks of at most 4,096 B (run
|
|
29
|
+
* 46342279485, #2296). A chunk of a piece's bytes or more, or what's left of one, that comes with
|
|
30
|
+
* nothing gathered goes on as it is, uncopied. It's read only as its reader asks, so it holds at
|
|
31
|
+
* most the piece it gathers and the rest of the chunk that filled the last, and it lets go of
|
|
32
|
+
* `body` once it ends, fails or is cancelled, a cancel reaching it. A piece under 1 byte, or not a
|
|
33
|
+
* whole number, fails the stream.
|
|
34
|
+
*/
|
|
35
|
+
const gathered = (body, pieceAt) => {
|
|
36
|
+
const reader = body.getReader();
|
|
37
|
+
let rest;
|
|
38
|
+
let given = 0;
|
|
39
|
+
/** Lets go of `body`, which a reader still waiting on it may already have. */
|
|
40
|
+
const release = () => {
|
|
41
|
+
try {
|
|
42
|
+
reader.releaseLock();
|
|
43
|
+
} catch {}
|
|
44
|
+
};
|
|
45
|
+
/** The next piece's bytes, gathered from as many chunks as it takes, or `body`'s end. */
|
|
46
|
+
const next = async (controller) => {
|
|
47
|
+
const piece = pieceAt(given);
|
|
48
|
+
wholePiece(piece);
|
|
49
|
+
let gathering;
|
|
50
|
+
let filled = 0;
|
|
51
|
+
/** `bytes` handed on as the next piece, counted. */
|
|
52
|
+
const hand = (bytes) => {
|
|
53
|
+
given += bytes.length;
|
|
54
|
+
controller.enqueue(bytes);
|
|
55
|
+
};
|
|
56
|
+
for (;;) {
|
|
57
|
+
const read = rest === void 0 ? await reader.read() : {
|
|
58
|
+
done: false,
|
|
59
|
+
value: rest
|
|
60
|
+
};
|
|
61
|
+
rest = void 0;
|
|
62
|
+
if (read.done) {
|
|
63
|
+
if (gathering !== void 0) hand(gathering.subarray(0, filled));
|
|
64
|
+
controller.close();
|
|
65
|
+
release();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const chunk = read.value;
|
|
69
|
+
if (chunk.length === 0) continue;
|
|
70
|
+
if (gathering === void 0 && chunk.length >= piece) {
|
|
71
|
+
hand(chunk);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
gathering ??= new Uint8Array(piece);
|
|
75
|
+
const moved = Math.min(chunk.length, piece - filled);
|
|
76
|
+
gathering.set(chunk.subarray(0, moved), filled);
|
|
77
|
+
filled += moved;
|
|
78
|
+
if (moved < chunk.length) rest = chunk.subarray(moved);
|
|
79
|
+
if (filled === piece) {
|
|
80
|
+
hand(gathering);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
return new ReadableStream({
|
|
86
|
+
pull: async (controller) => {
|
|
87
|
+
try {
|
|
88
|
+
await next(controller);
|
|
89
|
+
} catch (cause) {
|
|
90
|
+
release();
|
|
91
|
+
throw cause;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
cancel: async (reason) => {
|
|
95
|
+
try {
|
|
96
|
+
await reader.cancel(reason);
|
|
97
|
+
} finally {
|
|
98
|
+
release();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, { highWaterMark: 0 });
|
|
102
|
+
};
|
|
103
|
+
export { gathered, streamOf };
|
|
@@ -16,4 +16,9 @@ const isOid = (oid) => /^[0-9a-f]{40}$/.test(oid);
|
|
|
16
16
|
* message. JSON's string form, which never throws for a string.
|
|
17
17
|
*/
|
|
18
18
|
const quoted = (text) => JSON.stringify(text);
|
|
19
|
-
|
|
19
|
+
/** `text`'s first `most` UTF-16 units, the first half of a surrogate pair the cut splits dropped. */
|
|
20
|
+
const cutWords = (text, most) => {
|
|
21
|
+
const cut = text.slice(0, most);
|
|
22
|
+
return /[\uD800-\uDBFF]$/u.test(cut) ? cut.slice(0, -1) : cut;
|
|
23
|
+
};
|
|
24
|
+
export { cutWords, isOid, isWellFormed, quoted, utf8 };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Allotment, GitObject, ObjectsRead } from "../../contracts/objects.mjs";
|
|
2
2
|
import { Oid } from "../../contracts/ids.mjs";
|
|
3
|
+
import "../objects/commit.mjs";
|
|
3
4
|
import "../objects/tree.mjs";
|
|
4
5
|
import * as Effect from "effect/Effect";
|
|
5
6
|
import * as Schema from "effect/Schema";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { allotmentWithin, objectsReadMost } from "../../contracts/object-values.mjs";
|
|
2
2
|
import { gitError } from "../../contracts/result.mjs";
|
|
3
|
-
import { decodeCommit } from "../objects/commit.mjs";
|
|
3
|
+
import { decodeCommit, noRepoRoots } from "../objects/commit.mjs";
|
|
4
4
|
import { emptyTree } from "../objects/object.mjs";
|
|
5
5
|
import { decodeTag } from "../objects/tag.mjs";
|
|
6
6
|
import { parseTreeBytes, treeEntriesIn } from "../objects/tree.mjs";
|
|
@@ -143,11 +143,14 @@ var DiffReader = class {
|
|
|
143
143
|
limits;
|
|
144
144
|
tally;
|
|
145
145
|
batch;
|
|
146
|
-
|
|
146
|
+
/** The repo's roots, each of which a walk through this reader sees as having no parents. */
|
|
147
|
+
roots;
|
|
148
|
+
constructor(read, limits = defaultDiffLimits, tally, batch, roots = noRepoRoots) {
|
|
147
149
|
this.read = read;
|
|
148
150
|
this.limits = limits;
|
|
149
151
|
this.tally = tally;
|
|
150
152
|
this.batch = batch;
|
|
153
|
+
this.roots = roots;
|
|
151
154
|
}
|
|
152
155
|
/** The objects read so far. */
|
|
153
156
|
get objects() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Commit } from "../../contracts/engine.mjs";
|
|
2
|
+
import { Oid } from "../../contracts/ids.mjs";
|
|
2
3
|
import { WireDecodeError, WireEncodeError } from "../bytes/errors.mjs";
|
|
3
4
|
import * as Effect from "effect/Effect";
|
|
4
5
|
import "effect/Result";
|
|
@@ -7,6 +8,12 @@ import "effect/Result";
|
|
|
7
8
|
* paragraph, each line's trailing space off, joined by spaces.
|
|
8
9
|
*/
|
|
9
10
|
export declare function subjectOf(message: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* A repo's roots: the commits it holds without their parents, as Git's `shallow` file names them.
|
|
13
|
+
* Every walk of the repo sees a root as having no parents, as Git's shallow grafts make it, and
|
|
14
|
+
* still follows its tree.
|
|
15
|
+
*/
|
|
16
|
+
export type RepoRoots = ReadonlySet<Oid>;
|
|
10
17
|
/**
|
|
11
18
|
* A commit read from its bytes, as Git reads it: a `tree` line first, then its `parent` lines,
|
|
12
19
|
* and an `author` and a `committer` among the headers after them, read leniently, as
|
|
@@ -37,6 +37,10 @@ function subjectOf(message) {
|
|
|
37
37
|
}
|
|
38
38
|
return paragraph.join(" ");
|
|
39
39
|
}
|
|
40
|
+
/** A repo with no roots, as every repo without a `repo/roots` row is. */
|
|
41
|
+
const noRepoRoots = /* @__PURE__ */ new Set();
|
|
42
|
+
/** The parents a walk of a repo with `roots` follows from the commit `oid`: none from a root. */
|
|
43
|
+
const parentsWithin = (roots, oid, parents) => roots.has(oid) ? [] : parents;
|
|
40
44
|
/**
|
|
41
45
|
* A commit read from its bytes, as Git reads it: a `tree` line first, then its `parent` lines,
|
|
42
46
|
* and an `author` and a `committer` among the headers after them, read leniently, as
|
|
@@ -135,4 +139,4 @@ const encodeCommit = (commit) => Effect.suspend(() => {
|
|
|
135
139
|
];
|
|
136
140
|
return Effect.succeed(asCommitTreeStores(utf8(`${lines.join("\n")}\n\n${commit.message}`)));
|
|
137
141
|
});
|
|
138
|
-
export { decodeCommit, encodeCommit, readCommit, subjectOf };
|
|
142
|
+
export { decodeCommit, encodeCommit, noRepoRoots, parentsWithin, readCommit, subjectOf };
|
|
@@ -202,7 +202,10 @@ const entryFault = (entry) => {
|
|
|
202
202
|
if (entry.name.length > nameMost) return finding("largePathname", "contains excessively large pathname");
|
|
203
203
|
if (entry.zeroPadded) return finding("zeroPaddedFilemode", "contains zero-padded file modes");
|
|
204
204
|
};
|
|
205
|
-
const duplicate = () =>
|
|
205
|
+
const duplicate = (name) => ({
|
|
206
|
+
...finding("duplicateEntries", "contains duplicate file entries"),
|
|
207
|
+
name: new TextDecoder().decode(name)
|
|
208
|
+
});
|
|
206
209
|
/** Whether an entry before `end` is a file, any kind but a folder, named `name`. */
|
|
207
210
|
const fileBefore = (bytes, end, name) => {
|
|
208
211
|
for (let at = 0; at < end;) {
|
|
@@ -229,9 +232,9 @@ const orderReader = (bytes) => {
|
|
|
229
232
|
const tree = entry.kind === "tree";
|
|
230
233
|
const before = previous;
|
|
231
234
|
previous = entry;
|
|
232
|
-
if (before !== void 0 && compareNames(before.name, before.kind === "tree", entry.name, tree) >= 0) return sameName(before.name, entry.name) || tree && fileBefore(bytes, at, entry.name) ? duplicate() : finding("treeNotSorted", "not properly sorted");
|
|
235
|
+
if (before !== void 0 && compareNames(before.name, before.kind === "tree", entry.name, tree) >= 0) return sameName(before.name, entry.name) || tree && fileBefore(bytes, at, entry.name) ? duplicate(entry.name) : finding("treeNotSorted", "not properly sorted");
|
|
233
236
|
for (let top = files.at(-1); top !== void 0; top = files.at(-1)) {
|
|
234
|
-
if (tree && sameName(top, entry.name)) return duplicate();
|
|
237
|
+
if (tree && sameName(top, entry.name)) return duplicate(entry.name);
|
|
235
238
|
if (top.length < entry.name.length && (entry.name[top.length] ?? slash) < slash && sameName(top, entry.name.subarray(0, top.length))) break;
|
|
236
239
|
files.pop();
|
|
237
240
|
}
|