@git-stunts/git-cas 6.5.7 → 6.5.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/ARCHITECTURE.md +9 -0
  2. package/CHANGELOG.md +39 -0
  3. package/GUIDE.md +54 -0
  4. package/README.md +17 -9
  5. package/UPGRADING.md +68 -0
  6. package/build-info.json +2 -2
  7. package/docs/API.md +115 -12
  8. package/docs/releases/v6.5.8.md +89 -0
  9. package/docs/releases/v6.5.9.md +119 -0
  10. package/index.d.ts +75 -0
  11. package/index.js +19 -1
  12. package/package.json +4 -2
  13. package/src/domain/services/AssetService.js +201 -10
  14. package/src/domain/services/BoundedWriteWavePersistence.js +235 -0
  15. package/src/domain/services/BundleBatchPlanner.js +349 -0
  16. package/src/domain/services/BundleService.js +225 -2
  17. package/src/domain/services/CasService.d.ts +16 -0
  18. package/src/domain/services/CasService.js +9 -18
  19. package/src/domain/services/ManifestRepository.js +129 -50
  20. package/src/domain/services/ManifestTreeService.js +47 -0
  21. package/src/domain/services/PageService.js +36 -10
  22. package/src/domain/services/RootSet.js +32 -0
  23. package/src/domain/services/RootSetPersistence.js +58 -1
  24. package/src/domain/services/StagedTarget.js +19 -0
  25. package/src/domain/services/StagingWorkspace.js +95 -20
  26. package/src/domain/services/StagingWorkspaceRegistry.js +9 -4
  27. package/src/domain/services/WorkspaceCompoundAdmission.js +61 -0
  28. package/src/domain/services/WorkspaceCompoundScope.js +193 -0
  29. package/src/domain/services/forkCasPersistence.js +20 -0
  30. package/src/infrastructure/adapters/GitObjectSessionPool.js +47 -5
  31. package/src/infrastructure/adapters/GitPersistenceAdapter.js +169 -0
  32. package/src/infrastructure/adapters/GitPersistenceWriteScope.js +154 -0
  33. package/src/infrastructure/adapters/GitRefAdapter.js +38 -3
  34. package/src/infrastructure/adapters/GitUpdateRefSessionPool.js +115 -0
  35. package/src/package-version.js +1 -1
  36. package/src/ports/GitPersistencePort.js +43 -0
  37. package/src/ports/GitRefPort.js +8 -0
@@ -0,0 +1,235 @@
1
+ import GitPersistencePort from '../../ports/GitPersistencePort.js';
2
+ import createCasError from '../errors/createCasError.js';
3
+ import { ErrorCodes } from '../errors/index.js';
4
+ import { utf8ByteLength } from '../encoding/utf8.js';
5
+
6
+ const MAX_PROTOCOL_OBJECTS = 256;
7
+ const MAX_PROTOCOL_BYTES = 64 * 1024 * 1024;
8
+
9
+ /** Opt-in persistence decorator that coalesces concurrent immutable writes. */
10
+ export default class BoundedWriteWavePersistence extends GitPersistencePort {
11
+ #failure = null;
12
+ #flushing = false;
13
+ #maxBatchBytes;
14
+ #maxBatchObjects;
15
+ #persistence;
16
+ #queue = [];
17
+ #scheduled = false;
18
+ #writeBytes = 0;
19
+ #writeObjects = 0;
20
+
21
+ constructor({ persistence, maxBatchObjects, maxBatchBytes }) {
22
+ super();
23
+ this.#persistence = persistence;
24
+ this.#maxBatchObjects = maxBatchObjects;
25
+ this.#maxBatchBytes = maxBatchBytes;
26
+ }
27
+
28
+ async writeBlob(content) {
29
+ return await this.#enqueue({ kind: 'blob', value: content, bytes: contentBytes(content) });
30
+ }
31
+
32
+ async writeBlobs(contents) {
33
+ return await Promise.all([...contents].map((content) => this.writeBlob(content)));
34
+ }
35
+
36
+ async writeTree(entries) {
37
+ return await this.#enqueue({ kind: 'tree', value: entries, bytes: treeBytes(entries) });
38
+ }
39
+
40
+ async writeTrees(trees) {
41
+ return await Promise.all([...trees].map((entries) => this.writeTree(entries)));
42
+ }
43
+
44
+ async readBlob(oid, maxBytes) {
45
+ return await this.#persistence.readBlob(oid, maxBytes);
46
+ }
47
+
48
+ async readBlobStream(oid) {
49
+ return await this.#persistence.readBlobStream(oid);
50
+ }
51
+
52
+ async readTree(oid) {
53
+ return await this.#persistence.readTree(oid);
54
+ }
55
+
56
+ async readTreeEntry(oid, path) {
57
+ return await this.#persistence.readTreeEntry(oid, path);
58
+ }
59
+
60
+ async *iterateTree(oid) {
61
+ yield* this.#persistence.iterateTree(oid);
62
+ }
63
+
64
+ async readObjectType(oid) {
65
+ return await this.#persistence.readObjectType(oid);
66
+ }
67
+
68
+ async readObjectSize(oid) {
69
+ return await this.#persistence.readObjectSize(oid);
70
+ }
71
+
72
+ async readObjectInfos(oids) {
73
+ if (typeof this.#persistence.readObjectInfos === 'function') {
74
+ return await this.#persistence.readObjectInfos(oids);
75
+ }
76
+ return await super.readObjectInfos(oids);
77
+ }
78
+
79
+ setMaxBlobSize(maxBlobSize) {
80
+ this.#persistence.setMaxBlobSize?.(maxBlobSize);
81
+ }
82
+
83
+ snapshot() {
84
+ return Object.freeze({
85
+ writeObjects: this.#writeObjects,
86
+ writeBytes: this.#writeBytes,
87
+ failed: this.#failure !== null,
88
+ });
89
+ }
90
+
91
+ #enqueue(request) {
92
+ if (this.#failure !== null) {
93
+ return Promise.reject(this.#failure);
94
+ }
95
+ const objects = this.#writeObjects + 1;
96
+ const bytes = this.#writeBytes + request.bytes;
97
+ if (objects > this.#maxBatchObjects || bytes > this.#maxBatchBytes) {
98
+ this.#failure = batchLimit({ objects, bytes }, {
99
+ objects: this.#maxBatchObjects,
100
+ bytes: this.#maxBatchBytes,
101
+ });
102
+ return Promise.reject(this.#failure);
103
+ }
104
+ this.#writeObjects = objects;
105
+ this.#writeBytes = bytes;
106
+ const result = new Promise((resolve, reject) => {
107
+ this.#queue.push({ ...request, resolve, reject });
108
+ });
109
+ this.#schedule();
110
+ return result;
111
+ }
112
+
113
+ #schedule() {
114
+ if (this.#scheduled || this.#flushing) {
115
+ return;
116
+ }
117
+ this.#scheduled = true;
118
+ void Promise.resolve().then(() => {
119
+ this.#scheduled = false;
120
+ return this.#drain();
121
+ });
122
+ }
123
+
124
+ async #drain() {
125
+ if (this.#flushing) {
126
+ return;
127
+ }
128
+ this.#flushing = true;
129
+ try {
130
+ while (this.#queue.length > 0 && this.#failure === null) {
131
+ const group = this.#takeGroup();
132
+ await this.#writeGroup(group);
133
+ }
134
+ } catch (error) {
135
+ this.#failure = error;
136
+ } finally {
137
+ if (this.#failure !== null) {
138
+ this.#rejectQueued(this.#failure);
139
+ }
140
+ this.#flushing = false;
141
+ if (this.#queue.length > 0) {
142
+ this.#schedule();
143
+ }
144
+ }
145
+ }
146
+
147
+ #takeGroup() {
148
+ const first = this.#queue[0];
149
+ const group = [];
150
+ let bytes = 0;
151
+ while (group.length < MAX_PROTOCOL_OBJECTS && this.#queue[0]?.kind === first.kind) {
152
+ const next = this.#queue[0];
153
+ if (group.length > 0 && bytes + next.bytes > MAX_PROTOCOL_BYTES) {
154
+ break;
155
+ }
156
+ group.push(this.#queue.shift());
157
+ bytes += next.bytes;
158
+ if (next.bytes > MAX_PROTOCOL_BYTES) {
159
+ break;
160
+ }
161
+ }
162
+ return group;
163
+ }
164
+
165
+ async #writeGroup(group) {
166
+ try {
167
+ const oids = group.length === 1 || group[0].bytes > MAX_PROTOCOL_BYTES
168
+ ? [await this.#writeOne(group[0])]
169
+ : await this.#writeMany(group);
170
+ if (oids.length !== group.length) {
171
+ throw createCasError(
172
+ 'Persistence returned the wrong number of write-wave object identifiers',
173
+ ErrorCodes.GIT_ERROR,
174
+ { expected: group.length, actual: oids.length },
175
+ );
176
+ }
177
+ group.forEach((request, index) => request.resolve(oids[index]));
178
+ } catch (error) {
179
+ group.forEach((request) => request.reject(error));
180
+ throw error;
181
+ }
182
+ }
183
+
184
+ async #writeOne(request) {
185
+ return request.kind === 'blob'
186
+ ? await this.#persistence.writeBlob(request.value)
187
+ : await this.#persistence.writeTree(request.value);
188
+ }
189
+
190
+ async #writeMany(group) {
191
+ const values = group.map((request) => request.value);
192
+ if (group[0].kind === 'blob' && typeof this.#persistence.writeBlobs === 'function') {
193
+ return await this.#persistence.writeBlobs(values);
194
+ }
195
+ if (group[0].kind === 'tree' && typeof this.#persistence.writeTrees === 'function') {
196
+ return await this.#persistence.writeTrees(values);
197
+ }
198
+ const oids = [];
199
+ for (const request of group) {
200
+ oids.push(await this.#writeOne(request));
201
+ }
202
+ return oids;
203
+ }
204
+
205
+ #rejectQueued(error) {
206
+ for (const request of this.#queue.splice(0)) {
207
+ request.reject(error);
208
+ }
209
+ }
210
+ }
211
+
212
+ function contentBytes(content) {
213
+ if (content instanceof Uint8Array) {
214
+ return content.byteLength;
215
+ }
216
+ if (typeof content === 'string') {
217
+ return utf8ByteLength(content);
218
+ }
219
+ return Number.MAX_SAFE_INTEGER;
220
+ }
221
+
222
+ function treeBytes(entries) {
223
+ if (!Array.isArray(entries)) {
224
+ return Number.MAX_SAFE_INTEGER;
225
+ }
226
+ return entries.reduce((total, line) => total + utf8ByteLength(line) + 1, 0);
227
+ }
228
+
229
+ function batchLimit(observed, maximum) {
230
+ return createCasError(
231
+ 'Asset write batch exceeds its configured aggregate limit',
232
+ ErrorCodes.INVALID_OPTIONS,
233
+ { observed, maximum },
234
+ );
235
+ }
@@ -0,0 +1,349 @@
1
+ import createCasError from '../errors/createCasError.js';
2
+ import { ErrorCodes } from '../errors/index.js';
3
+ import { utf8ByteLength } from '../encoding/utf8.js';
4
+ import {
5
+ BUNDLE_DESCRIPTOR_VERSION,
6
+ BUNDLE_INDEX_ENTRY,
7
+ BUNDLE_LAYOUT,
8
+ } from './BundleDescriptorCodec.js';
9
+
10
+ const BLOB_MODE = '100644';
11
+ const TREE_MODE = '040000';
12
+ const SLOT_WIDTH = 6;
13
+ const MAX_PROTOCOL_OBJECTS = 256;
14
+ const MAX_PROTOCOL_BYTES = 64 * 1024 * 1024;
15
+ const MAX_PROTOCOL_TREE_ENTRIES = 65_536;
16
+ const CONSERVATIVE_OID = '0'.repeat(64);
17
+
18
+ /** Plans bounded bundle graphs before writing descriptors and dependency layers. */
19
+ export default class BundleBatchPlanner {
20
+ #codec;
21
+ #maxBatchBytes;
22
+ #maxBatchObjects;
23
+ #persistence;
24
+ #staging;
25
+
26
+ constructor({ persistence, codec, staging, maxBatchObjects, maxBatchBytes }) {
27
+ this.#persistence = persistence;
28
+ this.#codec = codec;
29
+ this.#staging = staging;
30
+ this.#maxBatchObjects = maxBatchObjects;
31
+ this.#maxBatchBytes = maxBatchBytes;
32
+ }
33
+
34
+ static estimateObjectCount(requests) {
35
+ return requests.reduce(
36
+ (total, request) => total + objectCount(request.members.length, request.limits),
37
+ 0,
38
+ );
39
+ }
40
+
41
+ create({ members, limits, observedAt }) {
42
+ const levels = [leafNodes(members, limits)];
43
+ while (levels.at(-1).length > 1) {
44
+ levels.push(branchNodes(levels.at(-1), limits));
45
+ }
46
+ const index = levels.at(-1)[0];
47
+ const root = rootNode({ index, memberCount: members.length, limits, codec: this.#codec });
48
+ const descriptors = [...levels.flat(), root];
49
+ let descriptorBytes = 0;
50
+ for (const record of descriptors) {
51
+ record.bytes = record.root
52
+ ? this.#codec.encodeRoot(record.descriptor)
53
+ : this.#codec.encodeNode(record.descriptor);
54
+ descriptorBytes += record.bytes.length;
55
+ if (descriptorBytes > limits.maxDescriptorBytes) {
56
+ throw createCasError(
57
+ 'Bundle descriptors exceed their configured byte limit',
58
+ ErrorCodes.BUNDLE_DESCRIPTOR_LIMIT,
59
+ { descriptorBytes, maxDescriptorBytes: limits.maxDescriptorBytes },
60
+ );
61
+ }
62
+ }
63
+ return { levels, root, descriptors, descriptorBytes, limits, observedAt };
64
+ }
65
+
66
+ async write(plans) {
67
+ this.#assertBounds(plans);
68
+ await this.#writeDescriptors(plans.flatMap((plan) => plan.descriptors));
69
+ const maximumDepth = Math.max(...plans.map((plan) => plan.levels.length));
70
+ for (let depth = 0; depth < maximumDepth; depth += 1) {
71
+ await this.#writeTreeLayer(plans.flatMap((plan) => plan.levels[depth] ?? []));
72
+ }
73
+ await this.#writeTreeLayer(plans.map((plan) => plan.root));
74
+ return plans.map((plan) => ({
75
+ oid: plan.root.oid,
76
+ memberCount: plan.root.descriptor.memberCount,
77
+ indexDepth: plan.root.descriptor.index.depth,
78
+ descriptorBytes: plan.descriptorBytes,
79
+ limits: plan.limits,
80
+ observedAt: plan.observedAt,
81
+ }));
82
+ }
83
+
84
+ #assertBounds(plans) {
85
+ const objects = plans.reduce((total, plan) => total + plan.descriptors.length * 2, 0);
86
+ const bytes = plans.reduce((total, plan) => total + plannedBytes(plan, this.#codec), 0);
87
+ if (objects > this.#maxBatchObjects) {
88
+ throw batchLimit('objects', objects, this.#maxBatchObjects);
89
+ }
90
+ if (bytes > this.#maxBatchBytes) {
91
+ throw batchLimit('bytes', bytes, this.#maxBatchBytes);
92
+ }
93
+ }
94
+
95
+ async #writeDescriptors(records) {
96
+ for (const batch of windows(records, descriptorWeight, {
97
+ maxObjects: Math.min(this.#maxBatchObjects, MAX_PROTOCOL_OBJECTS),
98
+ maxBytes: Math.min(this.#maxBatchBytes, MAX_PROTOCOL_BYTES),
99
+ })) {
100
+ const contents = batch.map((record) => record.bytes);
101
+ const oids = typeof this.#persistence.writeBlobs === 'function'
102
+ ? await this.#persistence.writeBlobs(contents)
103
+ : await writeIndividually(contents, (content) => this.#persistence.writeBlob(content));
104
+ assertCardinality('descriptor', batch, oids);
105
+ for (let index = 0; index < batch.length; index += 1) {
106
+ batch[index].descriptorOid = oids[index];
107
+ this.#staging.record(oids[index], 'blob');
108
+ }
109
+ }
110
+ }
111
+
112
+ async #writeTreeLayer(records) {
113
+ const prepared = records.map((record) => ({ record, lines: treeLines(record, this.#codec) }));
114
+ for (const batch of treeWindows(prepared, this.#maxBatchObjects, this.#maxBatchBytes)) {
115
+ const trees = batch.map((item) => item.lines);
116
+ const oids = typeof this.#persistence.writeTrees === 'function'
117
+ ? await this.#persistence.writeTrees(trees)
118
+ : await writeIndividually(trees, (entries) => this.#persistence.writeTree(entries));
119
+ assertCardinality('tree', batch, oids);
120
+ for (let index = 0; index < batch.length; index += 1) {
121
+ batch[index].record.oid = oids[index];
122
+ this.#staging.record(oids[index], 'tree');
123
+ }
124
+ }
125
+ }
126
+ }
127
+
128
+ function leafNodes(members, limits) {
129
+ const groups = members.length === 0 ? [[]] : chunks(members, limits.maxFanoutEntries - 1);
130
+ return groups.map((group) => node('leaf', 1, group));
131
+ }
132
+
133
+ function branchNodes(children, limits) {
134
+ const depth = children[0].descriptor.depth + 1;
135
+ if (depth > limits.maxFanoutDepth) {
136
+ throw createCasError('Bundle fanout exceeds its configured depth', ErrorCodes.BUNDLE_FANOUT_LIMIT, {
137
+ attemptedDepth: depth,
138
+ maxFanoutDepth: limits.maxFanoutDepth,
139
+ });
140
+ }
141
+ return chunks(children, limits.maxFanoutEntries - 1).map((group) =>
142
+ node('branch', depth, group)
143
+ );
144
+ }
145
+
146
+ function node(kind, depth, targets) {
147
+ const entries = kind === 'leaf' ? leafEntries(targets) : branchEntries(targets);
148
+ const descriptor = {
149
+ version: BUNDLE_DESCRIPTOR_VERSION,
150
+ kind,
151
+ depth,
152
+ count: kind === 'leaf'
153
+ ? entries.length
154
+ : targets.reduce((total, child) => total + child.descriptor.count, 0),
155
+ firstPath: rangePath(entries, kind, false),
156
+ lastPath: rangePath(entries, kind, true),
157
+ entries,
158
+ };
159
+ return { root: false, descriptor, targets };
160
+ }
161
+
162
+ function rootNode({ index, memberCount, limits, codec }) {
163
+ return {
164
+ root: true,
165
+ descriptor: {
166
+ version: BUNDLE_DESCRIPTOR_VERSION,
167
+ kind: 'bundle',
168
+ layout: BUNDLE_LAYOUT,
169
+ codec: codec.extension,
170
+ memberCount,
171
+ index: {
172
+ entry: BUNDLE_INDEX_ENTRY,
173
+ depth: index.descriptor.depth,
174
+ firstPath: index.descriptor.firstPath,
175
+ lastPath: index.descriptor.lastPath,
176
+ },
177
+ limits: limits.toJSON(),
178
+ },
179
+ targets: [index],
180
+ };
181
+ }
182
+
183
+ function leafEntries(members) {
184
+ return members.map((member, index) => ({
185
+ path: member.path,
186
+ slot: slotFor(index),
187
+ handle: member.handle.toString(),
188
+ type: member.type,
189
+ size: member.size,
190
+ }));
191
+ }
192
+
193
+ function branchEntries(children) {
194
+ return children.map((child, index) => ({
195
+ firstPath: child.descriptor.firstPath,
196
+ lastPath: child.descriptor.lastPath,
197
+ slot: slotFor(index),
198
+ count: child.descriptor.count,
199
+ depth: child.descriptor.depth,
200
+ }));
201
+ }
202
+
203
+ function rangePath(entries, kind, last) {
204
+ const entry = last ? entries.at(-1) : entries[0];
205
+ if (entry === undefined) {
206
+ return null;
207
+ }
208
+ if (kind === 'leaf') {
209
+ return entry.path;
210
+ }
211
+ return last ? entry.lastPath : entry.firstPath;
212
+ }
213
+
214
+ function treeLines(record, codec, oid = undefined) {
215
+ const descriptorName = record.root ? codec.rootEntryName : codec.nodeEntryName;
216
+ const lines = [blobEntry(record.descriptorOid ?? oid, descriptorName)];
217
+ if (record.root) {
218
+ lines.push(objectEntry(record.targets[0].oid ?? oid, BUNDLE_INDEX_ENTRY, 'tree'));
219
+ } else {
220
+ lines.push(...record.targets.map((target, index) => {
221
+ const targetOid = target.oid ?? oid;
222
+ const type = record.descriptor.kind === 'leaf' ? target.type : 'tree';
223
+ return objectEntry(targetOid, slotFor(index), type);
224
+ }));
225
+ }
226
+ lines.sort((left, right) => compareText(entryName(left), entryName(right)));
227
+ return lines;
228
+ }
229
+
230
+ function plannedBytes(plan, codec) {
231
+ const descriptorBytes = plan.descriptors.reduce((total, record) => total + record.bytes.length, 0);
232
+ const treeBytes = plan.descriptors.reduce(
233
+ (total, record) => total + linesWeight(treeLines(record, codec, CONSERVATIVE_OID)),
234
+ 0,
235
+ );
236
+ return descriptorBytes + treeBytes;
237
+ }
238
+
239
+ function treeWindows(records, configuredObjects, configuredBytes) {
240
+ return windows(records, treeWeight, {
241
+ maxObjects: Math.min(configuredObjects, MAX_PROTOCOL_OBJECTS),
242
+ maxBytes: Math.min(configuredBytes, MAX_PROTOCOL_BYTES),
243
+ maxEntries: MAX_PROTOCOL_TREE_ENTRIES,
244
+ });
245
+ }
246
+
247
+ function windows(records, weightOf, limits) {
248
+ const batches = [];
249
+ let batch = [];
250
+ let bytes = 0;
251
+ let entries = 0;
252
+ for (const record of records) {
253
+ const weight = weightOf(record);
254
+ const full = batch.length > 0 && (
255
+ batch.length + 1 > limits.maxObjects ||
256
+ bytes + weight.bytes > limits.maxBytes ||
257
+ entries + weight.entries > (limits.maxEntries ?? Number.POSITIVE_INFINITY)
258
+ );
259
+ if (full) {
260
+ batches.push(batch);
261
+ batch = [];
262
+ bytes = 0;
263
+ entries = 0;
264
+ }
265
+ batch.push(record);
266
+ bytes += weight.bytes;
267
+ entries += weight.entries;
268
+ }
269
+ if (batch.length > 0) {
270
+ batches.push(batch);
271
+ }
272
+ return batches;
273
+ }
274
+
275
+ function descriptorWeight(record) {
276
+ return { bytes: record.bytes.length, entries: 0 };
277
+ }
278
+
279
+ function treeWeight(item) {
280
+ return { bytes: linesWeight(item.lines), entries: item.lines.length };
281
+ }
282
+
283
+ function linesWeight(lines) {
284
+ return lines.reduce((total, line) => total + utf8ByteLength(line) + 1, 0);
285
+ }
286
+
287
+ function objectCount(memberCount, limits) {
288
+ let nodes = memberCount === 0 ? 1 : Math.ceil(memberCount / (limits.maxFanoutEntries - 1));
289
+ let level = nodes;
290
+ while (level > 1) {
291
+ level = Math.ceil(level / (limits.maxFanoutEntries - 1));
292
+ nodes += level;
293
+ }
294
+ return (nodes + 1) * 2;
295
+ }
296
+
297
+ function chunks(values, size) {
298
+ const result = [];
299
+ for (let index = 0; index < values.length; index += size) {
300
+ result.push(values.slice(index, index + size));
301
+ }
302
+ return result;
303
+ }
304
+
305
+ function assertCardinality(kind, input, output) {
306
+ if (output.length !== input.length) {
307
+ throw createCasError(
308
+ `Persistence returned the wrong number of ${kind} object identifiers`,
309
+ ErrorCodes.GIT_ERROR,
310
+ { expected: input.length, actual: output.length },
311
+ );
312
+ }
313
+ }
314
+
315
+ async function writeIndividually(values, write) {
316
+ const oids = [];
317
+ for (const value of values) {
318
+ oids.push(await write(value));
319
+ }
320
+ return oids;
321
+ }
322
+
323
+ function batchLimit(kind, observed, maximum) {
324
+ return createCasError(
325
+ `Bundle batch exceeds its configured ${kind} limit`,
326
+ ErrorCodes.INVALID_OPTIONS,
327
+ { kind, observed, maximum },
328
+ );
329
+ }
330
+
331
+ function slotFor(index) {
332
+ return `slot-${String(index).padStart(SLOT_WIDTH, '0')}`;
333
+ }
334
+
335
+ function blobEntry(oid, name) {
336
+ return `${BLOB_MODE} blob ${oid}\t${name}`;
337
+ }
338
+
339
+ function objectEntry(oid, name, type) {
340
+ return `${type === 'tree' ? TREE_MODE : BLOB_MODE} ${type} ${oid}\t${name}`;
341
+ }
342
+
343
+ function entryName(value) {
344
+ return value.slice(value.indexOf('\t') + 1);
345
+ }
346
+
347
+ function compareText(left, right) {
348
+ return left < right ? -1 : left > right ? 1 : 0;
349
+ }