@statewalker/vcs-commands 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/commands/archive/archive-command.d.ts +81 -7
  2. package/dist/commands/archive/archive-command.d.ts.map +1 -1
  3. package/dist/commands/archive/archive-entry.d.ts +48 -5
  4. package/dist/commands/archive/archive-entry.d.ts.map +1 -1
  5. package/dist/commands/archive/tar-archive.d.ts +5 -2
  6. package/dist/commands/archive/tar-archive.d.ts.map +1 -1
  7. package/dist/commands/archive/zip-archive.d.ts +9 -2
  8. package/dist/commands/archive/zip-archive.d.ts.map +1 -1
  9. package/dist/commands/attributes-source.d.ts +5 -0
  10. package/dist/commands/attributes-source.d.ts.map +1 -1
  11. package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
  12. package/dist/commands/http-config.d.ts +4 -2
  13. package/dist/commands/http-config.d.ts.map +1 -1
  14. package/dist/commands/index.d.ts +1 -0
  15. package/dist/commands/index.d.ts.map +1 -1
  16. package/dist/commands/index.js +6 -6
  17. package/dist/commands/ls-files-command.d.ts.map +1 -1
  18. package/dist/commands/ls-tree-command.d.ts.map +1 -1
  19. package/dist/commands/mv-command.d.ts.map +1 -1
  20. package/dist/commands/pathspec.d.ts.map +1 -1
  21. package/dist/commands/plumbing-shared.d.ts +72 -0
  22. package/dist/commands/plumbing-shared.d.ts.map +1 -0
  23. package/dist/commands/repack-command.d.ts +12 -3
  24. package/dist/commands/repack-command.d.ts.map +1 -1
  25. package/dist/commands/replace-command.d.ts.map +1 -1
  26. package/dist/commands/rerere-command.d.ts +12 -0
  27. package/dist/commands/rerere-command.d.ts.map +1 -1
  28. package/dist/commands/rerere.d.ts +22 -0
  29. package/dist/commands/rerere.d.ts.map +1 -1
  30. package/dist/commands/revision-resolver.d.ts +9 -4
  31. package/dist/commands/revision-resolver.d.ts.map +1 -1
  32. package/dist/{commands-bQQ9OmCh.js → commands-C2E51T1z.js} +595 -223
  33. package/dist/{fsck-BHT9bUS-.js → fsck-BjlxStsM.js} +1 -1
  34. package/dist/git-command.d.ts +6 -4
  35. package/dist/git-command.d.ts.map +1 -1
  36. package/dist/index.js +6 -6
  37. package/dist/{maintenance-run-command-Cx2PlGV9.js → maintenance-run-command-G_eWdA8O.js} +42 -16
  38. package/dist/remote-config/remote-config-store.d.ts +4 -1
  39. package/dist/remote-config/remote-config-store.d.ts.map +1 -1
  40. package/dist/{remote-transport-BrQZfyHu.js → remote-transport-CSgTJ1BH.js} +3 -3
  41. package/dist/results/index.js +1 -1
  42. package/dist/{results-CNHQnU5Y.js → results-Dg1KHG8y.js} +351 -51
  43. package/dist/transport-command.d.ts.map +1 -1
  44. package/package.json +12 -12
  45. package/src/commands/archive/archive-command.ts +395 -59
  46. package/src/commands/archive/archive-entry.ts +88 -5
  47. package/src/commands/archive/tar-archive.ts +40 -9
  48. package/src/commands/archive/zip-archive.ts +72 -21
  49. package/src/commands/attributes-source.ts +13 -1
  50. package/src/commands/cat-file/cat-file-command.ts +18 -44
  51. package/src/commands/http-config.ts +14 -2
  52. package/src/commands/index.ts +1 -0
  53. package/src/commands/ls-files-command.ts +25 -33
  54. package/src/commands/ls-tree-command.ts +5 -21
  55. package/src/commands/mv-command.ts +37 -6
  56. package/src/commands/pathspec.ts +2 -4
  57. package/src/commands/plumbing-shared.ts +197 -0
  58. package/src/commands/repack-command.ts +44 -11
  59. package/src/commands/replace-command.ts +16 -4
  60. package/src/commands/rerere-command.ts +17 -0
  61. package/src/commands/rerere.ts +144 -3
  62. package/src/commands/revision-resolver.ts +32 -23
  63. package/src/git-command.ts +17 -20
  64. package/src/remote-config/remote-config-store.ts +11 -3
  65. package/src/transport-command.ts +4 -1
@@ -11,13 +11,20 @@ export interface ArchiveEntry {
11
11
  mode: number;
12
12
  /** The object id in hex (an extra file: git's fake id, its number in the first 8 bytes) */
13
13
  id: string;
14
- /** The content (a symbolic link: its target); empty for directories */
14
+ /** The content (a symbolic link: its target); empty for directories and streamed blobs */
15
15
  content: Uint8Array;
16
16
  /**
17
17
  * The blob is streamed (git's `size > core.bigFileThreshold` with no export-subst): it is
18
18
  * written unconverted, and zip writes it with a data descriptor
19
19
  */
20
20
  streamed?: boolean;
21
+ /**
22
+ * A streamed blob's bytes as they are read (git's `open_istream`), {@link size} of them in
23
+ * all; without it a streamed entry's bytes are {@link content}
24
+ */
25
+ stream?: AsyncIterable<Uint8Array>;
26
+ /** The size of {@link stream} (the blob's size, as `oid_object_info` gives it) */
27
+ size?: number;
21
28
  /**
22
29
  * zip's `entry_is_binary`: the userdiff driver's `binary` setting for the path (`true`,
23
30
  * `false`), undefined to look at the content (a NUL in its first 8000 bytes)
@@ -33,14 +40,85 @@ export interface ArchiveSettings {
33
40
  commitId?: string;
34
41
  /** zlib's level (`-0` … `-9`); -1 for zlib's default */
35
42
  compressionLevel: number;
43
+ /** Where the bytes go as they are written; without it {@link ArchiveWriter.finish} returns them */
44
+ output?: ArchiveOutput;
36
45
  }
37
46
 
38
- /** Writes an archive one entry at a time (`write_archive_entries`' callback). */
47
+ /**
48
+ * Where a writer sends its bytes as it writes them (git's `write_or_die(1, ...)`): a
49
+ * returned promise holds the writer back until it settles. Each chunk is the writer's no
50
+ * longer (it may be kept).
51
+ */
52
+ export type ArchiveOutput = (chunk: Uint8Array) => void | Promise<void>;
53
+
54
+ /**
55
+ * Writes an archive one entry at a time (`write_archive_entries`' callback). Given an
56
+ * {@link ArchiveOutput} the bytes leave in chunks of about {@link OUTPUT_CHUNK} as they are
57
+ * written, and a streamed entry is never held whole; without one they are kept and
58
+ * {@link finish} returns them.
59
+ */
39
60
  export interface ArchiveWriter {
40
61
  /** Writes an entry; a string is git's `error:` message for an entry it refuses */
41
- entry(entry: ArchiveEntry): string | undefined;
42
- /** The archive's bytes (the trailer written) */
43
- finish(): Uint8Array;
62
+ entry(entry: ArchiveEntry): Promise<string | undefined>;
63
+ /** The archive's bytes (the trailer written); empty when they went to an output */
64
+ finish(): Promise<Uint8Array>;
65
+ }
66
+
67
+ /** The size of the chunks a writer sends to its output. */
68
+ export const OUTPUT_CHUNK = 64 * 1024;
69
+
70
+ /**
71
+ * The bytes a writer has written: kept whole, or sent to an {@link ArchiveOutput} in chunks
72
+ * of about {@link OUTPUT_CHUNK}.
73
+ */
74
+ export class ArchiveSink {
75
+ readonly buffer: ByteBuffer;
76
+ /** The bytes sent to the output so far */
77
+ private sent = 0;
78
+
79
+ constructor(
80
+ private readonly output: ArchiveOutput | undefined,
81
+ capacity = 16384,
82
+ ) {
83
+ this.buffer = new ByteBuffer(output ? OUTPUT_CHUNK * 2 : capacity);
84
+ }
85
+
86
+ /** The archive's length so far (sent and held). */
87
+ get position(): number {
88
+ return this.sent + this.buffer.length;
89
+ }
90
+
91
+ /** Sends what is held once it reaches a chunk (`force`: whatever is held). */
92
+ async flush(force = false): Promise<void> {
93
+ if (!this.output || this.buffer.length === 0) return;
94
+ if (!force && this.buffer.length < OUTPUT_CHUNK) return;
95
+ const chunk = this.buffer.bytes().slice();
96
+ this.sent += chunk.length;
97
+ this.buffer.clear();
98
+ await this.output(chunk);
99
+ }
100
+
101
+ /** Writes a large piece (a streamed blob's chunk), sent as it is when there is an output. */
102
+ async write(bytes: Uint8Array): Promise<void> {
103
+ if (!this.output) {
104
+ this.buffer.push(bytes);
105
+ return;
106
+ }
107
+ if (this.buffer.length + bytes.length < OUTPUT_CHUNK) {
108
+ this.buffer.push(bytes);
109
+ return;
110
+ }
111
+ await this.flush(true);
112
+ this.sent += bytes.length;
113
+ await this.output(bytes.slice());
114
+ }
115
+
116
+ /** The bytes held whole (no output), or empty once everything was sent. */
117
+ async finish(): Promise<Uint8Array> {
118
+ if (!this.output) return this.buffer.bytes();
119
+ await this.flush(true);
120
+ return new Uint8Array(0);
121
+ }
44
122
  }
45
123
 
46
124
  /** A growing byte buffer. */
@@ -73,6 +151,11 @@ export class ByteBuffer {
73
151
  this.length += n;
74
152
  }
75
153
 
154
+ /** Forgets the bytes written (the capacity kept). */
155
+ clear(): void {
156
+ this.length = 0;
157
+ }
158
+
76
159
  /** The bytes written (a view: copy before writing more). */
77
160
  bytes(): Uint8Array {
78
161
  return this.buf.subarray(0, this.length);
@@ -7,6 +7,7 @@
7
7
  import {
8
8
  type ArchiveEntry,
9
9
  type ArchiveSettings,
10
+ ArchiveSink,
10
11
  type ArchiveWriter,
11
12
  asciiBytes,
12
13
  ByteBuffer,
@@ -84,11 +85,14 @@ function pathPrefix(path: Uint8Array, maxlen: number): number {
84
85
 
85
86
  /** Writes git's tar archive (`git archive --format=tar`). */
86
87
  export class TarArchiveWriter implements ArchiveWriter {
87
- private readonly out = new ByteBuffer(BLOCKSIZE);
88
+ private readonly sink: ArchiveSink;
89
+ private readonly out: ByteBuffer;
88
90
  private readonly umask: number;
89
91
  private time: number;
90
92
 
91
93
  constructor(private readonly settings: TarArchiveOptions) {
94
+ this.sink = new ArchiveSink(settings.output, BLOCKSIZE);
95
+ this.out = this.sink.buffer;
92
96
  this.umask = settings.umask ?? 0o002;
93
97
  this.time = settings.time;
94
98
  this.writeGlobalExtendedHeader();
@@ -101,6 +105,24 @@ export class TarArchiveWriter implements ArchiveWriter {
101
105
  if (tail) this.out.zeros(RECORDSIZE - tail);
102
106
  }
103
107
 
108
+ /** `stream_blocked`: a streamed blob's bytes, padded to a whole record; false when short. */
109
+ private async streamBlocked(stream: AsyncIterable<Uint8Array>, size: number): Promise<boolean> {
110
+ let total = 0;
111
+ try {
112
+ for await (const chunk of stream) {
113
+ if (total + chunk.length > size) return false;
114
+ total += chunk.length;
115
+ await this.sink.write(chunk);
116
+ }
117
+ } catch {
118
+ return false;
119
+ }
120
+ if (total !== size) return false;
121
+ const tail = size % RECORDSIZE;
122
+ if (tail) this.out.zeros(RECORDSIZE - tail);
123
+ return true;
124
+ }
125
+
104
126
  /** `prepare_header`: the numeric fields, owner, magic and checksum. */
105
127
  private prepareHeader(header: Uint8Array, mode: number, size: number): void {
106
128
  octal(header, MODE, 8, mode & 0o7777);
@@ -148,8 +170,10 @@ export class TarArchiveWriter implements ArchiveWriter {
148
170
  }
149
171
 
150
172
  /** `write_tar_entry`. */
151
- entry(entry: ArchiveEntry): string | undefined {
173
+ async entry(entry: ArchiveEntry): Promise<string | undefined> {
152
174
  const { path, id, content } = entry;
175
+ const stream = isRegMode(entry.mode) ? entry.stream : undefined;
176
+ const size = stream ? (entry.size ?? 0) : content.length;
153
177
  let mode = entry.mode;
154
178
  const header = new Uint8Array(RECORDSIZE);
155
179
  const ext = new ByteBuffer(256);
@@ -184,24 +208,31 @@ export class TarArchiveWriter implements ArchiveWriter {
184
208
  } else header.set(content, LINKNAME);
185
209
  }
186
210
 
187
- let sizeInHeader = content.length;
188
- if (isRegMode(mode) && content.length > USTAR_MAX) {
211
+ let sizeInHeader = size;
212
+ if (isRegMode(mode) && size > USTAR_MAX) {
189
213
  sizeInHeader = 0;
190
- extRecord(ext, "size", asciiBytes(String(content.length)));
214
+ extRecord(ext, "size", asciiBytes(String(size)));
191
215
  }
192
216
  this.prepareHeader(header, mode, sizeInHeader);
193
217
  if (ext.length > 0) this.writeExtendedHeader(id, ext.bytes());
194
218
  this.writeBlocked(header);
195
- if (isRegMode(mode) && content.length > 0) this.writeBlocked(content);
219
+ if (stream) {
220
+ if (!(await this.streamBlocked(stream, size))) return `cannot stream blob ${id}`;
221
+ } else if (isRegMode(mode) && content.length > 0) {
222
+ await this.sink.write(content);
223
+ const tail = content.length % RECORDSIZE;
224
+ if (tail) this.out.zeros(RECORDSIZE - tail);
225
+ }
226
+ await this.sink.flush();
196
227
  return undefined;
197
228
  }
198
229
 
199
230
  /** `write_trailer`: the last block filled, another one when fewer than two records remain. */
200
- finish(): Uint8Array {
201
- const offset = this.out.length % BLOCKSIZE;
231
+ async finish(): Promise<Uint8Array> {
232
+ const offset = this.sink.position % BLOCKSIZE;
202
233
  const tail = BLOCKSIZE - offset;
203
234
  this.out.zeros(tail);
204
235
  if (tail < 2 * RECORDSIZE) this.out.zeros(BLOCKSIZE);
205
- return this.out.bytes();
236
+ return this.sink.finish();
206
237
  }
207
238
  }
@@ -5,12 +5,13 @@
5
5
  * the commit id as the archive's comment.
6
6
  */
7
7
 
8
- import { deflateSync } from "@statewalker/vcs-utils/compression";
9
- import { crc32 } from "@statewalker/vcs-utils/hash/crc32";
8
+ import { createDeflater, deflateSync } from "@statewalker/vcs-utils/compression";
9
+ import { CRC32, crc32 } from "@statewalker/vcs-utils/hash/crc32";
10
10
  import { bufferIsBinary } from "../grep/index.js";
11
11
  import {
12
12
  type ArchiveEntry,
13
13
  type ArchiveSettings,
14
+ ArchiveSink,
14
15
  type ArchiveWriter,
15
16
  asciiBytes,
16
17
  ByteBuffer,
@@ -27,6 +28,8 @@ const METHOD_DEFLATE = 8;
27
28
  const EXTRA_MTIME_SIZE = 9;
28
29
  const ZIP64_EXTRA_SIZE = 20;
29
30
  const MAX32 = 0xffffffff;
31
+ /** archive-zip.c's `STREAM_BUFFER_SIZE`: a streamed blob's reads. */
32
+ const STREAM_BUFFER_SIZE = 16384;
30
33
 
31
34
  /** Options of {@link ZipArchiveWriter}. */
32
35
  export interface ZipArchiveOptions extends ArchiveSettings {
@@ -95,9 +98,10 @@ export function dosTime(
95
98
 
96
99
  /** Writes git's zip archive (`git archive --format=zip`). */
97
100
  export class ZipArchiveWriter implements ArchiveWriter {
98
- private readonly out = new ByteBuffer(65536);
101
+ private readonly sink: ArchiveSink;
102
+ private readonly out: ByteBuffer;
99
103
  private readonly dir = new ByteBuffer(4096);
100
- private readonly le = new LeWriter(this.out);
104
+ private readonly le: LeWriter;
101
105
  private readonly dirLe = new LeWriter(this.dir);
102
106
  private entries = 0;
103
107
  private maxCreatorVersion = 0;
@@ -105,15 +109,18 @@ export class ZipArchiveWriter implements ArchiveWriter {
105
109
  private readonly dosTimeOfDay: number;
106
110
 
107
111
  constructor(private readonly settings: ZipArchiveOptions) {
112
+ this.sink = new ArchiveSink(settings.output, 65536);
113
+ this.out = this.sink.buffer;
114
+ this.le = new LeWriter(this.out);
108
115
  const dos = dosTime(settings.time, settings.localTzOffset);
109
116
  this.dosDate = dos.date;
110
117
  this.dosTimeOfDay = dos.time;
111
118
  }
112
119
 
113
120
  /** `write_zip_entry`. */
114
- entry(entry: ArchiveEntry): string | undefined {
121
+ async entry(entry: ArchiveEntry): Promise<string | undefined> {
115
122
  const { path, mode, id } = entry;
116
- const offset = this.out.length;
123
+ const offset = this.sink.position;
117
124
  let flags = 0;
118
125
  let crc = 0;
119
126
  let isBinary: boolean | undefined;
@@ -123,8 +130,8 @@ export class ZipArchiveWriter implements ArchiveWriter {
123
130
  let attr2: number;
124
131
  let out: Uint8Array | undefined;
125
132
  let compressedSize: number;
126
- const size = entry.content.length;
127
133
  const streamed = entry.streamed === true && isRegMode(mode);
134
+ const size = streamed && entry.stream ? (entry.size ?? 0) : entry.content.length;
128
135
 
129
136
  if (!onlyAscii(path)) {
130
137
  if (isUtf8(path)) flags |= ZIP_UTF8;
@@ -207,16 +214,11 @@ export class ZipArchiveWriter implements ArchiveWriter {
207
214
  }
208
215
 
209
216
  if (streamed) {
210
- crc = crc32(entry.content);
211
- isBinary = entry.binary ?? bufferIsBinary(entry.content.subarray(0, 16384));
212
- if (method === METHOD_STORE) {
213
- this.out.push(entry.content);
214
- compressedSize = size;
215
- } else {
216
- const deflated = deflateSync([entry.content], { format: "raw", level });
217
- this.out.push(deflated);
218
- compressedSize = deflated.length;
219
- }
217
+ const streamedOut = await this.writeStreamed(entry, size, method === METHOD_STORE, level);
218
+ if (!streamedOut) return `cannot stream blob ${id}`;
219
+ crc = streamedOut.crc;
220
+ isBinary = streamedOut.isBinary;
221
+ compressedSize = streamedOut.compressedSize;
220
222
  // write_zip_data_desc
221
223
  le.u32(0x08074b50);
222
224
  le.u32(crc);
@@ -228,7 +230,7 @@ export class ZipArchiveWriter implements ArchiveWriter {
228
230
  le.u32(size);
229
231
  }
230
232
  } else if (compressedSize > 0 && out) {
231
- this.out.push(out);
233
+ await this.sink.write(out);
232
234
  }
233
235
 
234
236
  let zip64DirPayload = 0;
@@ -268,12 +270,61 @@ export class ZipArchiveWriter implements ArchiveWriter {
268
270
  if (offset >= MAX32) d.u64(offset);
269
271
  }
270
272
  this.entries++;
273
+ await this.sink.flush();
271
274
  return undefined;
272
275
  }
273
276
 
277
+ /**
278
+ * A streamed blob's data (archive-zip.c's `stream` loops): the CRC-32 and the deflate
279
+ * computed as it is read, `entry_is_binary` asked of its first read (16 KiB); undefined
280
+ * when it cannot be read whole.
281
+ */
282
+ private async writeStreamed(
283
+ entry: ArchiveEntry,
284
+ size: number,
285
+ store: boolean,
286
+ level: number,
287
+ ): Promise<{ crc: number; isBinary: boolean; compressedSize: number } | undefined> {
288
+ const crc = new CRC32();
289
+ const deflater = store ? undefined : createDeflater({ format: "raw", level });
290
+ const head = new ByteBuffer(STREAM_BUFFER_SIZE);
291
+ let total = 0;
292
+ let compressedSize = 0;
293
+ const emit = async (chunks: Uint8Array[]) => {
294
+ for (const c of chunks) {
295
+ compressedSize += c.length;
296
+ await this.sink.write(c);
297
+ }
298
+ };
299
+ try {
300
+ for await (const chunk of entry.stream ?? [entry.content]) {
301
+ if (total + chunk.length > size) return undefined;
302
+ total += chunk.length;
303
+ crc.update(chunk);
304
+ if (head.length < STREAM_BUFFER_SIZE) {
305
+ head.push(chunk.subarray(0, STREAM_BUFFER_SIZE - head.length));
306
+ }
307
+ if (deflater) await emit(deflater.push(chunk));
308
+ else {
309
+ compressedSize += chunk.length;
310
+ await this.sink.write(chunk);
311
+ }
312
+ }
313
+ } catch {
314
+ return undefined;
315
+ }
316
+ if (total !== size) return undefined;
317
+ if (deflater) await emit(deflater.finish());
318
+ return {
319
+ crc: crc.getValue(),
320
+ isBinary: entry.binary ?? bufferIsBinary(head.bytes()),
321
+ compressedSize,
322
+ };
323
+ }
324
+
274
325
  /** `write_zip_trailer`. */
275
- finish(): Uint8Array {
276
- const zipOffset = this.out.length;
326
+ async finish(): Promise<Uint8Array> {
327
+ const zipOffset = this.sink.position;
277
328
  const dirBytes = this.dir.bytes();
278
329
  const clamped = this.entries > 0xffff || zipOffset > MAX32;
279
330
  this.out.push(dirBytes);
@@ -305,7 +356,7 @@ export class ZipArchiveWriter implements ArchiveWriter {
305
356
  le.u32(clamp32(zipOffset));
306
357
  le.u16(commitId ? (this.settings.hexLength ?? commitId.length) : 0);
307
358
  if (commitId) this.out.push(asciiBytes(commitId));
308
- return this.out.bytes();
359
+ return this.sink.finish();
309
360
  }
310
361
  }
311
362
 
@@ -61,6 +61,11 @@ export function bareAttributesResolver(o: {
61
61
  * check-attr --source`); the index tree still wins
62
62
  */
63
63
  sourceTree?: string;
64
+ /**
65
+ * The attribute source when none is set (git 2.43 reads a bare repository's from `HEAD`:
66
+ * attr.c's `compute_default_attr_source`); one that does not resolve gives none
67
+ */
68
+ defaultSource?: string;
64
69
  }): AttributesResolver {
65
70
  const { workingCopy } = o;
66
71
  const environment = hostEnvironmentOf(workingCopy);
@@ -88,7 +93,14 @@ export function bareAttributesResolver(o: {
88
93
  environment?.attrSource,
89
94
  configValue(workingCopy, "attr.tree"),
90
95
  );
91
- if (!setting) return undefined;
96
+ if (!setting) {
97
+ if (!o.defaultSource) return undefined;
98
+ // fromConfig: a default that names nothing is ignored, as a bad attr.tree
99
+ return resolveAttributesSource(
100
+ { name: o.defaultSource, fromConfig: true },
101
+ attributesSourceResolver(o.revisions),
102
+ );
103
+ }
92
104
  return resolveAttributesSource(setting, attributesSourceResolver(o.revisions));
93
105
  })();
94
106
  }
@@ -12,18 +12,14 @@
12
12
  * ```
13
13
  */
14
14
 
15
- import {
16
- type CompatObjects,
17
- decodeTreeBytes,
18
- type GitObjects,
19
- type ObjectId,
20
- } from "@statewalker/vcs-core";
15
+ import type { CompatObjects, GitObjects, ObjectId } from "@statewalker/vcs-core";
21
16
  import { ObjectInfoError } from "@statewalker/vcs-transport";
22
17
  import { parseGitBool } from "@statewalker/vcs-utils";
23
18
  import { decodeGitPath } from "@statewalker/vcs-utils/encoding";
24
19
  import { RemoteConfigStore } from "../../remote-config/index.js";
25
20
  import { quotePath } from "../../results/quote-path.js";
26
21
  import { PlumbingCommand, PlumbingError } from "../plumbing-command.js";
22
+ import { concatBytes, objectTypeOfMode } from "../plumbing-shared.js";
27
23
  import {
28
24
  RemoteObjectInfoCommand,
29
25
  type RemoteObjectInfoResult,
@@ -278,7 +274,7 @@ export class CatFileCommand extends PlumbingCommand {
278
274
  }
279
275
  const chunks: Uint8Array[] = [];
280
276
  for await (const c of object.content) chunks.push(c.slice());
281
- return { type: object.type, bytes: concat(chunks) };
277
+ return { type: object.type, bytes: concatBytes(chunks) };
282
278
  }
283
279
 
284
280
  /** `stream_blob`: the blob's content written chunk by chunk. */
@@ -376,19 +372,8 @@ export class CatFileCommand extends PlumbingCommand {
376
372
  return 0;
377
373
  case "pretty":
378
374
  if (object.type === "tree") {
379
- const config = RemoteConfigStore.from(this._workingCopy);
380
- const quoteFully = parseGitBool(config.value("core.quotePath")) ?? true;
381
- let out = "";
382
- for (const entry of decodeTreeBytes(object.content, {
383
- idLength: compat.compat.rawLength,
384
- checkNames: false,
385
- })) {
386
- const kind = entry.mode & S_IFMT;
387
- const type = kind === 0o040000 ? "tree" : kind === S_IFGITLINK ? "commit" : "blob";
388
- const mode = entry.mode.toString(8).padStart(6, "0");
389
- out += `${mode} ${type} ${entry.id}\t${quotePath(entry.name, quoteFully)}\n`;
390
- }
391
- await this.write(out);
375
+ // cmd_ls_tree of the compatibility id: its entries at that format's width
376
+ await this.listTree(name);
392
377
  return 0;
393
378
  }
394
379
  await this.write(
@@ -445,17 +430,19 @@ export class CatFileCommand extends PlumbingCommand {
445
430
  const entries = await this.listedTreeEntries(id);
446
431
  if (!entries) throw new PlumbingError(`fatal: Cannot read object ${id}`);
447
432
  let out = "";
448
- for (const entry of entries) {
449
- const kind = entry.mode & S_IFMT;
450
- const type = kind === 0o040000 ? "tree" : kind === S_IFGITLINK ? "commit" : "blob";
451
- const mode = entry.mode.toString(8).padStart(6, "0");
452
- out += `${mode} ${type} ${entry.id}\t${quotePath(entry.name, quoteFully)}\n`;
453
- if (out.length >= 1 << 16) {
454
- await this.write(out);
455
- out = "";
433
+ try {
434
+ for (const entry of entries) {
435
+ const mode = entry.mode.toString(8).padStart(6, "0");
436
+ out += `${mode} ${objectTypeOfMode(entry.mode)} ${entry.id}\t${quotePath(entry.name, quoteFully)}\n`;
437
+ if (out.length >= 1 << 16) {
438
+ await this.write(out);
439
+ out = "";
440
+ }
456
441
  }
442
+ } finally {
443
+ // what was listed before a corrupt entry is printed, as git's stdout is at its death
444
+ await this.write(out);
457
445
  }
458
- await this.write(out);
459
446
  }
460
447
 
461
448
  /** `<type> <object>` */
@@ -845,19 +832,6 @@ function modeLetter(mode: CatFileMode): string {
845
832
  return mode === "type" ? "t" : mode === "size" ? "s" : mode === "exists" ? "e" : "p";
846
833
  }
847
834
 
848
- function concat(chunks: Uint8Array[]): Uint8Array {
849
- if (chunks.length === 1) return chunks[0] as Uint8Array;
850
- let size = 0;
851
- for (const c of chunks) size += c.length;
852
- const out = new Uint8Array(size);
853
- let at = 0;
854
- for (const c of chunks) {
855
- out.set(c, at);
856
- at += c.length;
857
- }
858
- return out;
859
- }
860
-
861
835
  /**
862
836
  * `strbuf_getline` (`strbuf_getdelim_strip_crlf`) over the input as it arrives: each record
863
837
  * without its delimiter, and for newline-terminated input without a CR before it (`-z`'s
@@ -884,12 +858,12 @@ async function* readLines(input: CatFileInput, delimiter: number): AsyncGenerato
884
858
  const at = chunk.indexOf(delimiter, start);
885
859
  if (at < 0) break;
886
860
  const piece = chunk.subarray(start, at);
887
- const line = pending.length > 0 ? concat([...pending, piece]) : piece;
861
+ const line = pending.length > 0 ? concatBytes([...pending, piece]) : piece;
888
862
  pending = [];
889
863
  yield emit(line);
890
864
  start = at + 1;
891
865
  }
892
866
  if (start < chunk.length) pending.push(chunk.slice(start));
893
867
  }
894
- if (pending.length > 0) yield emit(concat(pending));
868
+ if (pending.length > 0) yield emit(concatBytes(pending));
895
869
  }
@@ -7,8 +7,8 @@
7
7
  * an empty value clearing the list. `GIT_HTTP_USER_AGENT`, `GIT_HTTP_MAX_RETRIES`,
8
8
  * `GIT_HTTP_RETRY_AFTER` and `GIT_HTTP_MAX_RETRY_TIME` override the configuration.
9
9
  *
10
- * Read here: `extraHeader`, `userAgent`, `followRedirects`, `emptyAuth`, `maxRetries`,
11
- * `retryAfter`, `maxRetryTime`. TLS, proxy, cookie, version and speed keys are the host
10
+ * Read here: `extraHeader`, `userAgent`, `followRedirects`, `emptyAuth`, `proactiveAuth`
11
+ * (2.46+), `maxRetries`, `retryAfter`, `maxRetryTime`. TLS, proxy, cookie, version and speed keys are the host
12
12
  * `fetch`'s business and are not read.
13
13
  *
14
14
  * @example
@@ -31,6 +31,8 @@ import type { RemoteConfigStore } from "../remote-config/index.js";
31
31
  export interface HttpConfigOptions {
32
32
  /** As git 2.43: no retries on 429 (`http.maxRetries` came with 2.52) */
33
33
  compatibility?: "2.43" | "2.56";
34
+ /** git's `warning:` lines about the configuration (`Unknown value for http.proactiveauth`) */
35
+ onWarning?(line: string): void;
34
36
  }
35
37
 
36
38
  /**
@@ -76,6 +78,16 @@ export function httpClientSettingsOf(
76
78
  case "emptyauth":
77
79
  settings.emptyAuth = value === "auto" ? "auto" : bool(key, value);
78
80
  break;
81
+ case "proactiveauth":
82
+ // git 2.46: an unknown value warns and leaves the setting as it was
83
+ if (options.compatibility === "2.43") break;
84
+ if (value === undefined) throw missingValue(key);
85
+ if (value === "auto" || value === "basic" || value === "none") {
86
+ settings.proactiveAuth = value;
87
+ } else {
88
+ options.onWarning?.("warning: Unknown value for http.proactiveauth");
89
+ }
90
+ break;
79
91
  case "followredirects":
80
92
  settings.followRedirects =
81
93
  value === "initial" ? "initial" : bool(key, value) ? "always" : "none";
@@ -113,6 +113,7 @@ export * from "./pack-refs-command.js";
113
113
  export { type PatchIdTextOptions, patchIdsOfPatchText } from "./patch-id.js";
114
114
  export * from "./patch-id-command.js";
115
115
  export * from "./plumbing-command.js";
116
+ export { CorruptTreeError } from "./plumbing-shared.js";
116
117
  export * from "./pretty-format.js";
117
118
  export * from "./promisor-remote.js";
118
119
  export * from "./promisor-remote-reply.js";