@statewalker/vcs-commands 0.10.0 → 0.11.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/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/index.d.ts +1 -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-tree-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/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 +15 -1
- 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-bQQ9OmCh.js} +354 -77
- package/dist/{fsck-CrhVMNIH.js → fsck-BHT9bUS-.js} +1 -1
- package/dist/git-command.d.ts +8 -2
- 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-Cx2PlGV9.js} +9 -4
- package/dist/{remote-transport-Bu4PGSMD.js → remote-transport-BrQZfyHu.js} +3 -3
- package/dist/results/index.js +1 -1
- package/dist/{results-ERo9vELd.js → results-CNHQnU5Y.js} +327 -54
- package/package.json +12 -12
- package/src/commands/am/am-command.ts +30 -14
- package/src/commands/cat-file/cat-file-command.ts +46 -8
- 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/index.ts +1 -0
- package/src/commands/log-output.ts +11 -0
- package/src/commands/ls-tree-command.ts +25 -1
- package/src/commands/repo-command.ts +124 -25
- package/src/commands/reset-command.ts +75 -3
- package/src/commands/rev-parse-command.ts +14 -28
- package/src/commands/revision-resolver.ts +53 -11
- 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 +48 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statewalker/vcs-commands",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Git-like VCS commands (commit, checkout, merge, diff, log)",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/statewalker/webrun-vcs/issues"
|
|
@@ -46,26 +46,26 @@
|
|
|
46
46
|
"src"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@statewalker/
|
|
50
|
-
"@statewalker/vcs-store-mem": "^0.
|
|
51
|
-
"@statewalker/vcs-
|
|
49
|
+
"@statewalker/webrun-rpc": "^0.15.0",
|
|
50
|
+
"@statewalker/vcs-store-mem": "^0.11.0",
|
|
51
|
+
"@statewalker/vcs-core": "^0.11.0",
|
|
52
|
+
"@statewalker/vcs-store-files": "^0.11.0",
|
|
53
|
+
"@statewalker/vcs-transport": "^0.11.0",
|
|
52
54
|
"@statewalker/vcs-utils": "^0.10.0",
|
|
53
|
-
"@statewalker/vcs-
|
|
54
|
-
"@statewalker/vcs-working-tree": "^0.10.0"
|
|
55
|
+
"@statewalker/vcs-working-tree": "^0.11.0"
|
|
55
56
|
},
|
|
56
57
|
"devDependencies": {
|
|
57
|
-
"@statewalker/webrun-rpc": "^0.15.0",
|
|
58
58
|
"@types/node": "^26.6.4",
|
|
59
59
|
"@types/ws": "^8.18.1",
|
|
60
60
|
"rolldown": "^1.2.12",
|
|
61
61
|
"typescript": "^7.0.2",
|
|
62
62
|
"vitest": "^5.1.0",
|
|
63
63
|
"ws": "^8.22.0",
|
|
64
|
-
"@statewalker/vcs-
|
|
65
|
-
"@statewalker/vcs-
|
|
66
|
-
"@statewalker/vcs-
|
|
67
|
-
"@statewalker/vcs-
|
|
68
|
-
"@statewalker/vcs-
|
|
64
|
+
"@statewalker/vcs-store-sql": "^0.11.0",
|
|
65
|
+
"@statewalker/vcs-transport-adapters": "^0.11.0",
|
|
66
|
+
"@statewalker/vcs-transport-lfs": "^0.9.0",
|
|
67
|
+
"@statewalker/vcs-store-kv": "^0.11.0",
|
|
68
|
+
"@statewalker/vcs-utils-node": "^0.11.0"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "rm -rf dist && rolldown -c && tsc --emitDeclarationOnly --declaration",
|
|
@@ -1348,21 +1348,37 @@ export class AmCommand extends GitCommand<AmResult> {
|
|
|
1348
1348
|
let header = "";
|
|
1349
1349
|
if (sign !== undefined) {
|
|
1350
1350
|
const payload = encodeGitPath(head + body);
|
|
1351
|
-
const
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1351
|
+
const signBytes = async (bytes: Uint8Array) =>
|
|
1352
|
+
latin1ToPath(
|
|
1353
|
+
bytesToLatin1(
|
|
1354
|
+
await this.signOrDie((cwd) =>
|
|
1355
|
+
signPayload(this.workingCopy, sign, bytes, {
|
|
1356
|
+
committer,
|
|
1357
|
+
tail: [],
|
|
1358
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
1359
|
+
}),
|
|
1360
|
+
),
|
|
1359
1361
|
),
|
|
1360
|
-
)
|
|
1361
|
-
|
|
1362
|
-
//
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1362
|
+
);
|
|
1363
|
+
// add_header_signature: the header (`gpgsig`, `gpgsig-sha256` in a SHA-256
|
|
1364
|
+
// repository) after the other headers, continuation lines indented
|
|
1365
|
+
const headerOf = (name: string, signature: string) =>
|
|
1366
|
+
`${name} ${(signature.endsWith("\n") ? signature.slice(0, -1) : signature).split("\n").join("\n ")}\n`;
|
|
1367
|
+
const signatures = [
|
|
1368
|
+
{ name: this.objectFormat.signatureHeader, value: await signBytes(payload) },
|
|
1369
|
+
];
|
|
1370
|
+
// commit_tree_extended with a compatibility object format: the converted commit
|
|
1371
|
+
// signed too, both signatures in both objects, `gpgsig` (SHA-1) first
|
|
1372
|
+
const compat = objects.compat;
|
|
1373
|
+
if (compat) {
|
|
1374
|
+
const compatPayload = await compat.convertToCompat("commit", payload);
|
|
1375
|
+
signatures.push({
|
|
1376
|
+
name: compat.compat.signatureHeader,
|
|
1377
|
+
value: await signBytes(compatPayload),
|
|
1378
|
+
});
|
|
1379
|
+
signatures.sort((a, b) => (a.name === "gpgsig" ? -1 : b.name === "gpgsig" ? 1 : 0));
|
|
1380
|
+
}
|
|
1381
|
+
header = signatures.map((s) => headerOf(s.name, s.value)).join("");
|
|
1366
1382
|
}
|
|
1367
1383
|
id = await objects.putUnsized("commit", [encodeGitPath(head + header + body)]);
|
|
1368
1384
|
} else {
|
|
@@ -301,21 +301,19 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
301
301
|
|
|
302
302
|
/** cat_one_file */
|
|
303
303
|
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
304
|
const resolver = this.revisionResolver();
|
|
311
305
|
let id: ObjectId | undefined;
|
|
312
306
|
try {
|
|
313
|
-
id
|
|
307
|
+
// GET_OID_HASH_ANY: an id of the compatibility format (full or abbreviated) names the
|
|
308
|
+
// object as that format sees it (its storage object converted)
|
|
309
|
+
id = await resolver.resolve(name, { onlyToDie: true, hashAny: true });
|
|
314
310
|
} finally {
|
|
315
311
|
for (const line of resolver.warnings) this.warn(line);
|
|
316
312
|
resolver.warnings.length = 0;
|
|
317
313
|
}
|
|
318
314
|
if (id === undefined) throw new PlumbingError(`fatal: Not a valid object name ${name}`);
|
|
315
|
+
const compat = this.compatIdOf(id);
|
|
316
|
+
if (compat) return this.catOneCompat(id, compat);
|
|
319
317
|
const couldNotGetInfo = () =>
|
|
320
318
|
new PlumbingError("fatal: git cat-file: could not get object info");
|
|
321
319
|
switch (this.mode) {
|
|
@@ -346,6 +344,12 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
346
344
|
}
|
|
347
345
|
}
|
|
348
346
|
|
|
347
|
+
/** The compatibility objects when `id` is an id of the compatibility format (not storage's) */
|
|
348
|
+
private compatIdOf(id: ObjectId): CompatObjects | undefined {
|
|
349
|
+
const compat = this.compatObjects;
|
|
350
|
+
return compat && id.length !== this.objectFormat.hexLength ? compat : undefined;
|
|
351
|
+
}
|
|
352
|
+
|
|
349
353
|
/**
|
|
350
354
|
* cat_one_file for an id of the compatibility format: the object read through the map and
|
|
351
355
|
* converted (`odb_read_object_info_extended` with an id of the other format).
|
|
@@ -690,7 +694,7 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
690
694
|
): Promise<void> {
|
|
691
695
|
let id: ObjectId | undefined;
|
|
692
696
|
try {
|
|
693
|
-
id = await resolver.resolve(name);
|
|
697
|
+
id = await resolver.resolve(name, { hashAny: true });
|
|
694
698
|
} finally {
|
|
695
699
|
for (const line of resolver.warnings) this.warn(line);
|
|
696
700
|
}
|
|
@@ -707,12 +711,46 @@ export class CatFileCommand extends PlumbingCommand {
|
|
|
707
711
|
});
|
|
708
712
|
}
|
|
709
713
|
|
|
714
|
+
/**
|
|
715
|
+
* batch_object_write for an id of the compatibility format (`GET_OID_HASH_ANY` in
|
|
716
|
+
* batch_one_object): the object read through the map and converted, so its id, type, size
|
|
717
|
+
* and content are the compatibility format's. Replace refs are storage ids: they do not
|
|
718
|
+
* apply to it.
|
|
719
|
+
*/
|
|
720
|
+
private async batchCompatWrite(
|
|
721
|
+
state: BatchState,
|
|
722
|
+
name: string | undefined,
|
|
723
|
+
data: BatchObjectData,
|
|
724
|
+
compat: CompatObjects,
|
|
725
|
+
): Promise<void> {
|
|
726
|
+
const object = await compat.readAsCompat(data.id);
|
|
727
|
+
if (!object) {
|
|
728
|
+
await this.write(`${name ?? data.id} missing${state.delim}`);
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
let content = object.content;
|
|
732
|
+
if (this.useMailmap && (object.type === "commit" || object.type === "tag")) {
|
|
733
|
+
content = await this.mapIdents(content);
|
|
734
|
+
}
|
|
735
|
+
data.type = object.type;
|
|
736
|
+
data.size = content.length;
|
|
737
|
+
const header = state.plain
|
|
738
|
+
? `${data.id} ${data.type} ${data.size}${state.delim}`
|
|
739
|
+
: `${expandBatchFormat(state.format, data)}${state.delim}`;
|
|
740
|
+
await this.write(header);
|
|
741
|
+
if (!state.contents) return;
|
|
742
|
+
await this.write(content);
|
|
743
|
+
await this.write(state.delim);
|
|
744
|
+
}
|
|
745
|
+
|
|
710
746
|
/** batch_object_write */
|
|
711
747
|
private async batchObjectWrite(
|
|
712
748
|
state: BatchState,
|
|
713
749
|
name: string | undefined,
|
|
714
750
|
data: BatchObjectData,
|
|
715
751
|
): Promise<void> {
|
|
752
|
+
const compat = this.compatIdOf(data.id);
|
|
753
|
+
if (compat) return this.batchCompatWrite(state, name, data, compat);
|
|
716
754
|
const target = state.replace ? await this.replaced(data.id) : data.id;
|
|
717
755
|
const info = await this.info(target);
|
|
718
756
|
if (!info) {
|
|
@@ -90,7 +90,13 @@ import { globalPathspecMagic } from "./pathspec.js";
|
|
|
90
90
|
import { PathspecFile } from "./pathspec-file.js";
|
|
91
91
|
import { markIndexUpdate } from "./post-index-change.js";
|
|
92
92
|
import { reflogMessages } from "./reflog-messages.js";
|
|
93
|
-
import {
|
|
93
|
+
import {
|
|
94
|
+
checkFlaggedEntries,
|
|
95
|
+
fsmonitorKeptEntries,
|
|
96
|
+
recordWrittenStat,
|
|
97
|
+
restoreKeptEntries,
|
|
98
|
+
restoreWorktreeHard,
|
|
99
|
+
} from "./reset-command.js";
|
|
94
100
|
import { removeBranchState } from "./sequencer-support.js";
|
|
95
101
|
import { pushSparseWarnings, SparseUnpack } from "./sparse-checkout-support.js";
|
|
96
102
|
import { StashApplyCommand } from "./stash-apply-command.js";
|
|
@@ -974,7 +980,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
974
980
|
treeId,
|
|
975
981
|
sparse,
|
|
976
982
|
);
|
|
983
|
+
// oneway_merge: what the file system monitor holds unchanged is neither stat'ed nor written
|
|
984
|
+
const fsmKept = worktree
|
|
985
|
+
? await fsmonitorKeptEntries(this.trees, this.staging, treeId)
|
|
986
|
+
: new Map<string, StagingEntry>();
|
|
977
987
|
await this.staging.readTree(this.trees, treeId, { keepMatching: "flags" });
|
|
988
|
+
await restoreKeptEntries(this.staging, fsmKept);
|
|
978
989
|
// reset_head's prime_cache_tree: the index is HEAD's tree
|
|
979
990
|
this.staging.setCacheTree?.(await cacheTreeOfTree(this.trees, treeId));
|
|
980
991
|
markIndexUpdate(this.staging, { workdir: true });
|
|
@@ -986,6 +997,8 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
986
997
|
trackedBefore,
|
|
987
998
|
keptOut,
|
|
988
999
|
sparse,
|
|
1000
|
+
undefined,
|
|
1001
|
+
new Set(fsmKept.keys()),
|
|
989
1002
|
);
|
|
990
1003
|
// check_updates: the entries written carry the stat of their new files
|
|
991
1004
|
await recordWrittenStat(this.staging, worktree, written);
|
|
@@ -1188,6 +1201,12 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1188
1201
|
});
|
|
1189
1202
|
const quiet = (path: string) => sparse?.leavesAlone(path) === true;
|
|
1190
1203
|
const writes = (path: string) => !sparse || sparse.writes(path);
|
|
1204
|
+
// checkout -f's oneway_merge: an entry the file system monitor holds unchanged and the
|
|
1205
|
+
// target keeps is neither stat'ed nor written, and stays in the index as it is
|
|
1206
|
+
const fsmKept =
|
|
1207
|
+
this.force && targetTreeId && this.worktreeAccess
|
|
1208
|
+
? await fsmonitorKeptEntries(this.trees, this.staging, targetTreeId)
|
|
1209
|
+
: new Map<string, StagingEntry>();
|
|
1191
1210
|
// --recurse-submodules: unpack-trees' submodule checks and moves (forced: o->reset)
|
|
1192
1211
|
const subs = this.worktreeAccess
|
|
1193
1212
|
? await SubmoduleUnpack.start(this.workingCopy, {
|
|
@@ -1272,6 +1291,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1272
1291
|
if ((i as { skipWorktree?: boolean } | undefined)?.skipWorktree && sameSide(i, t)) {
|
|
1273
1292
|
continue;
|
|
1274
1293
|
}
|
|
1294
|
+
if (fsmKept.has(path) && sameSide(i, t)) continue;
|
|
1275
1295
|
if (quiet(path)) continue;
|
|
1276
1296
|
// merged_entry's submodule check (FORCE): the submodule must be able to move
|
|
1277
1297
|
if (subs && t && !sameSide(i, t)) await subs.mergedRefuses(path, i, t);
|
|
@@ -1573,6 +1593,7 @@ export class CheckoutCommand extends GitCommand<CheckoutResult> {
|
|
|
1573
1593
|
// oneway_merge: an unchanged entry keeps its flags and stat, a changed one its
|
|
1574
1594
|
// skip-worktree bit
|
|
1575
1595
|
await this.staging.readTree(this.trees as any, targetTreeId, { keepMatching: "flags" });
|
|
1596
|
+
await restoreKeptEntries(this.staging, fsmKept);
|
|
1576
1597
|
// check_updates: the entries written carry the stat of their new files
|
|
1577
1598
|
if (worktree) await recordWrittenStat(this.staging, worktree, written);
|
|
1578
1599
|
await this.writeSwitchedIndex();
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
GitWorkingCopyConfig,
|
|
14
14
|
HostPaths,
|
|
15
15
|
hostRootOf,
|
|
16
|
+
objectStorageFormatByUri,
|
|
16
17
|
parseConfigKey,
|
|
17
18
|
setConfigMultivarText,
|
|
18
19
|
} from "@statewalker/vcs-store-files";
|
|
@@ -56,7 +57,11 @@ import {
|
|
|
56
57
|
parseBundleListLine,
|
|
57
58
|
} from "./bundle/index.js";
|
|
58
59
|
import { coreBool, worktreeModeTrust } from "./core-config.js";
|
|
59
|
-
import {
|
|
60
|
+
import {
|
|
61
|
+
defaultInitialBranch,
|
|
62
|
+
UnsupportedObjectStorageError,
|
|
63
|
+
unknownObjectStorageFormat,
|
|
64
|
+
} from "./default-branch.js";
|
|
60
65
|
import { TagOption, toTagMode, toTrackingRefUpdate } from "./fetch-command.js";
|
|
61
66
|
import { fetchFsckOf } from "./fsck/index.js";
|
|
62
67
|
import { runPostCheckoutHook } from "./git-hooks.js";
|
|
@@ -106,6 +111,7 @@ const CLONE_SETTINGS = [
|
|
|
106
111
|
"dissociate",
|
|
107
112
|
"references",
|
|
108
113
|
"recurseSubmodules",
|
|
114
|
+
"objectStorageFormat",
|
|
109
115
|
"shallowSubmodules",
|
|
110
116
|
"alsoFilterSubmodules",
|
|
111
117
|
"remoteSubmodules",
|
|
@@ -232,6 +238,7 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
232
238
|
private references: { path: string; required: boolean }[] = [];
|
|
233
239
|
/** `--recurse-submodules[=<pathspec>]` values, in the order given */
|
|
234
240
|
private recurseSubmodules: string[] = [];
|
|
241
|
+
private objectStorageFormat?: string;
|
|
235
242
|
private shallowSubmodules = false;
|
|
236
243
|
/** `--[no-]also-filter-submodules`; unset: `clone.filterSubmodules` */
|
|
237
244
|
private alsoFilterSubmodules?: boolean;
|
|
@@ -743,6 +750,19 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
743
750
|
* `protocol.file.allow=always`. Credentials and headers reach a submodule's URL only as
|
|
744
751
|
* `SubmoduleUpdateCommand.setCredentials` allows (the clone's own origin).
|
|
745
752
|
*/
|
|
753
|
+
/**
|
|
754
|
+
* `--object-storage-format=<format>`: the clone's object storage (git master). `files` is
|
|
755
|
+
* the repository as always and is passed on to the submodules a recursive clone makes; a
|
|
756
|
+
* name git does not know dies as git (`unknown object storage format '<v>'`), and
|
|
757
|
+
* `files://<directory>`, objects outside `objects/`, which we do not read, is refused
|
|
758
|
+
* before anything is fetched (`UnsupportedObjectStorageError`).
|
|
759
|
+
*/
|
|
760
|
+
setObjectStorageFormat(format: string): this {
|
|
761
|
+
this.checkCallable();
|
|
762
|
+
this.objectStorageFormat = format;
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
|
|
746
766
|
setRecurseSubmodules(recurse: boolean | string[]): this {
|
|
747
767
|
this.checkCallable();
|
|
748
768
|
this.recurseSubmodules = recurse === true ? ["."] : recurse === false ? [] : [...recurse];
|
|
@@ -842,6 +862,14 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
842
862
|
if (!this.uri) {
|
|
843
863
|
throw new InvalidRemoteError("", "URI must be specified for clone");
|
|
844
864
|
}
|
|
865
|
+
// cmd_clone: the object storage format is checked with the options, before anything
|
|
866
|
+
if (this.objectStorageFormat !== undefined) {
|
|
867
|
+
const unknown = unknownObjectStorageFormat(this.objectStorageFormat, "uri");
|
|
868
|
+
if (unknown) throw new GitApiError(unknown);
|
|
869
|
+
if (objectStorageFormatByUri(this.objectStorageFormat)?.payload !== undefined) {
|
|
870
|
+
throw new UnsupportedObjectStorageError(this.objectStorageFormat);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
845
873
|
// cmd_clone: what --recurse-submodules adds to the -c values (option_config)
|
|
846
874
|
const submoduleConfig: string[] = [];
|
|
847
875
|
if (this.recurseSubmodules.length > 0) {
|
|
@@ -908,10 +936,19 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
908
936
|
const uri = this.uri;
|
|
909
937
|
// a bare repository's working copy opens it from its git directory
|
|
910
938
|
const worktree = repositoryPlaceOf(this.workingCopy);
|
|
939
|
+
// a repository whose format we cannot open (an `extensions.objectStorage` payload, which
|
|
940
|
+
// git master clones non-locally) is refused with that format, never "does not exist"
|
|
941
|
+
let formatRefusal: Error | undefined;
|
|
911
942
|
const isRepositoryPath = await worktree
|
|
912
943
|
?.openRepository?.(uri, { checkOwnership: false, commandLineConfig: false })
|
|
913
944
|
.then((opened) => opened !== undefined)
|
|
914
|
-
.catch(() =>
|
|
945
|
+
.catch((error: unknown) => {
|
|
946
|
+
if (error instanceof Error && error.name === "UnsupportedRepositoryFormatError") {
|
|
947
|
+
formatRefusal = error;
|
|
948
|
+
}
|
|
949
|
+
return false;
|
|
950
|
+
});
|
|
951
|
+
if (formatRefusal) throw new TransportError(`fatal: ${formatRefusal.message}`);
|
|
915
952
|
// get_repo_path: then a regular file, `<path>.bundle` first (a bundle: the transport reads
|
|
916
953
|
// it there, remote.<name>.url keeps the path as given)
|
|
917
954
|
let bundleFile: string | undefined;
|
|
@@ -1568,6 +1605,8 @@ export class CloneCommand extends TransportCommand<CloneResult> {
|
|
|
1568
1605
|
if (this.shallowSubmodules) update.setDepth(1);
|
|
1569
1606
|
if (this.remoteSubmodules) update.setRemote(true).setNoFetch(true);
|
|
1570
1607
|
if (filterSubmodules && this.filterSpec !== undefined) update.setFilter(this.filterSpec);
|
|
1608
|
+
// object_storage_format_to_name: the name alone (`files`), never a payload
|
|
1609
|
+
if (this.objectStorageFormat !== undefined) update.setObjectStorageFormat("files");
|
|
1571
1610
|
// option_single_branch, settled before (a deepening clone is a single-branch one, a
|
|
1572
1611
|
// --revision clone none): always passed on, as --single-branch or --no-single-branch
|
|
1573
1612
|
update.setSingleBranch(
|
|
@@ -226,6 +226,25 @@ export class UnsupportedObjectStorageError extends Error {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
/**
|
|
230
|
+
* The death of an `--object-storage-format` option git master does not know: clone takes a
|
|
231
|
+
* URI (`files`, `files://<dir>`: `object_storage_format_by_uri`), `submodule add`/`update` a
|
|
232
|
+
* name (`files` alone: `object_storage_format_by_name`, so `files://objs` is unknown there).
|
|
233
|
+
* Undefined when git takes the value.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* unknownObjectStorageFormat("files://objs", "name"); // "fatal: unknown object storage format 'files://objs'"
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export function unknownObjectStorageFormat(
|
|
241
|
+
value: string,
|
|
242
|
+
kind: "uri" | "name",
|
|
243
|
+
): string | undefined {
|
|
244
|
+
const known = kind === "name" ? value === "files" : objectStorageFormatByUri(value) !== undefined;
|
|
245
|
+
return known ? undefined : `fatal: unknown object storage format '${value}'`;
|
|
246
|
+
}
|
|
247
|
+
|
|
229
248
|
/** A reinitialization naming another object storage payload: git dies (exit 128). */
|
|
230
249
|
export class ReinitializeObjectStorageError extends Error {
|
|
231
250
|
override name = "ReinitializeObjectStorageError";
|
|
@@ -3874,12 +3874,26 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
|
|
|
3874
3874
|
const trust = worktreeModeTrust(this.workingCopy, worktree);
|
|
3875
3875
|
const indexTime = this.staging.getUpdateTime();
|
|
3876
3876
|
const ignoreOf = await this.submoduleIgnoreOf();
|
|
3877
|
+
// the file system monitor, asked as git asks it on reading the index (tweak_fsmonitor,
|
|
3878
|
+
// refresh_fsmonitor): an entry it reported nothing for since its token is unchanged.
|
|
3879
|
+
// diff-files never stats it (run_diff_files, as CE_VALID); diff-index of git 2.5x neither
|
|
3880
|
+
// (check_removed's fake_lstat), while 2.43's check_removed still lstats it (a deleted file
|
|
3881
|
+
// is a deletion there), only ie_match_stat's comparison skipped
|
|
3882
|
+
const fsm = await this.fsmonitorRefresh(this.staging);
|
|
3883
|
+
const fsmValid = (entry: StageEntry) => !!fsm && entry.stage === 0 && fsm.state.isValid(entry);
|
|
3884
|
+
const statsValid = unmergedAsFiles && this.hooks.compatibility === "2.43";
|
|
3885
|
+
const fsmUnstated = (entry: StageEntry) => !statsValid && fsmValid(entry);
|
|
3877
3886
|
const compareWith = async (
|
|
3878
3887
|
entry: StageEntry,
|
|
3879
3888
|
current?: WorktreeEntry | null,
|
|
3880
3889
|
): Promise<Side | undefined> => {
|
|
3881
3890
|
const indexSide: Side = { mode: entry.mode, id: entry.objectId };
|
|
3882
|
-
if (entry.skipWorktree || entry.assumeValid) return indexSide;
|
|
3891
|
+
if (entry.skipWorktree || entry.assumeValid || fsmUnstated(entry)) return indexSide;
|
|
3892
|
+
if (fsmValid(entry)) {
|
|
3893
|
+
const file =
|
|
3894
|
+
current !== undefined ? current : await worktree.getEntry(entry.path).catch(() => null);
|
|
3895
|
+
return file ? indexSide : undefined;
|
|
3896
|
+
}
|
|
3883
3897
|
const ignore = entry.mode === GITLINK ? ignoreOf(entry.path) : undefined;
|
|
3884
3898
|
if (entry.mode === GITLINK && ignore === "all") return indexSide;
|
|
3885
3899
|
const result = await compareWithWorktree(worktree, entry, { trust, indexTime }, current);
|
|
@@ -3899,6 +3913,9 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
|
|
|
3899
3913
|
result.worktreeEntry?.isDirectory
|
|
3900
3914
|
) {
|
|
3901
3915
|
const found = await readSubmoduleDirt(worktree, entry.path, ignore !== "none");
|
|
3916
|
+
for (const line of found.unreadable ?? []) {
|
|
3917
|
+
if (!this.configWarnings.includes(line)) this.configWarnings.push(line);
|
|
3918
|
+
}
|
|
3902
3919
|
if (found.modified) dirt.modified = true;
|
|
3903
3920
|
if (ignore === "none" && found.untracked) dirt.untracked = true;
|
|
3904
3921
|
dirty = !!dirt.modified || !!dirt.untracked;
|
|
@@ -3950,6 +3967,7 @@ export class DiffCommand extends GitCommand<DiffEntry[]> {
|
|
|
3950
3967
|
!entry.skipWorktree &&
|
|
3951
3968
|
!entry.assumeValid &&
|
|
3952
3969
|
entry.mode !== GITLINK &&
|
|
3970
|
+
!fsmUnstated(entry) &&
|
|
3953
3971
|
this.matches(entry.path);
|
|
3954
3972
|
for await (const { item: entry, current } of withWorktreeEntries(
|
|
3955
3973
|
worktree,
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
* .callOutput();
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
15
|
-
* The formats are git's user formats (`format:`, `tformat:`, a text with `%`, a `pretty.<name>`
|
|
16
|
-
* alias) and the builtin `reference
|
|
17
|
-
*
|
|
18
|
-
*
|
|
15
|
+
* The formats are git's: user formats (`format:`, `tformat:`, a text with `%`, a `pretty.<name>`
|
|
16
|
+
* alias) and the builtin ones (`reference`, `oneline`, `medium`, `short`, `full`, `fuller`,
|
|
17
|
+
* `raw`, `email`, `mboxrd`), the latter as pretty.c's `pretty_print_commit` prints them: no
|
|
18
|
+
* `commit <id>` line (log-tree's), no notes, tabs kept, a mail's subject without `[PATCH]`.
|
|
19
|
+
* Each commit is formatted by `git log`'s pretty engine with no configuration of its own:
|
|
20
|
+
* `log.*` settings do not apply, as format-rev starts from a fresh `rev_info`.
|
|
19
21
|
*/
|
|
20
22
|
|
|
21
23
|
import type { ObjectId } from "@statewalker/vcs-core";
|
|
@@ -27,6 +29,9 @@ import { PlumbingCommand, PlumbingError } from "./plumbing-command.js";
|
|
|
27
29
|
/** `--stdin-mode`: lines of revisions, or running text holding object ids. */
|
|
28
30
|
export type FormatRevStdinMode = "text" | "revs";
|
|
29
31
|
|
|
32
|
+
/** A format as get_commit_format reads it: a user format, or a builtin `CMIT_FMT_*` one. */
|
|
33
|
+
type Pretty = { format: string; date?: string; builtin?: never } | { builtin: string };
|
|
34
|
+
|
|
30
35
|
/** A builtin format git's get_commit_format knows, with its default date mode. */
|
|
31
36
|
const BUILTIN_USER_FORMATS: Record<string, { format: string; date?: string }> = {
|
|
32
37
|
reference: { format: "%C(auto)%h (%s, %ad)", date: "short" },
|
|
@@ -192,7 +197,7 @@ export class FormatRevCommand extends PlumbingCommand {
|
|
|
192
197
|
}
|
|
193
198
|
|
|
194
199
|
/** get_commit_format: the user format and its date mode. */
|
|
195
|
-
private prettyOf(format: string, depth = 0):
|
|
200
|
+
private prettyOf(format: string, depth = 0): Pretty {
|
|
196
201
|
if (format.startsWith("format:")) return { format: format.slice(7) };
|
|
197
202
|
if (format.startsWith("tformat:")) return { format: format.slice(8) };
|
|
198
203
|
if (format.includes("%")) return { format };
|
|
@@ -202,19 +207,30 @@ export class FormatRevCommand extends PlumbingCommand {
|
|
|
202
207
|
const alias = RemoteConfigStore.from(this.workingCopy).value(`pretty.${format}`);
|
|
203
208
|
if (alias !== undefined) return this.prettyOf(alias, depth + 1);
|
|
204
209
|
}
|
|
205
|
-
if (BUILTIN_OTHER.has(format))
|
|
206
|
-
throw new PlumbingError(`fatal: format-rev: the '${format}' format is not supported`);
|
|
210
|
+
if (BUILTIN_OTHER.has(format)) return { builtin: format };
|
|
207
211
|
throw new PlumbingError(`fatal: invalid --pretty format: ${format}`);
|
|
208
212
|
}
|
|
209
213
|
|
|
210
214
|
/** pretty_print_commit of one commit (with its notes when the format shows `%N`). */
|
|
211
|
-
private async formatOne(
|
|
212
|
-
id: ObjectId,
|
|
213
|
-
pretty: { format: string; date?: string },
|
|
214
|
-
): Promise<string | undefined> {
|
|
215
|
+
private async formatOne(id: ObjectId, pretty: Pretty): Promise<string | undefined> {
|
|
215
216
|
const log = new LogCommand(this.workingCopy).setNoWalk([{ id }]).setLogConfig(false);
|
|
216
|
-
const wantsNotes = /%N/.test(pretty.format);
|
|
217
217
|
try {
|
|
218
|
+
if (pretty.builtin !== undefined) {
|
|
219
|
+
// pretty_print_commit with format-rev's context: fmt_output_email_subject of a
|
|
220
|
+
// rev_info without a subject prefix, encode_email_headers off, no mailmap, and the
|
|
221
|
+
// default date mode of a fresh rev_info (`log.date` is never read)
|
|
222
|
+
return decodeGitPath(
|
|
223
|
+
await log.callBytes({
|
|
224
|
+
pretty: pretty.builtin,
|
|
225
|
+
prettyOnly: true,
|
|
226
|
+
notes: false,
|
|
227
|
+
mailmap: false,
|
|
228
|
+
date: "default",
|
|
229
|
+
mail: { subject: () => "Subject: ", encodeHeaders: false },
|
|
230
|
+
}),
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
const wantsNotes = /%N/.test(pretty.format);
|
|
218
234
|
return decodeGitPath(
|
|
219
235
|
await log.callBytes({
|
|
220
236
|
pretty: `format:${pretty.format}`,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* git's builtin file system monitor daemon asked over a `MessagePort` (fsmonitor-ipc.c's
|
|
3
|
+
* `fsmonitor_ipc__send_query` over simple-ipc): the request is the token, the answer the new
|
|
4
|
+
* token and the changed paths, both sent as pkt-lines ended by a flush packet.
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const port = await environment.openIpcPort({ service: "fsmonitor--daemon", path });
|
|
8
|
+
* const answer = await queryFsmonitorDaemon(port, "builtin:fake");
|
|
9
|
+
* // answer: "<token>\0<path>\0<path>\0..." as the daemon wrote it, or undefined on failure
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* The protocol code never sees a socket: the port speaks webrun-rpc's stream tier (one
|
|
13
|
+
* stream per port, bounded both ways), whatever carries it (a Unix socket through
|
|
14
|
+
* `connectSocketPort` of `@statewalker/vcs-utils-node`, a `MessageChannel`, a worker).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { duplexOverPort } from "@statewalker/webrun-rpc";
|
|
18
|
+
|
|
19
|
+
/** git's `LARGE_PACKET_DATA_MAX`: the largest payload of one pkt-line. */
|
|
20
|
+
const LARGE_PACKET_DATA_MAX = 65520 - 4;
|
|
21
|
+
|
|
22
|
+
/** The daemon's socket in the git directory (`fsmonitor_ipc__get_default_path`). */
|
|
23
|
+
export const FSMONITOR_DAEMON_IPC_NAME = "fsmonitor--daemon.ipc";
|
|
24
|
+
|
|
25
|
+
const hex = (n: number) => n.toString(16).padStart(4, "0");
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `write_packetized_from_buf_no_flush` then `packet_flush`: `payload` as pkt-lines of at
|
|
29
|
+
* most {@link LARGE_PACKET_DATA_MAX} bytes (none for an empty payload), then `0000`.
|
|
30
|
+
*/
|
|
31
|
+
export function encodePacketized(payload: Uint8Array): Uint8Array {
|
|
32
|
+
const lines = Math.ceil(payload.byteLength / LARGE_PACKET_DATA_MAX);
|
|
33
|
+
const out = new Uint8Array(payload.byteLength + lines * 4 + 4);
|
|
34
|
+
let at = 0;
|
|
35
|
+
for (let from = 0; from < payload.byteLength; from += LARGE_PACKET_DATA_MAX) {
|
|
36
|
+
const chunk = payload.subarray(from, from + LARGE_PACKET_DATA_MAX);
|
|
37
|
+
for (const c of hex(chunk.byteLength + 4)) out[at++] = c.charCodeAt(0);
|
|
38
|
+
out.set(chunk, at);
|
|
39
|
+
at += chunk.byteLength;
|
|
40
|
+
}
|
|
41
|
+
for (let i = 0; i < 4; i++) out[at++] = 0x30;
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Reads pkt-lines from `chunks` up to the first flush packet (`read_packetized_to_strbuf`):
|
|
47
|
+
* their payloads joined, or undefined when the stream ends first or a length is malformed.
|
|
48
|
+
*/
|
|
49
|
+
async function readPacketized(chunks: AsyncIterator<Uint8Array>): Promise<Uint8Array | undefined> {
|
|
50
|
+
let buffer = new Uint8Array(0);
|
|
51
|
+
const parts: Uint8Array[] = [];
|
|
52
|
+
let size = 0;
|
|
53
|
+
const fill = async (need: number): Promise<boolean> => {
|
|
54
|
+
while (buffer.byteLength < need) {
|
|
55
|
+
const next = await chunks.next();
|
|
56
|
+
if (next.done) return false;
|
|
57
|
+
const joined = new Uint8Array(buffer.byteLength + next.value.byteLength);
|
|
58
|
+
joined.set(buffer);
|
|
59
|
+
joined.set(next.value, buffer.byteLength);
|
|
60
|
+
buffer = joined;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
};
|
|
64
|
+
for (;;) {
|
|
65
|
+
if (!(await fill(4))) return undefined;
|
|
66
|
+
let length = 0;
|
|
67
|
+
for (let i = 0; i < 4; i++) {
|
|
68
|
+
const digit = Number.parseInt(String.fromCharCode(buffer[i] as number), 16);
|
|
69
|
+
if (Number.isNaN(digit)) return undefined;
|
|
70
|
+
length = length * 16 + digit;
|
|
71
|
+
}
|
|
72
|
+
if (length === 0) break;
|
|
73
|
+
// a delimiter or response-end packet, or a length shorter than its header: protocol error
|
|
74
|
+
if (length < 4) return undefined;
|
|
75
|
+
if (!(await fill(length))) return undefined;
|
|
76
|
+
const payload = buffer.slice(4, length);
|
|
77
|
+
parts.push(payload);
|
|
78
|
+
size += payload.byteLength;
|
|
79
|
+
buffer = buffer.subarray(length);
|
|
80
|
+
}
|
|
81
|
+
const out = new Uint8Array(size);
|
|
82
|
+
let at = 0;
|
|
83
|
+
for (const part of parts) {
|
|
84
|
+
out.set(part, at);
|
|
85
|
+
at += part.byteLength;
|
|
86
|
+
}
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Sends `token` to the daemon behind `port` and returns its answer (the new token, a NUL,
|
|
92
|
+
* then the changed paths, each ended by a NUL); undefined when the exchange fails (the
|
|
93
|
+
* stream fails or ends before the answer's flush packet), as git's
|
|
94
|
+
* `ipc_client_send_command_to_connection` fails. The port is closed afterwards.
|
|
95
|
+
*/
|
|
96
|
+
export async function queryFsmonitorDaemon(
|
|
97
|
+
port: MessagePort,
|
|
98
|
+
token: string,
|
|
99
|
+
): Promise<Uint8Array | undefined> {
|
|
100
|
+
let answered: () => void = () => {};
|
|
101
|
+
const done = new Promise<void>((resolve) => {
|
|
102
|
+
answered = resolve;
|
|
103
|
+
});
|
|
104
|
+
// as git's client: the request and its flush, then the connection held open (no
|
|
105
|
+
// half-close) until the answer is read
|
|
106
|
+
async function* request() {
|
|
107
|
+
yield encodePacketized(new TextEncoder().encode(token));
|
|
108
|
+
await done;
|
|
109
|
+
}
|
|
110
|
+
const output = duplexOverPort(port)(request());
|
|
111
|
+
port.start();
|
|
112
|
+
try {
|
|
113
|
+
return await readPacketized(output);
|
|
114
|
+
} catch {
|
|
115
|
+
return undefined;
|
|
116
|
+
} finally {
|
|
117
|
+
answered();
|
|
118
|
+
await output.return(undefined).catch(() => undefined);
|
|
119
|
+
port.close();
|
|
120
|
+
}
|
|
121
|
+
}
|