@statewalker/vcs-commands 0.10.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.
- package/dist/commands/am/am-command.d.ts.map +1 -1
- package/dist/commands/archive/archive-command.d.ts +81 -7
- package/dist/commands/archive/archive-command.d.ts.map +1 -1
- package/dist/commands/archive/archive-entry.d.ts +48 -5
- package/dist/commands/archive/archive-entry.d.ts.map +1 -1
- package/dist/commands/archive/tar-archive.d.ts +5 -2
- package/dist/commands/archive/tar-archive.d.ts.map +1 -1
- package/dist/commands/archive/zip-archive.d.ts +9 -2
- package/dist/commands/archive/zip-archive.d.ts.map +1 -1
- package/dist/commands/attributes-source.d.ts +5 -0
- package/dist/commands/attributes-source.d.ts.map +1 -1
- package/dist/commands/cat-file/cat-file-command.d.ts +9 -0
- package/dist/commands/cat-file/cat-file-command.d.ts.map +1 -1
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +9 -0
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/default-branch.d.ts +12 -0
- package/dist/commands/default-branch.d.ts.map +1 -1
- package/dist/commands/diff-command.d.ts.map +1 -1
- package/dist/commands/format-rev-command.d.ts +6 -4
- package/dist/commands/format-rev-command.d.ts.map +1 -1
- package/dist/commands/fsmonitor-ipc.d.ts +30 -0
- package/dist/commands/fsmonitor-ipc.d.ts.map +1 -0
- package/dist/commands/fsmonitor-refresh.d.ts.map +1 -1
- package/dist/commands/http-config.d.ts +4 -2
- package/dist/commands/http-config.d.ts.map +1 -1
- package/dist/commands/index.d.ts +2 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +6 -6
- package/dist/commands/log-output.d.ts +6 -0
- package/dist/commands/log-output.d.ts.map +1 -1
- package/dist/commands/ls-files-command.d.ts.map +1 -1
- package/dist/commands/ls-tree-command.d.ts.map +1 -1
- package/dist/commands/mv-command.d.ts.map +1 -1
- package/dist/commands/pathspec.d.ts.map +1 -1
- package/dist/commands/plumbing-shared.d.ts +72 -0
- package/dist/commands/plumbing-shared.d.ts.map +1 -0
- package/dist/commands/repack-command.d.ts +12 -3
- package/dist/commands/repack-command.d.ts.map +1 -1
- package/dist/commands/replace-command.d.ts.map +1 -1
- package/dist/commands/repo-command.d.ts +28 -6
- package/dist/commands/repo-command.d.ts.map +1 -1
- package/dist/commands/rerere-command.d.ts +12 -0
- package/dist/commands/rerere-command.d.ts.map +1 -1
- package/dist/commands/rerere.d.ts +22 -0
- package/dist/commands/rerere.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts +19 -2
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/rev-parse-command.d.ts +3 -7
- package/dist/commands/rev-parse-command.d.ts.map +1 -1
- package/dist/commands/revision-resolver.d.ts +24 -5
- package/dist/commands/revision-resolver.d.ts.map +1 -1
- package/dist/commands/signing.d.ts +8 -1
- package/dist/commands/signing.d.ts.map +1 -1
- package/dist/commands/status-command.d.ts +14 -1
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/submodule-add-command.d.ts +12 -0
- package/dist/commands/submodule-add-command.d.ts.map +1 -1
- package/dist/commands/submodule-update-command.d.ts +14 -0
- package/dist/commands/submodule-update-command.d.ts.map +1 -1
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/update-index-command.d.ts +21 -0
- package/dist/commands/update-index-command.d.ts.map +1 -1
- package/dist/{commands-Mlo1dxQN.js → commands-C2E51T1z.js} +942 -293
- package/dist/{fsck-CrhVMNIH.js → fsck-BjlxStsM.js} +1 -1
- package/dist/git-command.d.ts +14 -6
- package/dist/git-command.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/{maintenance-run-command-Bw21HEkH.js → maintenance-run-command-G_eWdA8O.js} +48 -17
- package/dist/remote-config/remote-config-store.d.ts +4 -1
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/{remote-transport-Bu4PGSMD.js → remote-transport-CSgTJ1BH.js} +3 -3
- package/dist/results/index.js +1 -1
- package/dist/{results-ERo9vELd.js → results-Dg1KHG8y.js} +669 -96
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/commands/am/am-command.ts +30 -14
- package/src/commands/archive/archive-command.ts +395 -59
- package/src/commands/archive/archive-entry.ts +88 -5
- package/src/commands/archive/tar-archive.ts +40 -9
- package/src/commands/archive/zip-archive.ts +72 -21
- package/src/commands/attributes-source.ts +13 -1
- package/src/commands/cat-file/cat-file-command.ts +64 -52
- package/src/commands/checkout-command.ts +22 -1
- package/src/commands/clone-command.ts +41 -2
- package/src/commands/default-branch.ts +19 -0
- package/src/commands/diff-command.ts +19 -1
- package/src/commands/format-rev-command.ts +28 -12
- package/src/commands/fsmonitor-ipc.ts +121 -0
- package/src/commands/fsmonitor-refresh.ts +7 -2
- package/src/commands/http-config.ts +14 -2
- package/src/commands/index.ts +2 -0
- package/src/commands/log-output.ts +11 -0
- package/src/commands/ls-files-command.ts +25 -33
- package/src/commands/ls-tree-command.ts +30 -22
- package/src/commands/mv-command.ts +37 -6
- package/src/commands/pathspec.ts +2 -4
- package/src/commands/plumbing-shared.ts +197 -0
- package/src/commands/repack-command.ts +44 -11
- package/src/commands/replace-command.ts +16 -4
- package/src/commands/repo-command.ts +124 -25
- package/src/commands/rerere-command.ts +17 -0
- package/src/commands/rerere.ts +144 -3
- package/src/commands/reset-command.ts +75 -3
- package/src/commands/rev-parse-command.ts +14 -28
- package/src/commands/revision-resolver.ts +85 -34
- package/src/commands/signing.ts +54 -7
- package/src/commands/status-command.ts +31 -2
- package/src/commands/submodule-add-command.ts +18 -1
- package/src/commands/submodule-update-command.ts +18 -1
- package/src/commands/tag-command.ts +33 -11
- package/src/commands/update-index-command.ts +137 -5
- package/src/git-command.ts +60 -19
- package/src/remote-config/remote-config-store.ts +11 -3
- 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
|
-
/**
|
|
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
|
|
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 =
|
|
188
|
-
if (isRegMode(mode) &&
|
|
211
|
+
let sizeInHeader = size;
|
|
212
|
+
if (isRegMode(mode) && size > USTAR_MAX) {
|
|
189
213
|
sizeInHeader = 0;
|
|
190
|
-
extRecord(ext, "size", asciiBytes(String(
|
|
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 (
|
|
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.
|
|
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.
|
|
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
|
|
101
|
+
private readonly sink: ArchiveSink;
|
|
102
|
+
private readonly out: ByteBuffer;
|
|
99
103
|
private readonly dir = new ByteBuffer(4096);
|
|
100
|
-
private readonly le
|
|
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.
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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)
|
|
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:
|
|
277
|
+
return { type: object.type, bytes: concatBytes(chunks) };
|
|
282
278
|
}
|
|
283
279
|
|
|
284
280
|
/** `stream_blob`: the blob's content written chunk by chunk. */
|
|
@@ -301,21 +297,19 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
301
297
|
|
|
302
298
|
/** cat_one_file */
|
|
303
299
|
private async catOne(name: string): Promise<number> {
|
|
304
|
-
const compat = this.compatObjects;
|
|
305
|
-
// GET_OID_HASH_ANY: a full id of the compatibility format names the object as that
|
|
306
|
-
// format sees it (its storage object converted)
|
|
307
|
-
if (compat && name.length === compat.compat.hexLength && /^[0-9a-f]+$/.test(name)) {
|
|
308
|
-
return this.catOneCompat(name, compat);
|
|
309
|
-
}
|
|
310
300
|
const resolver = this.revisionResolver();
|
|
311
301
|
let id: ObjectId | undefined;
|
|
312
302
|
try {
|
|
313
|
-
id
|
|
303
|
+
// GET_OID_HASH_ANY: an id of the compatibility format (full or abbreviated) names the
|
|
304
|
+
// object as that format sees it (its storage object converted)
|
|
305
|
+
id = await resolver.resolve(name, { onlyToDie: true, hashAny: true });
|
|
314
306
|
} finally {
|
|
315
307
|
for (const line of resolver.warnings) this.warn(line);
|
|
316
308
|
resolver.warnings.length = 0;
|
|
317
309
|
}
|
|
318
310
|
if (id === undefined) throw new PlumbingError(`fatal: Not a valid object name ${name}`);
|
|
311
|
+
const compat = this.compatIdOf(id);
|
|
312
|
+
if (compat) return this.catOneCompat(id, compat);
|
|
319
313
|
const couldNotGetInfo = () =>
|
|
320
314
|
new PlumbingError("fatal: git cat-file: could not get object info");
|
|
321
315
|
switch (this.mode) {
|
|
@@ -346,6 +340,12 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
346
340
|
}
|
|
347
341
|
}
|
|
348
342
|
|
|
343
|
+
/** The compatibility objects when `id` is an id of the compatibility format (not storage's) */
|
|
344
|
+
private compatIdOf(id: ObjectId): CompatObjects | undefined {
|
|
345
|
+
const compat = this.compatObjects;
|
|
346
|
+
return compat && id.length !== this.objectFormat.hexLength ? compat : undefined;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
349
|
/**
|
|
350
350
|
* cat_one_file for an id of the compatibility format: the object read through the map and
|
|
351
351
|
* converted (`odb_read_object_info_extended` with an id of the other format).
|
|
@@ -372,19 +372,8 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
372
372
|
return 0;
|
|
373
373
|
case "pretty":
|
|
374
374
|
if (object.type === "tree") {
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
let out = "";
|
|
378
|
-
for (const entry of decodeTreeBytes(object.content, {
|
|
379
|
-
idLength: compat.compat.rawLength,
|
|
380
|
-
checkNames: false,
|
|
381
|
-
})) {
|
|
382
|
-
const kind = entry.mode & S_IFMT;
|
|
383
|
-
const type = kind === 0o040000 ? "tree" : kind === S_IFGITLINK ? "commit" : "blob";
|
|
384
|
-
const mode = entry.mode.toString(8).padStart(6, "0");
|
|
385
|
-
out += `${mode} ${type} ${entry.id}\t${quotePath(entry.name, quoteFully)}\n`;
|
|
386
|
-
}
|
|
387
|
-
await this.write(out);
|
|
375
|
+
// cmd_ls_tree of the compatibility id: its entries at that format's width
|
|
376
|
+
await this.listTree(name);
|
|
388
377
|
return 0;
|
|
389
378
|
}
|
|
390
379
|
await this.write(
|
|
@@ -441,17 +430,19 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
441
430
|
const entries = await this.listedTreeEntries(id);
|
|
442
431
|
if (!entries) throw new PlumbingError(`fatal: Cannot read object ${id}`);
|
|
443
432
|
let out = "";
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
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
|
+
}
|
|
452
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);
|
|
453
445
|
}
|
|
454
|
-
await this.write(out);
|
|
455
446
|
}
|
|
456
447
|
|
|
457
448
|
/** `<type> <object>` */
|
|
@@ -690,7 +681,7 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
690
681
|
): Promise<void> {
|
|
691
682
|
let id: ObjectId | undefined;
|
|
692
683
|
try {
|
|
693
|
-
id = await resolver.resolve(name);
|
|
684
|
+
id = await resolver.resolve(name, { hashAny: true });
|
|
694
685
|
} finally {
|
|
695
686
|
for (const line of resolver.warnings) this.warn(line);
|
|
696
687
|
}
|
|
@@ -707,12 +698,46 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
707
698
|
});
|
|
708
699
|
}
|
|
709
700
|
|
|
701
|
+
/**
|
|
702
|
+
* batch_object_write for an id of the compatibility format (`GET_OID_HASH_ANY` in
|
|
703
|
+
* batch_one_object): the object read through the map and converted, so its id, type, size
|
|
704
|
+
* and content are the compatibility format's. Replace refs are storage ids: they do not
|
|
705
|
+
* apply to it.
|
|
706
|
+
*/
|
|
707
|
+
private async batchCompatWrite(
|
|
708
|
+
state: BatchState,
|
|
709
|
+
name: string | undefined,
|
|
710
|
+
data: BatchObjectData,
|
|
711
|
+
compat: CompatObjects,
|
|
712
|
+
): Promise<void> {
|
|
713
|
+
const object = await compat.readAsCompat(data.id);
|
|
714
|
+
if (!object) {
|
|
715
|
+
await this.write(`${name ?? data.id} missing${state.delim}`);
|
|
716
|
+
return;
|
|
717
|
+
}
|
|
718
|
+
let content = object.content;
|
|
719
|
+
if (this.useMailmap && (object.type === "commit" || object.type === "tag")) {
|
|
720
|
+
content = await this.mapIdents(content);
|
|
721
|
+
}
|
|
722
|
+
data.type = object.type;
|
|
723
|
+
data.size = content.length;
|
|
724
|
+
const header = state.plain
|
|
725
|
+
? `${data.id} ${data.type} ${data.size}${state.delim}`
|
|
726
|
+
: `${expandBatchFormat(state.format, data)}${state.delim}`;
|
|
727
|
+
await this.write(header);
|
|
728
|
+
if (!state.contents) return;
|
|
729
|
+
await this.write(content);
|
|
730
|
+
await this.write(state.delim);
|
|
731
|
+
}
|
|
732
|
+
|
|
710
733
|
/** batch_object_write */
|
|
711
734
|
private async batchObjectWrite(
|
|
712
735
|
state: BatchState,
|
|
713
736
|
name: string | undefined,
|
|
714
737
|
data: BatchObjectData,
|
|
715
738
|
): Promise<void> {
|
|
739
|
+
const compat = this.compatIdOf(data.id);
|
|
740
|
+
if (compat) return this.batchCompatWrite(state, name, data, compat);
|
|
716
741
|
const target = state.replace ? await this.replaced(data.id) : data.id;
|
|
717
742
|
const info = await this.info(target);
|
|
718
743
|
if (!info) {
|
|
@@ -807,19 +832,6 @@ function modeLetter(mode: CatFileMode): string {
|
|
|
807
832
|
return mode === "type" ? "t" : mode === "size" ? "s" : mode === "exists" ? "e" : "p";
|
|
808
833
|
}
|
|
809
834
|
|
|
810
|
-
function concat(chunks: Uint8Array[]): Uint8Array {
|
|
811
|
-
if (chunks.length === 1) return chunks[0] as Uint8Array;
|
|
812
|
-
let size = 0;
|
|
813
|
-
for (const c of chunks) size += c.length;
|
|
814
|
-
const out = new Uint8Array(size);
|
|
815
|
-
let at = 0;
|
|
816
|
-
for (const c of chunks) {
|
|
817
|
-
out.set(c, at);
|
|
818
|
-
at += c.length;
|
|
819
|
-
}
|
|
820
|
-
return out;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
835
|
/**
|
|
824
836
|
* `strbuf_getline` (`strbuf_getdelim_strip_crlf`) over the input as it arrives: each record
|
|
825
837
|
* without its delimiter, and for newline-terminated input without a CR before it (`-z`'s
|
|
@@ -846,12 +858,12 @@ async function* readLines(input: CatFileInput, delimiter: number): AsyncGenerato
|
|
|
846
858
|
const at = chunk.indexOf(delimiter, start);
|
|
847
859
|
if (at < 0) break;
|
|
848
860
|
const piece = chunk.subarray(start, at);
|
|
849
|
-
const line = pending.length > 0 ?
|
|
861
|
+
const line = pending.length > 0 ? concatBytes([...pending, piece]) : piece;
|
|
850
862
|
pending = [];
|
|
851
863
|
yield emit(line);
|
|
852
864
|
start = at + 1;
|
|
853
865
|
}
|
|
854
866
|
if (start < chunk.length) pending.push(chunk.slice(start));
|
|
855
867
|
}
|
|
856
|
-
if (pending.length > 0) yield emit(
|
|
868
|
+
if (pending.length > 0) yield emit(concatBytes(pending));
|
|
857
869
|
}
|