@osdlc/typed-git 0.17.0 → 0.21.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/CHANGELOG.md +32 -0
- package/README.md +43 -8
- package/dist/async.d.ts +26 -2
- package/dist/async.js +67 -2
- package/dist/backend.d.ts +17 -3
- package/dist/backend.js +9 -1
- package/dist/cat-file.d.ts +78 -0
- package/dist/cat-file.js +155 -0
- package/dist/client.d.ts +2 -1
- package/dist/outcome.d.ts +4 -3
- package/dist/sync.d.ts +31 -2
- package/dist/sync.js +60 -1
- package/dist/verbs.d.ts +82 -10
- package/dist/verbs.js +120 -16
- package/package.json +2 -2
package/dist/cat-file.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `git cat-file --batch` reads: many objects, byte-exact, in a few processes.
|
|
3
|
+
*
|
|
4
|
+
* The planner here is a generator that asks its driver to run git and gets
|
|
5
|
+
* the stdout bytes back, so the sync client (`Git.catFileBatch`) and the async
|
|
6
|
+
* one (`AsyncGit.catFileBatch`) share every line of the batching and parsing.
|
|
7
|
+
* Each driver supplies the bytes runner behind `rawBytesChecked`.
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_CHUNK_BYTES = 64 * 1024 * 1024;
|
|
10
|
+
/** Names per `--batch-check` run: bounds one process's input and output. */
|
|
11
|
+
const CHECK_NAMES = 10_000;
|
|
12
|
+
/** More than a `<sha> <type> <size>\n` header and the `\n` after the content take. */
|
|
13
|
+
const OBJECT_OVERHEAD = 160;
|
|
14
|
+
/** Git's binary test: a NUL in the first 8000 bytes. */
|
|
15
|
+
const BINARY_WINDOW = 8000;
|
|
16
|
+
// git reads names a line at a time and drops a CR before the LF, so `foo\r`
|
|
17
|
+
// would be read as `foo` and its entry filed under the wrong name.
|
|
18
|
+
function checkNames(names) {
|
|
19
|
+
const unique = new Set();
|
|
20
|
+
for (const name of names) {
|
|
21
|
+
if (typeof name !== 'string' || name === '' || /[\n\0]|\r$/.test(name)) {
|
|
22
|
+
throw new TypeError(`typed-git: catFileBatch: a name must be a non-empty string with no newline, NUL or trailing CR (got ${JSON.stringify(name)})`);
|
|
23
|
+
}
|
|
24
|
+
unique.add(name);
|
|
25
|
+
}
|
|
26
|
+
return [...unique];
|
|
27
|
+
}
|
|
28
|
+
function limit(option, value, fallback, zeroOk) {
|
|
29
|
+
const n = value ?? fallback;
|
|
30
|
+
if (typeof n !== 'number' || Number.isNaN(n) || n < 0 || (!zeroOk && n === 0)) {
|
|
31
|
+
throw new TypeError(`typed-git: catFileBatch: ${option} must be a ${zeroOk ? 'non-negative' : 'positive'} number (got ${JSON.stringify(n)})`);
|
|
32
|
+
}
|
|
33
|
+
return n;
|
|
34
|
+
}
|
|
35
|
+
/** Parses the `--batch-check` answer for `names`: sets `missing` names in `out` and returns the others, in order. */
|
|
36
|
+
function parseCheck(stdout, names, out) {
|
|
37
|
+
const lines = stdout.toString('utf8').split('\n');
|
|
38
|
+
lines.pop(); // the empty string after the trailing newline
|
|
39
|
+
if (lines.length !== names.length) {
|
|
40
|
+
throw new Error(`typed-git: catFileBatch: git answered ${lines.length} lines for ${names.length} names`);
|
|
41
|
+
}
|
|
42
|
+
const found = [];
|
|
43
|
+
lines.forEach((line, i) => {
|
|
44
|
+
const name = names[i];
|
|
45
|
+
if (line.endsWith(' missing') || line.endsWith(' ambiguous')) {
|
|
46
|
+
out.set(name, { kind: 'missing' });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const m = /^([0-9a-f]+) (\S+) (\d+)$/.exec(line);
|
|
50
|
+
if (m === null) {
|
|
51
|
+
throw new Error(`typed-git: catFileBatch: cannot read git's answer for ${name}: ${line}`);
|
|
52
|
+
}
|
|
53
|
+
found.push({ name, sha: m[1], type: m[2], size: Number(m[3]) });
|
|
54
|
+
});
|
|
55
|
+
return found;
|
|
56
|
+
}
|
|
57
|
+
/** Reads `blobs`' headers and content, in order, from one `--batch` stdout. */
|
|
58
|
+
function parseContent(stdout, blobs) {
|
|
59
|
+
const out = new Map();
|
|
60
|
+
let at = 0;
|
|
61
|
+
for (const b of blobs) {
|
|
62
|
+
const eol = stdout.indexOf(0x0a, at);
|
|
63
|
+
if (eol < 0)
|
|
64
|
+
throw new Error(`typed-git: catFileBatch: git's output for ${b.name} is cut short`);
|
|
65
|
+
const header = stdout.toString('utf8', at, eol);
|
|
66
|
+
if (header !== `${b.sha} blob ${b.size}`) {
|
|
67
|
+
throw new Error(`typed-git: catFileBatch: unexpected header for ${b.name} (expected "${b.sha} blob ${b.size}", got "${header}")`);
|
|
68
|
+
}
|
|
69
|
+
const start = eol + 1;
|
|
70
|
+
const end = start + b.size;
|
|
71
|
+
if (end >= stdout.length) {
|
|
72
|
+
throw new Error(`typed-git: catFileBatch: git's output for ${b.name} is cut short`);
|
|
73
|
+
}
|
|
74
|
+
const bytes = stdout.subarray(start, end);
|
|
75
|
+
const binary = bytes.subarray(0, BINARY_WINDOW).includes(0);
|
|
76
|
+
out.set(b.name, { kind: binary ? 'binary' : 'text', sha: b.sha, size: b.size, bytes });
|
|
77
|
+
at = end + 1;
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
/** `entries` in the order of `names`, a repeated name once. */
|
|
82
|
+
export function inOrder(names, entries) {
|
|
83
|
+
const out = new Map();
|
|
84
|
+
for (const name of names)
|
|
85
|
+
out.set(name, entries.get(name));
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Plan the reads of `names`: `--batch-check` for their sizes, then `--batch`
|
|
90
|
+
* for the blobs within `maxBytes`, grouped so a process is asked for about
|
|
91
|
+
* `chunkBytes`. Yields a {@link CatFileRun} for the driver to run, which sends
|
|
92
|
+
* back the stdout bytes, and a {@link CatFileChunk} for each group of finished
|
|
93
|
+
* entries. The first chunk also holds every entry that needed no content read.
|
|
94
|
+
*/
|
|
95
|
+
export function* planCatFileBatch(names, opts = {}) {
|
|
96
|
+
const unique = checkNames(names);
|
|
97
|
+
const maxBytes = limit('maxBytes', opts.maxBytes, Infinity, true);
|
|
98
|
+
const chunkBytes = limit('chunkBytes', opts.chunkBytes, DEFAULT_CHUNK_BYTES, false);
|
|
99
|
+
const settled = new Map();
|
|
100
|
+
const wanted = [];
|
|
101
|
+
for (let i = 0; i < unique.length; i += CHECK_NAMES) {
|
|
102
|
+
const part = unique.slice(i, i + CHECK_NAMES);
|
|
103
|
+
const stdout = yield {
|
|
104
|
+
type: 'run',
|
|
105
|
+
argv: ['cat-file', '--batch-check'],
|
|
106
|
+
input: part.join('\n') + '\n',
|
|
107
|
+
maxOutputBytes: undefined,
|
|
108
|
+
};
|
|
109
|
+
for (const f of parseCheck(stdout, part, settled)) {
|
|
110
|
+
if (f.type !== 'blob') {
|
|
111
|
+
settled.set(f.name, { kind: 'not-blob', type: f.type, sha: f.sha, size: f.size });
|
|
112
|
+
}
|
|
113
|
+
else if (f.size > maxBytes) {
|
|
114
|
+
settled.set(f.name, { kind: 'too-large', sha: f.sha, size: f.size });
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
wanted.push(f);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
let group = [];
|
|
122
|
+
let groupBytes = 0;
|
|
123
|
+
const groups = [];
|
|
124
|
+
for (const f of wanted) {
|
|
125
|
+
if (group.length > 0 && groupBytes + f.size > chunkBytes) {
|
|
126
|
+
groups.push(group);
|
|
127
|
+
group = [];
|
|
128
|
+
groupBytes = 0;
|
|
129
|
+
}
|
|
130
|
+
group.push(f);
|
|
131
|
+
groupBytes += f.size;
|
|
132
|
+
}
|
|
133
|
+
if (group.length > 0)
|
|
134
|
+
groups.push(group);
|
|
135
|
+
if (groups.length === 0) {
|
|
136
|
+
yield { type: 'chunk', entries: settled };
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
let first = true;
|
|
140
|
+
for (const g of groups) {
|
|
141
|
+
const stdout = yield {
|
|
142
|
+
type: 'run',
|
|
143
|
+
argv: ['cat-file', '--batch'],
|
|
144
|
+
// By sha, so a ref that moves after the size check cannot change the object.
|
|
145
|
+
input: g.map((f) => f.sha).join('\n') + '\n',
|
|
146
|
+
maxOutputBytes: g.reduce((sum, f) => sum + f.size + OBJECT_OVERHEAD, 0),
|
|
147
|
+
};
|
|
148
|
+
const entries = parseContent(stdout, g);
|
|
149
|
+
if (first)
|
|
150
|
+
for (const [name, entry] of settled)
|
|
151
|
+
entries.set(name, entry);
|
|
152
|
+
first = false;
|
|
153
|
+
yield { type: 'chunk', entries };
|
|
154
|
+
}
|
|
155
|
+
}
|
package/dist/client.d.ts
CHANGED
|
@@ -22,5 +22,6 @@ export { classifyGitFailure, describeGitFailure, UnsupportedRequest, type GitFai
|
|
|
22
22
|
export { type Soft, type TriedAsync, type TriedSync } from './outcome.ts';
|
|
23
23
|
export { GIT_FEATURES, GIT_FLOOR, gitSupports, type GitFeature, type GitFeatureSpec, type GitRelease, type UnsupportedGit, } from './features.ts';
|
|
24
24
|
export { compareGitVersions, parseGitVersion, type GitVersion } from './git-version.ts';
|
|
25
|
-
export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type ForceLease, type GcOptions, type GrepOptions, type HashObjectOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type MktreeEntry, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type UpdateRefOptions, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
|
|
25
|
+
export { forceWithLeaseArg, parseRefRows, PUSH_REJECTIONS, REF_FORMAT, type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CheckoutOptions, type CleanOptions, type CloneOptions, type CommitFlags, type CommitOptions, type ConfigGetOptions, type ConfigScope, type ConfigSetOptions, type ConflictSide, type DiffCheckOptions, type DiffCheckResult, type DiffEntry, type DiffNameOnlyOptions, type DiffNameStatusOptions, type DiffStatOptions, type DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type ForceLease, type GcOptions, type GrepOptions, type HashObjectOptions, type InitOptions, type IntegrationOutcome, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type MktreeEntry, type NumstatEntry, type PushFlag, type PushOptions, type PushRefResult, type PushRejection, type PushRejectionInfo, type PushReport, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type RemoteRef, type RemoteSetBranchesOptions, type RemoteSetHeadOptions, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type IndexSubmodule, type TaggedFile, type TreeEntry, type UnmergedEntry, type UpdateRefOptions, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, } from './verbs.ts';
|
|
26
26
|
export { asAsync, CommandFailed, runChecked, runCheckedAsync, spawnRunner, spawnRunnerAsync, spawnRunnerBytes, spawnRunnerBytesAsync, type AsyncBytesCommandRunner, type AsyncCommandRunner, type AsyncCommandRunOptions, type BytesCommandRunner, type CommandResult, type CommandRunner, type CommandRunOptions, } from '@osdlc/command-seam';
|
|
27
|
+
export type { CatFileBatchOptions, CatFileEntry } from './cat-file.ts';
|
package/dist/outcome.d.ts
CHANGED
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
import type { Result } from '@osdlc/result';
|
|
21
21
|
import { type GitFailure } from './failure.ts';
|
|
22
22
|
/**
|
|
23
|
-
* The methods `try` mirrors: everything except the `raw*` methods,
|
|
24
|
-
*
|
|
23
|
+
* The methods `try` mirrors: everything except the `raw*` methods, the
|
|
24
|
+
* `catFileBatchChunks` generator (git runs as it is iterated, after any
|
|
25
|
+
* `try` could catch), `at`, and `try` itself. The unchecked `raw*` methods already return a
|
|
25
26
|
* `CommandResult` and never throw for a failed git; the checked ones exist
|
|
26
27
|
* to throw. `at(cwd)` returns a new client that has its own `.try`. The
|
|
27
28
|
* types leave them out, but the runtime proxy wraps every function property,
|
|
28
29
|
* these included.
|
|
29
30
|
*/
|
|
30
|
-
type Triable<C> = Omit<C, 'raw' | 'rawChecked' | 'rawBytes' | 'rawBytesChecked' | 'at' | 'try' | 'soft' | 'cwd'>;
|
|
31
|
+
type Triable<C> = Omit<C, 'raw' | 'rawChecked' | 'rawBytes' | 'rawBytesChecked' | 'catFileBatchChunks' | 'at' | 'try' | 'soft' | 'cwd'>;
|
|
31
32
|
/** Every synchronous client method, returning a `Result<T, GitFailure>`. */
|
|
32
33
|
export type TriedSync<C> = {
|
|
33
34
|
[K in keyof Triable<C>]: Triable<C>[K] extends (...a: infer A) => infer R ? (...a: A) => Result<R, GitFailure> : never;
|
package/dist/sync.d.ts
CHANGED
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
* service's compare-and-swap ref operations. That is not general git.
|
|
17
17
|
*/
|
|
18
18
|
import { type BytesCommandRunner, type CommandResult, type CommandRunner } from '@osdlc/command-seam';
|
|
19
|
+
import { type CatFileBatchOptions, type CatFileEntry } from './cat-file.ts';
|
|
19
20
|
import { type GitVersion } from './git-version.ts';
|
|
20
21
|
import { type Soft, type TriedSync } from './outcome.ts';
|
|
21
22
|
import { type RemoteCoordinate } from './remote-url.ts';
|
|
22
|
-
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffTextOptions, type DiffTreeOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
23
|
+
import { type AddOptions, type AheadBehind, type CherryEntry, type CommitTreeOptions, type CommitOptions, type HashObjectOptions, type MktreeEntry, type UpdateRefOptions, type CheckoutOptions, type ConfigGetOptions, type CloneOptions, type ConflictSide, type MergeOptions, type MergeOutcome, type MergeTreeOptions, type MergeTreeOutcome, type RebaseOptions, type RebaseOutcome, type RemoteGetUrlOptions, type IndexSubmodule, type TaggedFile, type UnmergedEntry, type ConfigSetOptions, type DiffEntry, type DiffNameOnlyOptions, type DiffStatOptions, type DiffNameStatusOptions, type DiffAddedFileOptions, type DiffTextOptions, type DiffTreeOptions, type FetchManyOptions, type FetchOptions, type ForEachRefOptions, type GrepOptions, type InitOptions, type LogOptions, type IgnoreMatch, type LsFilesOptions, type LsRemoteOptions, type LsTreeOptions, type NumstatEntry, type PushReport, type RemoteRef, type CleanOptions, type DiffCheckOptions, type DiffCheckResult, type StatusEntriesOptions, type StatusEntry, type StatusPorcelainOptions, type TreeEntry, type Worktree, type WorktreeAddOptions, type WorktreeMoveOptions, type GcOptions, type PushOptions, type RemoteSetBranchesOptions, type RemoteSetHeadOptions } from './verbs.ts';
|
|
23
24
|
/**
|
|
24
25
|
* Per-call concerns that are not part of the operation itself.
|
|
25
26
|
*
|
|
@@ -166,6 +167,26 @@ export declare class Git {
|
|
|
166
167
|
rawBytesChecked(argv: string[], opts?: GitSyncCallOptions & {
|
|
167
168
|
input?: string | undefined;
|
|
168
169
|
}): CommandResult<Buffer>;
|
|
170
|
+
/**
|
|
171
|
+
* Many objects at once, byte-exact: `names` are anything `git cat-file`
|
|
172
|
+
* reads, such as `rev:path` or a sha. Runs `cat-file --batch-check` for the
|
|
173
|
+
* sizes, then `cat-file --batch` for the blobs within `maxBytes`, a few
|
|
174
|
+
* processes in all, on the `bytesRunner`. The map is keyed by the names
|
|
175
|
+
* given. Throws the classified failure if git fails, `UnsupportedRequest`
|
|
176
|
+
* when the client has no bytes runner, and `TypeError` for a name that is
|
|
177
|
+
* empty or holds a newline, a NUL or a trailing CR. See {@link CatFileEntry}.
|
|
178
|
+
*
|
|
179
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
180
|
+
*/
|
|
181
|
+
catFileBatch(names: readonly string[], opts?: GitSyncCallOptions & CatFileBatchOptions): Map<string, CatFileEntry>;
|
|
182
|
+
/**
|
|
183
|
+
* {@link Git.catFileBatch} one group of blobs at a time (about `chunkBytes`
|
|
184
|
+
* each), so a caller can use the bytes and drop them before the next read.
|
|
185
|
+
* The first map also holds every entry that needed no content read.
|
|
186
|
+
*
|
|
187
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
188
|
+
*/
|
|
189
|
+
catFileBatchChunks(names: readonly string[], opts?: GitSyncCallOptions & CatFileBatchOptions): Generator<Map<string, CatFileEntry>, void, undefined>;
|
|
169
190
|
private bytes;
|
|
170
191
|
/** The verb's argv, after this client's `--git-dir` / `--work-tree` flags. */
|
|
171
192
|
private argv;
|
|
@@ -322,7 +343,7 @@ export declare class Git {
|
|
|
322
343
|
* One untracked file rendered as an all-added diff. A path git cannot read
|
|
323
344
|
* throws. See `diffAddedFile` in `verbs.ts`.
|
|
324
345
|
*/
|
|
325
|
-
diffAddedFile(relPath: string, opts?: GitSyncCallOptions): string;
|
|
346
|
+
diffAddedFile(relPath: string, opts?: GitSyncCallOptions & DiffAddedFileOptions): string;
|
|
326
347
|
/** `for-each-ref` rows, one line each, in the caller's format. */
|
|
327
348
|
forEachRef(pattern: string | string[], opts?: GitSyncCallOptions & ForEachRefOptions): string[];
|
|
328
349
|
/**
|
|
@@ -390,6 +411,10 @@ export declare class Git {
|
|
|
390
411
|
hashObject(content: string, opts?: GitSyncCallOptions & HashObjectOptions): string;
|
|
391
412
|
/** Write a tree of `entries` and return its sha; no ref moves. See `mktree` in `verbs.ts`. */
|
|
392
413
|
mktree(entries: readonly MktreeEntry[], opts?: GitSyncCallOptions): string;
|
|
414
|
+
/** Load `rev`'s tree into the index; pass `env: { GIT_INDEX_FILE }` to use a temporary one. See `readTree` in `verbs.ts`. */
|
|
415
|
+
readTree(rev: string, opts?: GitSyncCallOptions): void;
|
|
416
|
+
/** Write the index as a tree and return its sha; no ref moves. See `writeTree` in `verbs.ts`. */
|
|
417
|
+
writeTree(opts?: GitSyncCallOptions): string;
|
|
393
418
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
394
419
|
remotes(opts?: GitSyncCallOptions): string[];
|
|
395
420
|
/**
|
|
@@ -421,6 +446,8 @@ export declare class Git {
|
|
|
421
446
|
remoteOwnerRepo(remote?: string, opts?: GitSyncCallOptions): RemoteCoordinate | null;
|
|
422
447
|
/** `git fetch <remote> [refspec…]`. See {@link FetchOptions} for the flags. */
|
|
423
448
|
fetch(remote: string, refspec?: string | string[] | undefined, opts?: GitSyncCallOptions & FetchOptions): void;
|
|
449
|
+
/** `git fetch --multiple <remote>…`. See {@link FetchManyOptions}. */
|
|
450
|
+
fetchMany(remotes: readonly string[], opts?: GitSyncCallOptions & FetchManyOptions): void;
|
|
424
451
|
/** Stage paths; `all` / `update` are `git add -A` / `-u`. */
|
|
425
452
|
add(paths: string[], opts?: GitSyncCallOptions & AddOptions): void;
|
|
426
453
|
/**
|
|
@@ -488,6 +515,8 @@ export declare class Git {
|
|
|
488
515
|
worktreeUnlock(path: string, opts?: GitSyncCallOptions): void;
|
|
489
516
|
/** `git worktree prune`. */
|
|
490
517
|
worktreePrune(opts?: GitSyncCallOptions): void;
|
|
518
|
+
/** `git submodule update --init --recursive --checkout`, refusing `file` and `ext` URLs. See `submoduleUpdate` in verbs.ts. */
|
|
519
|
+
submoduleUpdate(opts?: GitSyncCallOptions): void;
|
|
491
520
|
/** `git remote add <name> <url>`. */
|
|
492
521
|
remoteAdd(name: string, url: string, opts?: GitSyncCallOptions): void;
|
|
493
522
|
/**
|
package/dist/sync.js
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { basename, dirname, resolve } from 'node:path';
|
|
19
19
|
import { spawnRunner, spawnRunnerBytes, } from '@osdlc/command-seam';
|
|
20
|
+
import { inOrder, planCatFileBatch, } from "./cat-file.js";
|
|
20
21
|
import { UnsupportedRequest } from "./failure.js";
|
|
21
22
|
import { versionedVerb } from "./features.js";
|
|
22
23
|
import { pinnedGitVersion, probeGitVersion } from "./git-version.js";
|
|
@@ -170,6 +171,48 @@ export class Git {
|
|
|
170
171
|
const ran = this.argv(argv);
|
|
171
172
|
return gateBytes(this.bytes().run(ran, this.runOpts(opts)), ran);
|
|
172
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Many objects at once, byte-exact: `names` are anything `git cat-file`
|
|
176
|
+
* reads, such as `rev:path` or a sha. Runs `cat-file --batch-check` for the
|
|
177
|
+
* sizes, then `cat-file --batch` for the blobs within `maxBytes`, a few
|
|
178
|
+
* processes in all, on the `bytesRunner`. The map is keyed by the names
|
|
179
|
+
* given. Throws the classified failure if git fails, `UnsupportedRequest`
|
|
180
|
+
* when the client has no bytes runner, and `TypeError` for a name that is
|
|
181
|
+
* empty or holds a newline, a NUL or a trailing CR. See {@link CatFileEntry}.
|
|
182
|
+
*
|
|
183
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
184
|
+
*/
|
|
185
|
+
catFileBatch(names, opts = {}) {
|
|
186
|
+
const all = new Map();
|
|
187
|
+
for (const chunk of this.catFileBatchChunks(names, opts)) {
|
|
188
|
+
for (const [name, entry] of chunk)
|
|
189
|
+
all.set(name, entry);
|
|
190
|
+
}
|
|
191
|
+
return inOrder(names, all);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* {@link Git.catFileBatch} one group of blobs at a time (about `chunkBytes`
|
|
195
|
+
* each), so a caller can use the bytes and drop them before the next read.
|
|
196
|
+
* The first map also holds every entry that needed no content read.
|
|
197
|
+
*
|
|
198
|
+
* @experimental command-seam's bytes runners are experimental.
|
|
199
|
+
*/
|
|
200
|
+
*catFileBatchChunks(names, opts = {}) {
|
|
201
|
+
const { maxBytes, chunkBytes, ...call } = opts;
|
|
202
|
+
const plan = planCatFileBatch(names, { maxBytes, chunkBytes });
|
|
203
|
+
let step = plan.next();
|
|
204
|
+
while (step.done !== true) {
|
|
205
|
+
if (step.value.type === 'chunk') {
|
|
206
|
+
yield step.value.entries;
|
|
207
|
+
step = plan.next();
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
const { argv, input, maxOutputBytes } = step.value;
|
|
211
|
+
const run = { ...call, input, maxOutputBytes: call.maxOutputBytes ?? maxOutputBytes };
|
|
212
|
+
step = plan.next(this.rawBytesChecked(argv, run).stdout);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
173
216
|
bytes() {
|
|
174
217
|
if (this.bytesRunner === undefined) {
|
|
175
218
|
throw new UnsupportedRequest('rawBytes', 'Git with a runner and no bytesRunner');
|
|
@@ -460,7 +503,7 @@ export class Git {
|
|
|
460
503
|
* throws. See `diffAddedFile` in `verbs.ts`.
|
|
461
504
|
*/
|
|
462
505
|
diffAddedFile(relPath, opts = {}) {
|
|
463
|
-
return this.exec(v.diffAddedFile(relPath), opts);
|
|
506
|
+
return this.exec(v.diffAddedFile(relPath, opts), opts);
|
|
464
507
|
}
|
|
465
508
|
/** `for-each-ref` rows, one line each, in the caller's format. */
|
|
466
509
|
forEachRef(pattern, opts = {}) {
|
|
@@ -565,6 +608,14 @@ export class Git {
|
|
|
565
608
|
mktree(entries, opts = {}) {
|
|
566
609
|
return this.exec(v.mktree(entries), opts);
|
|
567
610
|
}
|
|
611
|
+
/** Load `rev`'s tree into the index; pass `env: { GIT_INDEX_FILE }` to use a temporary one. See `readTree` in `verbs.ts`. */
|
|
612
|
+
readTree(rev, opts = {}) {
|
|
613
|
+
this.exec(v.readTree(rev), opts);
|
|
614
|
+
}
|
|
615
|
+
/** Write the index as a tree and return its sha; no ref moves. See `writeTree` in `verbs.ts`. */
|
|
616
|
+
writeTree(opts = {}) {
|
|
617
|
+
return this.exec(v.writeTree(), opts);
|
|
618
|
+
}
|
|
568
619
|
/** Configured remote names (`git remote`); `[]` when there are none. */
|
|
569
620
|
remotes(opts = {}) {
|
|
570
621
|
return this.exec(v.remote(), opts);
|
|
@@ -612,6 +663,10 @@ export class Git {
|
|
|
612
663
|
fetch(remote, refspec, opts = {}) {
|
|
613
664
|
this.exec(v.fetch(remote, refspec, opts), opts);
|
|
614
665
|
}
|
|
666
|
+
/** `git fetch --multiple <remote>…`. See {@link FetchManyOptions}. */
|
|
667
|
+
fetchMany(remotes, opts = {}) {
|
|
668
|
+
this.exec(v.fetchMany(remotes, opts), opts);
|
|
669
|
+
}
|
|
615
670
|
/** Stage paths; `all` / `update` are `git add -A` / `-u`. */
|
|
616
671
|
add(paths, opts = {}) {
|
|
617
672
|
this.exec(v.add(paths, opts), opts);
|
|
@@ -707,6 +762,10 @@ export class Git {
|
|
|
707
762
|
worktreePrune(opts = {}) {
|
|
708
763
|
this.exec(v.worktreePrune(), opts);
|
|
709
764
|
}
|
|
765
|
+
/** `git submodule update --init --recursive --checkout`, refusing `file` and `ext` URLs. See `submoduleUpdate` in verbs.ts. */
|
|
766
|
+
submoduleUpdate(opts = {}) {
|
|
767
|
+
this.exec(v.submoduleUpdate(), opts);
|
|
768
|
+
}
|
|
710
769
|
/** `git remote add <name> <url>`. */
|
|
711
770
|
remoteAdd(name, url, opts = {}) {
|
|
712
771
|
this.exec(v.remoteAdd(name, url), opts);
|
package/dist/verbs.d.ts
CHANGED
|
@@ -526,6 +526,8 @@ export interface ForEachRefOptions {
|
|
|
526
526
|
sort?: string | undefined;
|
|
527
527
|
/** `--count=` cap on the rows returned. */
|
|
528
528
|
count?: number | undefined;
|
|
529
|
+
/** `--contains=` commit: only refs whose history includes it. */
|
|
530
|
+
contains?: string | undefined;
|
|
529
531
|
}
|
|
530
532
|
/** The `forEachRef` format {@link refs} parses: sha, TAB, full refname. */
|
|
531
533
|
export declare const REF_FORMAT = "%(objectname)%09%(refname)";
|
|
@@ -759,30 +761,48 @@ export interface DiffTextOptions {
|
|
|
759
761
|
* The patch is ASCII (base85), so the decode to a string keeps it intact.
|
|
760
762
|
*/
|
|
761
763
|
binary?: boolean | undefined;
|
|
764
|
+
/**
|
|
765
|
+
* `--unified=<n>`: lines of context around each change. Default 3, whatever
|
|
766
|
+
* `diff.context` says; 0 gives a patch of the changed lines alone. A
|
|
767
|
+
* non-negative integer, else the verb throws a `TypeError`.
|
|
768
|
+
*/
|
|
769
|
+
context?: number | undefined;
|
|
770
|
+
/**
|
|
771
|
+
* `-M`: detect renames, whatever `diff.renames` says, so a moved file reads
|
|
772
|
+
* as one `rename from`/`rename to` patch and not as a delete plus an add.
|
|
773
|
+
* Off by default: without it `diff.renames` applies (git's own default is
|
|
774
|
+
* on).
|
|
775
|
+
*/
|
|
776
|
+
findRenames?: boolean | undefined;
|
|
762
777
|
/** Pathspecs, passed after `--`. */
|
|
763
778
|
paths?: string[] | undefined;
|
|
764
779
|
}
|
|
780
|
+
/** Options for {@link diffAddedFile}. */
|
|
781
|
+
export interface DiffAddedFileOptions {
|
|
782
|
+
/** `--unified=<n>`: lines of context. As {@link DiffTextOptions.context}. */
|
|
783
|
+
context?: number | undefined;
|
|
784
|
+
}
|
|
765
785
|
/**
|
|
766
786
|
* The unified diff text (`git diff --no-color --no-ext-diff --no-textconv
|
|
767
787
|
* --src-prefix=a/ --dst-prefix=b/ --no-relative --submodule=short
|
|
768
|
-
* --unified
|
|
788
|
+
* --unified=<context> [--cached] [--binary] [-M] [rev] [--] [paths]`), for the same rev
|
|
769
789
|
* and staged shape {@link diffNameStatus} lists paths for. `--` is passed
|
|
770
790
|
* once, when there is a rev or a path. Empty when nothing differs.
|
|
771
791
|
* {@link diffNameOnly} selects the same paths except under `diff.relative`,
|
|
772
792
|
* which it still follows.
|
|
773
793
|
*
|
|
774
|
-
* The text is a plain unified diff with `a/` and `b/` prefixes
|
|
775
|
-
* lines of context. The flags that are always passed turn off colour codes
|
|
794
|
+
* The text is a plain unified diff with `a/` and `b/` prefixes. The flags that are always passed turn off colour codes
|
|
776
795
|
* (`color.ui`, `color.diff`), an external diff tool (`diff.external`, a
|
|
777
796
|
* `diff.<driver>.command`), textconv conversion, other prefixes
|
|
778
797
|
* (`diff.noprefix`, `diff.mnemonicPrefix`, `diff.srcPrefix`,
|
|
779
798
|
* `diff.dstPrefix`) and `diff.relative`, which with a cwd below the
|
|
780
799
|
* repository root would drop changes outside it. They also keep a submodule
|
|
781
800
|
* change as a `Subproject commit` patch, whatever `diff.submodule` says, and
|
|
782
|
-
* the context at
|
|
783
|
-
* still apply: rename detection (`diff.renames
|
|
784
|
-
* `
|
|
785
|
-
*
|
|
801
|
+
* the context at `context` lines (default three), whatever `diff.context`
|
|
802
|
+
* says. Other settings still apply: rename detection (`diff.renames`, unless
|
|
803
|
+
* `findRenames` pins it on), `diff.ignoreSubmodules` and `diff.algorithm`; so
|
|
804
|
+
* does the `GIT_DIFF_OPTS` environment variable, where `-u0` overrides the
|
|
805
|
+
* lines of context. The rev is followed by `--`, so git never reads it as a
|
|
786
806
|
* path: a rev that names a file but no revision throws, and a branch that
|
|
787
807
|
* shares its name with a file works.
|
|
788
808
|
*
|
|
@@ -799,7 +819,7 @@ export declare function diffText(rev?: string | undefined, opts?: DiffTextOption
|
|
|
799
819
|
/**
|
|
800
820
|
* One untracked file rendered as an all-added diff (`diff --no-color
|
|
801
821
|
* --no-ext-diff --no-textconv --src-prefix=a/ --dst-prefix=b/ --no-relative
|
|
802
|
-
* --submodule=short --unified
|
|
822
|
+
* --submodule=short --unified=<context> --no-index -- /dev/null <path>`), so a new
|
|
803
823
|
* file reaches a consumer in the same shape as a modified one: the flags are
|
|
804
824
|
* the ones {@link diffText} passes, and the text is as plain. An empty
|
|
805
825
|
* existing file still gives a diff header.
|
|
@@ -809,7 +829,7 @@ export declare function diffText(rev?: string | undefined, opts?: DiffTextOption
|
|
|
809
829
|
* for a path it cannot read; that throws the classified failure. Exit 2 (a usage or
|
|
810
830
|
* read error) throws too.
|
|
811
831
|
*/
|
|
812
|
-
export declare function diffAddedFile(relPath: string): GitVerb<string>;
|
|
832
|
+
export declare function diffAddedFile(relPath: string, opts?: DiffAddedFileOptions): GitVerb<string>;
|
|
813
833
|
/**
|
|
814
834
|
* The paths and statuses one commit changed (`git diff-tree --name-status -z`).
|
|
815
835
|
*
|
|
@@ -918,6 +938,21 @@ export interface CommitTreeOptions {
|
|
|
918
938
|
* this throws. `absent: []`, and a reply that is not a sha throws.
|
|
919
939
|
*/
|
|
920
940
|
export declare function commitTree(tree: string, opts: CommitTreeOptions): GitVerb<string>;
|
|
941
|
+
/**
|
|
942
|
+
* Load `rev`'s tree into the index (`git read-tree <rev>`), replacing it.
|
|
943
|
+
*
|
|
944
|
+
* It leaves the working tree alone. Run it with `env: { GIT_INDEX_FILE }` on
|
|
945
|
+
* the call to seed a temporary index, so the repository's own index is not
|
|
946
|
+
* touched. `absent: []`.
|
|
947
|
+
*/
|
|
948
|
+
export declare function readTree(rev: string): GitVerb<void>;
|
|
949
|
+
/**
|
|
950
|
+
* Write the index as a tree object and print its sha (`git write-tree`).
|
|
951
|
+
*
|
|
952
|
+
* It writes objects and no ref. A conflicted index makes git exit 128 and
|
|
953
|
+
* this throws; a reply that is not a sha throws. `absent: []`.
|
|
954
|
+
*/
|
|
955
|
+
export declare function writeTree(): GitVerb<string>;
|
|
921
956
|
/** Options for {@link hashObject}. */
|
|
922
957
|
export interface HashObjectOptions {
|
|
923
958
|
/**
|
|
@@ -1068,6 +1103,22 @@ export interface FetchOptions {
|
|
|
1068
1103
|
* `refspec` takes an array, for fetching several refs in one invocation.
|
|
1069
1104
|
*/
|
|
1070
1105
|
export declare function fetch(remote: string, refspec?: string | string[] | undefined, opts?: FetchOptions): GitVerb<void>;
|
|
1106
|
+
/** Options for {@link fetchMany}. */
|
|
1107
|
+
export interface FetchManyOptions extends Omit<FetchOptions, 'depth'> {
|
|
1108
|
+
/**
|
|
1109
|
+
* `--jobs=<n>` — fetch up to `n` remotes at once. Default: git's own
|
|
1110
|
+
* (`fetch.parallel`, 1 unless set). Anything but a positive integer throws a
|
|
1111
|
+
* `TypeError`.
|
|
1112
|
+
*/
|
|
1113
|
+
jobs?: number | undefined;
|
|
1114
|
+
}
|
|
1115
|
+
/**
|
|
1116
|
+
* `git fetch --multiple <remote>…`: every remote in one invocation, in
|
|
1117
|
+
* parallel with `jobs`. Git fetches each remote it can and exits non-zero
|
|
1118
|
+
* when any failed, naming it on stderr; the classified failure carries that
|
|
1119
|
+
* text. Throws a `TypeError` for an empty list.
|
|
1120
|
+
*/
|
|
1121
|
+
export declare function fetchMany(remotes: readonly string[], opts?: FetchManyOptions): GitVerb<void>;
|
|
1071
1122
|
/** Options for {@link add}. */
|
|
1072
1123
|
export interface AddOptions {
|
|
1073
1124
|
/** `--all` — stage deletions and untracked files too, not just changes. */
|
|
@@ -1367,10 +1418,13 @@ export declare function resetHard(rev: string): GitVerb<void>;
|
|
|
1367
1418
|
export interface CleanOptions {
|
|
1368
1419
|
/** `-d` — also delete untracked directories. */
|
|
1369
1420
|
directories?: boolean | undefined;
|
|
1421
|
+
/** A second `-f`, so a nested repository (a populated submodule) is deleted too. */
|
|
1422
|
+
nested?: boolean | undefined;
|
|
1370
1423
|
}
|
|
1371
1424
|
/**
|
|
1372
1425
|
* `git clean -f`: delete untracked files, and untracked directories with
|
|
1373
|
-
* `{directories: true}
|
|
1426
|
+
* `{directories: true}`; `{nested: true}` also deletes untracked nested repositories.
|
|
1427
|
+
* Ignored files are kept.
|
|
1374
1428
|
*/
|
|
1375
1429
|
export declare function clean(opts?: CleanOptions): GitVerb<void>;
|
|
1376
1430
|
/** Delete a local branch (`-d`, or `-D` with `{force: true}`). */
|
|
@@ -1450,6 +1504,17 @@ export declare function worktreeMove(from: string, to: string, opts?: WorktreeMo
|
|
|
1450
1504
|
export declare function worktreeUnlock(path: string): GitVerb<void>;
|
|
1451
1505
|
/** `git worktree prune`. */
|
|
1452
1506
|
export declare function worktreePrune(): GitVerb<void>;
|
|
1507
|
+
/**
|
|
1508
|
+
* `git submodule update --init --recursive --checkout`, with the `file` and `ext` transports
|
|
1509
|
+
* refused: check out every submodule, nested ones included, at the commit the checked-out tree pins, cloning those not yet initialised. A repository
|
|
1510
|
+
* with no submodules is exit 0 and no work.
|
|
1511
|
+
*
|
|
1512
|
+
* The URLs come from the tree's own `.gitmodules`, which a pull request's author controls, so
|
|
1513
|
+
* the `file` and `ext` transports are refused (a local path or a command as a "URL"). A
|
|
1514
|
+
* `GIT_ALLOW_PROTOCOL` in the environment still takes precedence over these. `--checkout` ignores a
|
|
1515
|
+
* `submodule.<name>.update` the tree's `.gitmodules` sets (`none`, `rebase`, `merge`, `!command`).
|
|
1516
|
+
*/
|
|
1517
|
+
export declare function submoduleUpdate(): GitVerb<void>;
|
|
1453
1518
|
/** `git remote add <name> <url>`. */
|
|
1454
1519
|
export declare function remoteAdd(name: string, url: string): GitVerb<void>;
|
|
1455
1520
|
/**
|
|
@@ -1580,6 +1645,13 @@ export interface RebaseOptions {
|
|
|
1580
1645
|
* base commits are left behind instead of replayed onto the new ones.
|
|
1581
1646
|
*/
|
|
1582
1647
|
upstream?: string | undefined;
|
|
1648
|
+
/**
|
|
1649
|
+
* `--fork-point`: take the branch's old base from the reflog of `onto`, so
|
|
1650
|
+
* commits the base held before it was rewritten are left behind. Where the
|
|
1651
|
+
* reflog lacks the old base (a fresh clone), git falls back to the merge
|
|
1652
|
+
* base, which is a plain `rebase`. `upstream` wins when both are set.
|
|
1653
|
+
*/
|
|
1654
|
+
forkPoint?: boolean | undefined;
|
|
1583
1655
|
}
|
|
1584
1656
|
/**
|
|
1585
1657
|
* Replay the current branch onto `onto` (`git rebase`, or
|