@ricsam/r5d-worker 0.0.137 → 0.0.139
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/README.md +4 -94
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/main.mjs +46 -7543
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/personal/action-scheduler.mjs +31 -0
- package/dist/mjs/personal/client.mjs +215 -0
- package/dist/mjs/personal/runtime.mjs +359 -0
- package/dist/mjs/personal/tcp.mjs +217 -0
- package/dist/mjs/runtime/adapter.mjs +42 -0
- package/dist/mjs/runtime/client.mjs +95 -0
- package/dist/mjs/runtime/daemon.mjs +131 -0
- package/dist/mjs/runtime/executor.mjs +436 -0
- package/dist/mjs/runtime/index.mjs +15 -0
- package/dist/mjs/runtime/protocol.mjs +139 -0
- package/dist/mjs/runtime/pty-host.mjs +156 -0
- package/dist/mjs/runtime/pty.mjs +127 -0
- package/dist/mjs/runtime/releases/artifacts.mjs +201 -0
- package/dist/mjs/runtime/releases/grants.mjs +93 -0
- package/dist/mjs/runtime/releases/main.mjs +101 -0
- package/dist/mjs/runtime/releases/manager.mjs +541 -0
- package/dist/mjs/runtime/releases/process.mjs +88 -0
- package/dist/mjs/runtime/releases/retirement.mjs +18 -0
- package/dist/mjs/runtime/releases/rpc-client.mjs +184 -0
- package/dist/mjs/runtime/releases/rpc-main.mjs +213 -0
- package/dist/mjs/runtime/releases/rpc-protocol.mjs +103 -0
- package/dist/mjs/runtime/storage.mjs +156 -0
- package/dist/mjs/runtime/workspace/artifacts.mjs +121 -0
- package/dist/mjs/runtime/workspace/authority.mjs +1355 -0
- package/dist/mjs/runtime/workspace/contracts.mjs +60 -0
- package/dist/mjs/runtime/workspace/file-write.mjs +23 -0
- package/dist/mjs/runtime/workspace/files.mjs +308 -0
- package/dist/mjs/runtime/workspace/http-body.mjs +45 -0
- package/dist/mjs/runtime/workspace/storage-client.mjs +59 -0
- package/dist/mjs/runtime/workspace/storage-wire.mjs +53 -0
- package/dist/types/main.d.ts +0 -1167
- package/dist/types/personal/action-scheduler.d.ts +23 -0
- package/dist/types/personal/client.d.ts +14 -0
- package/dist/types/personal/runtime.d.ts +121 -0
- package/dist/types/personal/tcp.d.ts +14 -0
- package/dist/types/runtime/client.d.ts +3 -1
- package/dist/types/runtime/executor.d.ts +6 -1
- package/dist/types/runtime/protocol.d.ts +176 -4
- package/dist/types/runtime/pty.d.ts +1 -0
- package/dist/types/runtime/releases/artifacts.d.ts +51 -0
- package/dist/types/runtime/releases/grants.d.ts +16 -0
- package/dist/types/runtime/releases/manager.d.ts +145 -0
- package/dist/types/runtime/releases/process.d.ts +14 -0
- package/dist/types/runtime/releases/retirement.d.ts +15 -0
- package/dist/types/runtime/releases/rpc-client.d.ts +52 -0
- package/dist/types/runtime/releases/rpc-main.d.ts +10 -0
- package/dist/types/runtime/releases/rpc-protocol.d.ts +1139 -0
- package/dist/types/runtime/workspace/artifacts.d.ts +30 -0
- package/dist/types/runtime/workspace/authority.d.ts +338 -0
- package/dist/types/runtime/workspace/contracts.d.ts +86 -0
- package/dist/types/runtime/workspace/file-write.d.ts +14 -0
- package/dist/types/runtime/workspace/files.d.ts +21 -0
- package/dist/types/runtime/workspace/http-body.d.ts +9 -0
- package/dist/types/runtime/workspace/storage-client.d.ts +23 -0
- package/dist/types/runtime/workspace/storage-wire.d.ts +138 -0
- package/package.json +8 -6
- package/dist/cjs/atomic-rename.cjs +0 -303
- package/dist/cjs/browser-upload.cjs +0 -73
- package/dist/cjs/cli-update.cjs +0 -108
- package/dist/cjs/command-launcher.cjs +0 -423
- package/dist/cjs/control-command-policy.cjs +0 -177
- package/dist/cjs/git-blob-hash.cjs +0 -41
- package/dist/cjs/git-identity.cjs +0 -39
- package/dist/cjs/git-process-environment.cjs +0 -133
- package/dist/cjs/inline-output.cjs +0 -62
- package/dist/cjs/main.cjs +0 -7517
- package/dist/cjs/managed-paths.cjs +0 -215
- package/dist/cjs/plan-lint.cjs +0 -165
- package/dist/cjs/plan-parser.cjs +0 -127
- package/dist/cjs/plan-paths.cjs +0 -53
- package/dist/cjs/port-forward-client.cjs +0 -206
- package/dist/cjs/process-tree.cjs +0 -117
- package/dist/cjs/project-checkout-garbage.cjs +0 -219
- package/dist/cjs/project-mirror-fetch-policy.cjs +0 -82
- package/dist/cjs/project-mirror-refs-token.cjs +0 -85
- package/dist/cjs/project-workspace-state.cjs +0 -972
- package/dist/cjs/project-worktrees.cjs +0 -1713
- package/dist/cjs/pty-output-coalescer.cjs +0 -87
- package/dist/cjs/recovery-journal-protocol.cjs +0 -56
- package/dist/cjs/recovery-journal-runtime.cjs +0 -133
- package/dist/cjs/recovery-journal-thread.cjs +0 -9
- package/dist/cjs/recovery-journal.cjs +0 -742
- package/dist/cjs/recovery-output-window.cjs +0 -77
- package/dist/cjs/recovery-protocol.cjs +0 -31
- package/dist/cjs/recovery-store.cjs +0 -252
- package/dist/cjs/registry-auth.cjs +0 -310
- package/dist/cjs/repository-transition-policy.cjs +0 -49
- package/dist/cjs/runtime-version.cjs +0 -88
- package/dist/cjs/session-file-mutations.cjs +0 -61
- package/dist/cjs/supervisor.cjs +0 -147
- package/dist/cjs/three-way-merge.cjs +0 -346
- package/dist/cjs/working-tree-mirror.cjs +0 -1872
- package/dist/cjs/workspace-automatic-sync-policy.cjs +0 -79
- package/dist/cjs/workspace-branch-incarnation-policy.cjs +0 -37
- package/dist/cjs/workspace-command-sync-policy.cjs +0 -112
- package/dist/cjs/workspace-command-targets.cjs +0 -63
- package/dist/cjs/workspace-filesystem-executor-thread.cjs +0 -36
- package/dist/cjs/workspace-filesystem-executor.cjs +0 -327
- package/dist/cjs/workspace-filesystem-job-types.cjs +0 -144
- package/dist/cjs/workspace-filesystem-jobs.cjs +0 -59
- package/dist/cjs/workspace-git-sync.cjs +0 -3595
- package/dist/cjs/workspace-hydration-ledger.cjs +0 -83
- package/dist/cjs/workspace-hydration-merge.cjs +0 -448
- package/dist/cjs/workspace-hydration-recovery-state.cjs +0 -53
- package/dist/cjs/workspace-incident-state.cjs +0 -37
- package/dist/cjs/workspace-merge-projection.cjs +0 -628
- package/dist/cjs/workspace-mount-boundary.cjs +0 -71
- package/dist/cjs/workspace-mount-hold-fence.cjs +0 -120
- package/dist/cjs/workspace-mutation-gate.cjs +0 -127
- package/dist/cjs/workspace-path-move.cjs +0 -195
- package/dist/cjs/workspace-preserve-only-policy.cjs +0 -36
- package/dist/cjs/workspace-project-config-policy.cjs +0 -53
- package/dist/cjs/workspace-projection-ledger.cjs +0 -81
- package/dist/cjs/workspace-publication-evidence.cjs +0 -46
- package/dist/cjs/workspace-sync-coalescer.cjs +0 -58
- package/dist/mjs/atomic-rename.mjs +0 -261
- package/dist/mjs/browser-upload.mjs +0 -42
- package/dist/mjs/command-launcher.mjs +0 -393
- package/dist/mjs/control-command-policy.mjs +0 -146
- package/dist/mjs/git-blob-hash.mjs +0 -16
- package/dist/mjs/git-identity.mjs +0 -15
- package/dist/mjs/git-process-environment.mjs +0 -105
- package/dist/mjs/inline-output.mjs +0 -37
- package/dist/mjs/managed-paths.mjs +0 -174
- package/dist/mjs/plan-lint.mjs +0 -129
- package/dist/mjs/plan-parser.mjs +0 -94
- package/dist/mjs/plan-paths.mjs +0 -25
- package/dist/mjs/port-forward-client.mjs +0 -172
- package/dist/mjs/project-checkout-garbage.mjs +0 -178
- package/dist/mjs/project-mirror-fetch-policy.mjs +0 -56
- package/dist/mjs/project-mirror-refs-token.mjs +0 -53
- package/dist/mjs/project-workspace-state.mjs +0 -937
- package/dist/mjs/project-worktrees.mjs +0 -1657
- package/dist/mjs/pty-output-coalescer.mjs +0 -61
- package/dist/mjs/recovery-journal-protocol.mjs +0 -30
- package/dist/mjs/recovery-journal-runtime.mjs +0 -112
- package/dist/mjs/recovery-journal-thread.mjs +0 -8
- package/dist/mjs/recovery-journal.mjs +0 -694
- package/dist/mjs/recovery-output-window.mjs +0 -53
- package/dist/mjs/recovery-protocol.mjs +0 -6
- package/dist/mjs/recovery-store.mjs +0 -217
- package/dist/mjs/registry-auth.mjs +0 -269
- package/dist/mjs/repository-transition-policy.mjs +0 -22
- package/dist/mjs/runtime-version.mjs +0 -54
- package/dist/mjs/session-file-mutations.mjs +0 -37
- package/dist/mjs/supervisor.mjs +0 -114
- package/dist/mjs/three-way-merge.mjs +0 -318
- package/dist/mjs/working-tree-mirror.mjs +0 -1817
- package/dist/mjs/workspace-automatic-sync-policy.mjs +0 -48
- package/dist/mjs/workspace-branch-incarnation-policy.mjs +0 -13
- package/dist/mjs/workspace-command-sync-policy.mjs +0 -84
- package/dist/mjs/workspace-command-targets.mjs +0 -37
- package/dist/mjs/workspace-filesystem-executor-thread.mjs +0 -38
- package/dist/mjs/workspace-filesystem-executor.mjs +0 -287
- package/dist/mjs/workspace-filesystem-job-types.mjs +0 -116
- package/dist/mjs/workspace-filesystem-jobs.mjs +0 -55
- package/dist/mjs/workspace-git-sync.mjs +0 -3553
- package/dist/mjs/workspace-hydration-ledger.mjs +0 -58
- package/dist/mjs/workspace-hydration-merge.mjs +0 -414
- package/dist/mjs/workspace-hydration-recovery-state.mjs +0 -29
- package/dist/mjs/workspace-incident-state.mjs +0 -12
- package/dist/mjs/workspace-merge-projection.mjs +0 -594
- package/dist/mjs/workspace-mount-boundary.mjs +0 -37
- package/dist/mjs/workspace-mount-hold-fence.mjs +0 -95
- package/dist/mjs/workspace-mutation-gate.mjs +0 -103
- package/dist/mjs/workspace-path-move.mjs +0 -160
- package/dist/mjs/workspace-preserve-only-policy.mjs +0 -11
- package/dist/mjs/workspace-project-config-policy.mjs +0 -27
- package/dist/mjs/workspace-projection-ledger.mjs +0 -57
- package/dist/mjs/workspace-publication-evidence.mjs +0 -21
- package/dist/mjs/workspace-sync-coalescer.mjs +0 -34
- package/dist/types/atomic-rename.d.ts +0 -78
- package/dist/types/browser-upload.d.ts +0 -7
- package/dist/types/command-launcher.d.ts +0 -104
- package/dist/types/control-command-policy.d.ts +0 -53
- package/dist/types/git-blob-hash.d.ts +0 -10
- package/dist/types/git-identity.d.ts +0 -9
- package/dist/types/git-process-environment.d.ts +0 -9
- package/dist/types/inline-output.d.ts +0 -3
- package/dist/types/managed-paths.d.ts +0 -19
- package/dist/types/plan-lint.d.ts +0 -16
- package/dist/types/plan-parser.d.ts +0 -38
- package/dist/types/plan-paths.d.ts +0 -36
- package/dist/types/port-forward-client.d.ts +0 -8
- package/dist/types/project-checkout-garbage.d.ts +0 -86
- package/dist/types/project-mirror-fetch-policy.d.ts +0 -84
- package/dist/types/project-mirror-refs-token.d.ts +0 -53
- package/dist/types/project-workspace-state.d.ts +0 -188
- package/dist/types/project-worktrees.d.ts +0 -397
- package/dist/types/pty-output-coalescer.d.ts +0 -20
- package/dist/types/recovery-journal-protocol.d.ts +0 -35
- package/dist/types/recovery-journal-runtime.d.ts +0 -12
- package/dist/types/recovery-journal-stall-fixture.d.ts +0 -1
- package/dist/types/recovery-journal-thread.d.ts +0 -1
- package/dist/types/recovery-journal.d.ts +0 -248
- package/dist/types/recovery-output-window.d.ts +0 -19
- package/dist/types/recovery-protocol.d.ts +0 -59
- package/dist/types/recovery-store.d.ts +0 -52
- package/dist/types/registry-auth.d.ts +0 -47
- package/dist/types/repository-transition-policy.d.ts +0 -26
- package/dist/types/runtime-version.d.ts +0 -1
- package/dist/types/session-file-mutations.d.ts +0 -22
- package/dist/types/supervisor-daemonized-fixture.d.ts +0 -1
- package/dist/types/supervisor-launcher-cleanup-fixture.d.ts +0 -1
- package/dist/types/supervisor-signal-fixture.d.ts +0 -1
- package/dist/types/supervisor.d.ts +0 -23
- package/dist/types/three-way-merge.d.ts +0 -77
- package/dist/types/working-tree-mirror.d.ts +0 -424
- package/dist/types/workspace-automatic-sync-policy.d.ts +0 -57
- package/dist/types/workspace-branch-incarnation-policy.d.ts +0 -14
- package/dist/types/workspace-command-sync-policy.d.ts +0 -57
- package/dist/types/workspace-command-targets.d.ts +0 -37
- package/dist/types/workspace-filesystem-executor-thread.d.ts +0 -1
- package/dist/types/workspace-filesystem-executor.d.ts +0 -123
- package/dist/types/workspace-filesystem-job-types.d.ts +0 -302
- package/dist/types/workspace-filesystem-jobs.d.ts +0 -7
- package/dist/types/workspace-git-sync.d.ts +0 -514
- package/dist/types/workspace-hydration-ledger.d.ts +0 -76
- package/dist/types/workspace-hydration-merge.d.ts +0 -103
- package/dist/types/workspace-hydration-recovery-state.d.ts +0 -10
- package/dist/types/workspace-incident-state.d.ts +0 -19
- package/dist/types/workspace-merge-projection.d.ts +0 -69
- package/dist/types/workspace-mount-boundary.d.ts +0 -10
- package/dist/types/workspace-mount-hold-fence.d.ts +0 -42
- package/dist/types/workspace-mutation-gate.d.ts +0 -42
- package/dist/types/workspace-path-move.d.ts +0 -21
- package/dist/types/workspace-preserve-only-policy.d.ts +0 -15
- package/dist/types/workspace-project-config-policy.d.ts +0 -48
- package/dist/types/workspace-projection-ledger.d.ts +0 -59
- package/dist/types/workspace-publication-evidence.d.ts +0 -17
- package/dist/types/workspace-sync-coalescer.d.ts +0 -28
- /package/dist/types/{credential-authority-lock-fixture.d.ts → runtime/releases/main.d.ts} +0 -0
|
@@ -1,628 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var workspace_merge_projection_exports = {};
|
|
30
|
-
__export(workspace_merge_projection_exports, {
|
|
31
|
-
materializeWorkspaceProjectionTree: () => materializeWorkspaceProjectionTree,
|
|
32
|
-
mergeWorkspaceProjectionMount: () => mergeWorkspaceProjectionMount,
|
|
33
|
-
workspaceMergeProjectionSupport: () => workspaceMergeProjectionSupport,
|
|
34
|
-
workspaceMergeProjectionTestHarness: () => workspaceMergeProjectionTestHarness
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(workspace_merge_projection_exports);
|
|
37
|
-
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
38
|
-
var import_node_path = __toESM(require("node:path"), 1);
|
|
39
|
-
var import_git_process_environment = require("./git-process-environment.cjs");
|
|
40
|
-
var import_working_tree_mirror = require("./working-tree-mirror.cjs");
|
|
41
|
-
var import_workspace_mount_boundary = require("./workspace-mount-boundary.cjs");
|
|
42
|
-
const MINIMUM_MERGE_TREE_GIT_VERSION = { major: 2, minor: 40 };
|
|
43
|
-
const NON_RECURSIVE_GIT_CONFIG = [
|
|
44
|
-
"-c",
|
|
45
|
-
"submodule.recurse=false",
|
|
46
|
-
"-c",
|
|
47
|
-
"fetch.recurseSubmodules=false",
|
|
48
|
-
"-c",
|
|
49
|
-
"push.recurseSubmodules=false"
|
|
50
|
-
];
|
|
51
|
-
let cachedWorkspaceMergeProjectionSupport = null;
|
|
52
|
-
function gitCommandArgs(args) {
|
|
53
|
-
return ["git", ...NON_RECURSIVE_GIT_CONFIG, ...args];
|
|
54
|
-
}
|
|
55
|
-
function gitResult(cwd, args, options = {}) {
|
|
56
|
-
const result = Bun.spawnSync(gitCommandArgs(args), {
|
|
57
|
-
cwd,
|
|
58
|
-
...options.stdin !== void 0 ? { stdin: options.stdin } : {},
|
|
59
|
-
stdout: "pipe",
|
|
60
|
-
stderr: "pipe",
|
|
61
|
-
env: options.environment ?? (0, import_git_process_environment.workerGitProcessEnvironment)()
|
|
62
|
-
});
|
|
63
|
-
return { exitCode: result.exitCode, stdout: Buffer.from(result.stdout), stderr: Buffer.from(result.stderr) };
|
|
64
|
-
}
|
|
65
|
-
function git(cwd, args, action, options = {}) {
|
|
66
|
-
const result = gitResult(cwd, args, options);
|
|
67
|
-
if (result.exitCode !== 0) {
|
|
68
|
-
const detail = result.stderr.toString().trim() || result.stdout.toString().trim() || `git exited ${result.exitCode}`;
|
|
69
|
-
throw new Error(`${action}: ${detail}`);
|
|
70
|
-
}
|
|
71
|
-
return result.stdout;
|
|
72
|
-
}
|
|
73
|
-
function gitText(cwd, args, action, options = {}) {
|
|
74
|
-
return git(cwd, args, action, options).toString().trim();
|
|
75
|
-
}
|
|
76
|
-
function gitVersionIsSupported(version) {
|
|
77
|
-
const match = /(?:^|\s)(\d+)\.(\d+)(?:\.\d+)?(?:\s|$)/u.exec(version);
|
|
78
|
-
if (!match) return false;
|
|
79
|
-
const major = Number(match[1]);
|
|
80
|
-
const minor = Number(match[2]);
|
|
81
|
-
return major > MINIMUM_MERGE_TREE_GIT_VERSION.major || major === MINIMUM_MERGE_TREE_GIT_VERSION.major && minor >= MINIMUM_MERGE_TREE_GIT_VERSION.minor;
|
|
82
|
-
}
|
|
83
|
-
function workspaceMergeProjectionSupport() {
|
|
84
|
-
if (cachedWorkspaceMergeProjectionSupport) return cachedWorkspaceMergeProjectionSupport;
|
|
85
|
-
if (process.env.R5D_WORKSPACE_MERGE_PROJECTION === "0") {
|
|
86
|
-
cachedWorkspaceMergeProjectionSupport = {
|
|
87
|
-
supported: false,
|
|
88
|
-
error: "Workspace merge projection is disabled by R5D_WORKSPACE_MERGE_PROJECTION=0; stale mounts will remain pinned until it is enabled"
|
|
89
|
-
};
|
|
90
|
-
return cachedWorkspaceMergeProjectionSupport;
|
|
91
|
-
}
|
|
92
|
-
const version = gitResult(void 0, ["--version"]);
|
|
93
|
-
const versionText = version.stdout.toString().trim();
|
|
94
|
-
if (version.exitCode !== 0 || !gitVersionIsSupported(versionText)) {
|
|
95
|
-
const observed = versionText || version.stderr.toString().trim() || `git exited ${version.exitCode}`;
|
|
96
|
-
cachedWorkspaceMergeProjectionSupport = {
|
|
97
|
-
supported: false,
|
|
98
|
-
error: `Workspace merge projection requires Git 2.40 or newer (found ${observed}); upgrade Git before synchronizing stale mounts`
|
|
99
|
-
};
|
|
100
|
-
return cachedWorkspaceMergeProjectionSupport;
|
|
101
|
-
}
|
|
102
|
-
cachedWorkspaceMergeProjectionSupport = { supported: true };
|
|
103
|
-
return cachedWorkspaceMergeProjectionSupport;
|
|
104
|
-
}
|
|
105
|
-
function normalizeWorkspaceRelativePath(value) {
|
|
106
|
-
const normalized = value.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
107
|
-
if (!normalized || normalized === "." || normalized.includes("\0") || normalized.split("/").some((segment) => segment === ".." || segment === ".git")) {
|
|
108
|
-
throw new Error(`Invalid workspace merge-projection path: ${value}`);
|
|
109
|
-
}
|
|
110
|
-
return normalized;
|
|
111
|
-
}
|
|
112
|
-
function requireObjectId(value, label) {
|
|
113
|
-
if (!/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/u.test(value)) throw new Error(`${label} is not a Git object id: ${value}`);
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
function requireCommit(workspacePath, revision, label) {
|
|
117
|
-
const head = gitText(workspacePath, ["rev-parse", "--verify", `${revision}^{commit}`], `resolve ${label}`);
|
|
118
|
-
return requireObjectId(head, label);
|
|
119
|
-
}
|
|
120
|
-
function workspacePrivateStateDirectory(workspacePath) {
|
|
121
|
-
const gitDirectory = import_node_path.default.join(workspacePath, ".git");
|
|
122
|
-
const gitStatus = import_node_fs.default.lstatSync(gitDirectory);
|
|
123
|
-
if (!gitStatus.isDirectory() || gitStatus.isSymbolicLink()) {
|
|
124
|
-
throw new Error(`Workspace Git directory is not a regular directory: ${gitDirectory}`);
|
|
125
|
-
}
|
|
126
|
-
const stateDirectory = import_node_path.default.join(gitDirectory, "r5d");
|
|
127
|
-
let stateStatus = null;
|
|
128
|
-
try {
|
|
129
|
-
stateStatus = import_node_fs.default.lstatSync(stateDirectory);
|
|
130
|
-
} catch (error) {
|
|
131
|
-
if (error.code !== "ENOENT") throw error;
|
|
132
|
-
}
|
|
133
|
-
if (!stateStatus) import_node_fs.default.mkdirSync(stateDirectory, { mode: 448 });
|
|
134
|
-
else if (!stateStatus.isDirectory() || stateStatus.isSymbolicLink()) {
|
|
135
|
-
throw new Error(`Workspace Git private state is not a regular directory: ${stateDirectory}`);
|
|
136
|
-
}
|
|
137
|
-
return stateDirectory;
|
|
138
|
-
}
|
|
139
|
-
function temporaryIndexPath(workspacePath) {
|
|
140
|
-
return import_node_path.default.join(workspacePrivateStateDirectory(workspacePath), `tmp-index-${crypto.randomUUID()}`);
|
|
141
|
-
}
|
|
142
|
-
function temporaryIndexEnvironment(indexPath) {
|
|
143
|
-
return { ...(0, import_git_process_environment.workerGitProcessEnvironment)(), GIT_INDEX_FILE: indexPath };
|
|
144
|
-
}
|
|
145
|
-
function removeTemporaryIndex(indexPath) {
|
|
146
|
-
import_node_fs.default.rmSync(indexPath, { force: true });
|
|
147
|
-
import_node_fs.default.rmSync(`${indexPath}.lock`, { force: true });
|
|
148
|
-
}
|
|
149
|
-
function sourceEntryPath(sourceRoot, relativePath) {
|
|
150
|
-
const candidate = import_node_path.default.resolve(sourceRoot, ...relativePath.split("/"));
|
|
151
|
-
const relative = import_node_path.default.relative(sourceRoot, candidate);
|
|
152
|
-
if (relative === ".." || relative.startsWith(`..${import_node_path.default.sep}`) || import_node_path.default.isAbsolute(relative)) {
|
|
153
|
-
throw new Error(`Workspace merge-projection source escapes its root: ${relativePath}`);
|
|
154
|
-
}
|
|
155
|
-
return candidate;
|
|
156
|
-
}
|
|
157
|
-
function assertSameOpenFile(before, after, sourcePath) {
|
|
158
|
-
if (!after.isFile() || before.dev !== after.dev || before.ino !== after.ino || before.size !== after.size || before.mode !== after.mode || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs) {
|
|
159
|
-
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function hashRegularFile(workspacePath, sourcePath, entry) {
|
|
163
|
-
const descriptor = import_node_fs.default.openSync(sourcePath, import_node_fs.default.constants.O_RDONLY | import_node_fs.default.constants.O_NOFOLLOW);
|
|
164
|
-
try {
|
|
165
|
-
const before = import_node_fs.default.fstatSync(descriptor);
|
|
166
|
-
if (!before.isFile() || before.size !== entry.size || (before.mode & 511) !== (entry.mode & 511)) {
|
|
167
|
-
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
168
|
-
}
|
|
169
|
-
const objectId = requireObjectId(
|
|
170
|
-
gitText(workspacePath, ["hash-object", "-w", "--stdin"], `hash workspace projection file ${sourcePath}`, {
|
|
171
|
-
stdin: descriptor
|
|
172
|
-
}),
|
|
173
|
-
`Workspace projection blob for ${sourcePath}`
|
|
174
|
-
);
|
|
175
|
-
const after = import_node_fs.default.fstatSync(descriptor);
|
|
176
|
-
assertSameOpenFile(before, after, sourcePath);
|
|
177
|
-
const pathStatus = import_node_fs.default.lstatSync(sourcePath);
|
|
178
|
-
if (pathStatus.dev !== after.dev || pathStatus.ino !== after.ino || !pathStatus.isFile() || pathStatus.isSymbolicLink()) {
|
|
179
|
-
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
180
|
-
}
|
|
181
|
-
return { objectId, projected: (0, import_working_tree_mirror.projectedFileEntry)(after) };
|
|
182
|
-
} finally {
|
|
183
|
-
import_node_fs.default.closeSync(descriptor);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
function hashSymlink(workspacePath, sourcePath, entry) {
|
|
187
|
-
const status = import_node_fs.default.lstatSync(sourcePath);
|
|
188
|
-
if (!status.isSymbolicLink() || import_node_fs.default.readlinkSync(sourcePath) !== entry.target) {
|
|
189
|
-
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
190
|
-
}
|
|
191
|
-
const objectId = requireObjectId(
|
|
192
|
-
gitText(workspacePath, ["hash-object", "-w", "--stdin"], `hash workspace projection symlink ${sourcePath}`, {
|
|
193
|
-
stdin: Buffer.from(entry.target)
|
|
194
|
-
}),
|
|
195
|
-
`Workspace projection symlink blob for ${sourcePath}`
|
|
196
|
-
);
|
|
197
|
-
if (!import_node_fs.default.lstatSync(sourcePath).isSymbolicLink() || import_node_fs.default.readlinkSync(sourcePath) !== entry.target) {
|
|
198
|
-
throw new Error(`Working-tree source changed while its merge projection was being synthesized: ${sourcePath}`);
|
|
199
|
-
}
|
|
200
|
-
return objectId;
|
|
201
|
-
}
|
|
202
|
-
function indexMode(entry) {
|
|
203
|
-
if (entry.kind === "symlink") return "120000";
|
|
204
|
-
return (entry.mode & 73) !== 0 ? "100755" : "100644";
|
|
205
|
-
}
|
|
206
|
-
function indexInfoRecord(mode, objectId, relativePath) {
|
|
207
|
-
return Buffer.concat([Buffer.from(`${mode} ${objectId} `), Buffer.from(relativePath), Buffer.from([0])]);
|
|
208
|
-
}
|
|
209
|
-
function synthesizeMountTree(input) {
|
|
210
|
-
const sourceRoot = import_node_path.default.resolve(input.sourcePath);
|
|
211
|
-
const entries = (0, import_working_tree_mirror.inspectWorkingTree)(sourceRoot, input.sourceMode);
|
|
212
|
-
const indexPath = temporaryIndexPath(input.workspacePath);
|
|
213
|
-
const environment = temporaryIndexEnvironment(indexPath);
|
|
214
|
-
const projectedFiles = {};
|
|
215
|
-
const blobs = /* @__PURE__ */ new Map();
|
|
216
|
-
try {
|
|
217
|
-
git(input.workspacePath, ["read-tree", "--empty"], "initialize workspace projection index", { environment });
|
|
218
|
-
const records = [];
|
|
219
|
-
for (const [relativePath, entry] of [...entries.entries()].sort(([left], [right]) => left.localeCompare(right))) {
|
|
220
|
-
if (entry.kind === "directory") continue;
|
|
221
|
-
if (entry.kind === "gitlink") {
|
|
222
|
-
records.push(indexInfoRecord("160000", entry.objectId, relativePath));
|
|
223
|
-
projectedFiles[relativePath] = { kind: "gitlink", objectId: entry.objectId };
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
226
|
-
const sourcePath = sourceEntryPath(sourceRoot, relativePath);
|
|
227
|
-
let objectId;
|
|
228
|
-
if (entry.kind === "file") {
|
|
229
|
-
const hashed = hashRegularFile(input.workspacePath, sourcePath, entry);
|
|
230
|
-
objectId = hashed.objectId;
|
|
231
|
-
projectedFiles[relativePath] = hashed.projected;
|
|
232
|
-
} else {
|
|
233
|
-
objectId = hashSymlink(input.workspacePath, sourcePath, entry);
|
|
234
|
-
projectedFiles[relativePath] = { kind: "symlink", target: entry.target };
|
|
235
|
-
}
|
|
236
|
-
blobs.set(relativePath, objectId);
|
|
237
|
-
records.push(indexInfoRecord(indexMode(entry), objectId, relativePath));
|
|
238
|
-
}
|
|
239
|
-
if (records.length > 0) {
|
|
240
|
-
git(input.workspacePath, ["update-index", "-z", "--index-info"], "populate workspace projection index", {
|
|
241
|
-
environment,
|
|
242
|
-
stdin: Buffer.concat(records)
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
const tree = requireObjectId(
|
|
246
|
-
gitText(input.workspacePath, ["write-tree"], "write workspace projection mount tree", { environment }),
|
|
247
|
-
"Workspace projection mount tree"
|
|
248
|
-
);
|
|
249
|
-
return { tree, projectedFiles, blobs };
|
|
250
|
-
} finally {
|
|
251
|
-
removeTemporaryIndex(indexPath);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
function ledgerStatMatches(recorded, projected) {
|
|
255
|
-
return recorded !== null && projected?.kind === "file" && projected.ino === recorded.ino && projected.size === recorded.size && projected.mode === recorded.mode && projected.mtimeMs === recorded.mtimeMs && projected.ctimeMs === recorded.ctimeMs;
|
|
256
|
-
}
|
|
257
|
-
function classifyHydrationLedger(input) {
|
|
258
|
-
const entries = Object.entries(input.hydrationLedger ?? {});
|
|
259
|
-
if (entries.length === 0) return { stale: [], merge: [], cleared: [] };
|
|
260
|
-
const probed = gitText(input.workspacePath, ["cat-file", "--batch-check"], "resolve workspace projection basis subtree", {
|
|
261
|
-
stdin: Buffer.from(`${input.basisHead}:${input.workspaceRelativePath}
|
|
262
|
-
`)
|
|
263
|
-
});
|
|
264
|
-
const basisSubtree = /^([0-9a-f]{40,64}) tree \d+$/u.exec(probed);
|
|
265
|
-
if (!basisSubtree && !/ missing$/u.test(probed))
|
|
266
|
-
throw new Error(`Resolve workspace projection basis subtree: unexpected answer ${probed}`);
|
|
267
|
-
const changed = /* @__PURE__ */ new Set();
|
|
268
|
-
if (!basisSubtree) {
|
|
269
|
-
for (const relativePath of input.blobs.keys()) changed.add(relativePath);
|
|
270
|
-
} else {
|
|
271
|
-
const listing = git(
|
|
272
|
-
input.workspacePath,
|
|
273
|
-
["diff-tree", "-r", "-z", "--no-renames", "--raw", basisSubtree[1], input.mountTree],
|
|
274
|
-
"compare workspace projection with its basis"
|
|
275
|
-
);
|
|
276
|
-
const records = nulRecords(listing);
|
|
277
|
-
for (let index = 0; index + 1 < records.length; index += 2) changed.add(records[index + 1].toString());
|
|
278
|
-
}
|
|
279
|
-
const stale = [];
|
|
280
|
-
const merge = [];
|
|
281
|
-
const cleared = [];
|
|
282
|
-
for (const [relativePath, entry] of entries) {
|
|
283
|
-
const synthesized = input.blobs.get(relativePath);
|
|
284
|
-
if (synthesized === void 0) {
|
|
285
|
-
if (entry.postBlob === null) continue;
|
|
286
|
-
cleared.push(relativePath);
|
|
287
|
-
continue;
|
|
288
|
-
}
|
|
289
|
-
if (ledgerStatMatches(entry.stat, input.projectedFiles[relativePath]) || synthesized === entry.postBlob) continue;
|
|
290
|
-
if (!changed.has(relativePath)) {
|
|
291
|
-
cleared.push(relativePath);
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
if (entry.processLiveAcrossHydration) {
|
|
295
|
-
merge.push({ relativePath, preBlob: entry.preBlob, postBlob: entry.postBlob });
|
|
296
|
-
continue;
|
|
297
|
-
}
|
|
298
|
-
if (synthesized === entry.preBlob) {
|
|
299
|
-
stale.push(relativePath);
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
cleared.push(relativePath);
|
|
303
|
-
}
|
|
304
|
-
if (merge.length > 0) {
|
|
305
|
-
const ids = [...new Set(merge.flatMap(({ preBlob, postBlob }) => postBlob ? [preBlob, postBlob] : [preBlob]))];
|
|
306
|
-
const checked = gitText(input.workspacePath, ["cat-file", "--batch-check"], "verify hydration ledger blobs", {
|
|
307
|
-
stdin: Buffer.from(`${ids.join("\n")}
|
|
308
|
-
`)
|
|
309
|
-
});
|
|
310
|
-
const missing = new Set(
|
|
311
|
-
checked.split("\n").filter((line) => / missing$/u.test(line)).map((line) => line.split(" ")[0])
|
|
312
|
-
);
|
|
313
|
-
if (missing.size > 0) {
|
|
314
|
-
for (let index = merge.length - 1; index >= 0; index -= 1) {
|
|
315
|
-
const { relativePath, preBlob, postBlob } = merge[index];
|
|
316
|
-
if (missing.has(preBlob) || postBlob !== null && missing.has(postBlob)) {
|
|
317
|
-
merge.splice(index, 1);
|
|
318
|
-
cleared.push(relativePath);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return { stale: stale.sort(), merge: merge.sort((left, right) => left.relativePath.localeCompare(right.relativePath)), cleared: cleared.sort() };
|
|
324
|
-
}
|
|
325
|
-
function hydrationLedgerMergeBase(input) {
|
|
326
|
-
if (input.merges.length === 0) return input.basisHead;
|
|
327
|
-
return commitWithLedgerPaths({
|
|
328
|
-
workspacePath: input.workspacePath,
|
|
329
|
-
workspaceRelativePath: input.workspaceRelativePath,
|
|
330
|
-
parent: input.basisHead,
|
|
331
|
-
paths: input.merges.map(({ relativePath, preBlob }) => ({ relativePath, blob: preBlob })),
|
|
332
|
-
message: JSON.stringify({
|
|
333
|
-
type: "workspace_hydration_ledger_basis",
|
|
334
|
-
mountId: input.mountId,
|
|
335
|
-
attemptId: input.attemptId,
|
|
336
|
-
paths: input.merges.map(({ relativePath }) => relativePath)
|
|
337
|
-
}),
|
|
338
|
-
action: "hydration ledger merge base"
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
function hydrationLedgerTheirs(input) {
|
|
342
|
-
const paths = input.merges.flatMap(({ relativePath, postBlob }) => postBlob ? [{ relativePath, blob: postBlob }] : []);
|
|
343
|
-
if (paths.length === 0) return input.currentHead;
|
|
344
|
-
return commitWithLedgerPaths({
|
|
345
|
-
workspacePath: input.workspacePath,
|
|
346
|
-
workspaceRelativePath: input.workspaceRelativePath,
|
|
347
|
-
parent: input.currentHead,
|
|
348
|
-
paths,
|
|
349
|
-
message: JSON.stringify({
|
|
350
|
-
type: "workspace_hydration_ledger_theirs",
|
|
351
|
-
mountId: input.mountId,
|
|
352
|
-
attemptId: input.attemptId,
|
|
353
|
-
paths: paths.map(({ relativePath }) => relativePath)
|
|
354
|
-
}),
|
|
355
|
-
action: "hydration ledger theirs"
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
function commitWithLedgerPaths(input) {
|
|
359
|
-
const indexPath = temporaryIndexPath(input.workspacePath);
|
|
360
|
-
const environment = temporaryIndexEnvironment(indexPath);
|
|
361
|
-
try {
|
|
362
|
-
git(input.workspacePath, ["read-tree", input.parent], `read workspace tree for the ${input.action}`, { environment });
|
|
363
|
-
const paths = input.paths.map(({ relativePath }) => `${input.workspaceRelativePath}/${relativePath}`);
|
|
364
|
-
const listed = git(
|
|
365
|
-
input.workspacePath,
|
|
366
|
-
["ls-files", "-z", "--stage", "--", ...paths.map((entry) => `:(literal)${entry}`)],
|
|
367
|
-
`inspect modes for the ${input.action}`,
|
|
368
|
-
{ environment }
|
|
369
|
-
);
|
|
370
|
-
const modes = /* @__PURE__ */ new Map();
|
|
371
|
-
for (const record of nulRecords(listed)) {
|
|
372
|
-
const match = /^([0-7]{6}) [0-9a-f]{40,64} [0-3]\t(.+)$/su.exec(record.toString());
|
|
373
|
-
if (match) modes.set(match[2], match[1]);
|
|
374
|
-
}
|
|
375
|
-
const records = input.paths.map(
|
|
376
|
-
({ relativePath, blob }, index) => indexInfoRecord(modes.get(paths[index]) ?? "100644", requireObjectId(blob, `hydration ledger blob for ${relativePath}`), paths[index])
|
|
377
|
-
);
|
|
378
|
-
git(input.workspacePath, ["update-index", "-z", "--index-info"], `rewrite paths for the ${input.action}`, {
|
|
379
|
-
environment,
|
|
380
|
-
stdin: Buffer.concat(records)
|
|
381
|
-
});
|
|
382
|
-
const tree = requireObjectId(gitText(input.workspacePath, ["write-tree"], `write the ${input.action}`, { environment }), `${input.action} tree`);
|
|
383
|
-
return requireObjectId(
|
|
384
|
-
gitText(input.workspacePath, ["commit-tree", tree, "-p", input.parent, "-m", input.message], `commit the ${input.action}`),
|
|
385
|
-
`${input.action} commit`
|
|
386
|
-
);
|
|
387
|
-
} finally {
|
|
388
|
-
removeTemporaryIndex(indexPath);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
function nulRecords(content) {
|
|
392
|
-
const records = [];
|
|
393
|
-
let start = 0;
|
|
394
|
-
for (let index = 0; index < content.length; index += 1) {
|
|
395
|
-
if (content[index] !== 0) continue;
|
|
396
|
-
if (index > start) records.push(content.subarray(start, index));
|
|
397
|
-
start = index + 1;
|
|
398
|
-
}
|
|
399
|
-
if (start < content.length) records.push(content.subarray(start));
|
|
400
|
-
return records;
|
|
401
|
-
}
|
|
402
|
-
function indexedSubtreePaths(content, workspaceRelativePath) {
|
|
403
|
-
const prefix = Buffer.from(workspaceRelativePath);
|
|
404
|
-
const descendantPrefix = Buffer.from(`${workspaceRelativePath}/`);
|
|
405
|
-
const records = nulRecords(content).filter(
|
|
406
|
-
(record) => record.equals(prefix) || record.length > descendantPrefix.length && record.subarray(0, descendantPrefix.length).equals(descendantPrefix)
|
|
407
|
-
);
|
|
408
|
-
return records.length > 0 ? Buffer.concat(records.flatMap((record) => [record, Buffer.from([0])])) : Buffer.alloc(0);
|
|
409
|
-
}
|
|
410
|
-
function graftMountTree(input) {
|
|
411
|
-
const indexPath = temporaryIndexPath(input.workspacePath);
|
|
412
|
-
const environment = temporaryIndexEnvironment(indexPath);
|
|
413
|
-
try {
|
|
414
|
-
git(input.workspacePath, ["read-tree", input.basisHead], "read workspace projection basis", { environment });
|
|
415
|
-
const indexedPaths = git(input.workspacePath, ["ls-files", "-z"], "enumerate workspace projection basis", { environment });
|
|
416
|
-
const removedPaths = indexedSubtreePaths(indexedPaths, input.workspaceRelativePath);
|
|
417
|
-
if (removedPaths.length > 0) {
|
|
418
|
-
git(input.workspacePath, ["update-index", "--force-remove", "-z", "--stdin"], "remove prior workspace projection subtree", {
|
|
419
|
-
environment,
|
|
420
|
-
stdin: removedPaths
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
if (input.mountTree !== null) {
|
|
424
|
-
git(
|
|
425
|
-
input.workspacePath,
|
|
426
|
-
["read-tree", "-i", `--prefix=${input.workspaceRelativePath}/`, input.mountTree],
|
|
427
|
-
"graft workspace projection mount tree",
|
|
428
|
-
{ environment }
|
|
429
|
-
);
|
|
430
|
-
}
|
|
431
|
-
return requireObjectId(
|
|
432
|
-
gitText(input.workspacePath, ["write-tree"], "write grafted workspace projection tree", { environment }),
|
|
433
|
-
"Grafted workspace projection tree"
|
|
434
|
-
);
|
|
435
|
-
} finally {
|
|
436
|
-
removeTemporaryIndex(indexPath);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
function mountSubtreeObjectId(workspacePath, revision, workspaceRelativePath, label) {
|
|
440
|
-
const spec = `${revision}:${workspaceRelativePath}`;
|
|
441
|
-
if (gitResult(workspacePath, ["cat-file", "-e", spec]).exitCode !== 0) return null;
|
|
442
|
-
const type = gitText(workspacePath, ["cat-file", "-t", spec], `inspect ${label}`);
|
|
443
|
-
if (type !== "tree") throw new Error(`${label} is not a directory at ${workspaceRelativePath}`);
|
|
444
|
-
return requireObjectId(gitText(workspacePath, ["rev-parse", spec], `resolve ${label}`), label);
|
|
445
|
-
}
|
|
446
|
-
function synthesizeOursCommit(input) {
|
|
447
|
-
const synthesized = synthesizeMountTree({
|
|
448
|
-
workspacePath: input.workspacePath,
|
|
449
|
-
sourcePath: input.mount.sourcePath,
|
|
450
|
-
sourceMode: input.mount.sourceMode
|
|
451
|
-
});
|
|
452
|
-
const classified = classifyHydrationLedger({
|
|
453
|
-
workspacePath: input.workspacePath,
|
|
454
|
-
workspaceRelativePath: input.workspaceRelativePath,
|
|
455
|
-
basisHead: input.basisHead,
|
|
456
|
-
mountTree: synthesized.tree,
|
|
457
|
-
blobs: synthesized.blobs,
|
|
458
|
-
projectedFiles: synthesized.projectedFiles,
|
|
459
|
-
hydrationLedger: input.hydrationLedger
|
|
460
|
-
});
|
|
461
|
-
if (classified.stale.length > 0) return { staleRewritePaths: classified.stale, staleRewriteCleared: classified.cleared };
|
|
462
|
-
const mergeBase = hydrationLedgerMergeBase({
|
|
463
|
-
workspacePath: input.workspacePath,
|
|
464
|
-
workspaceRelativePath: input.workspaceRelativePath,
|
|
465
|
-
basisHead: input.basisHead,
|
|
466
|
-
merges: classified.merge,
|
|
467
|
-
mountId: input.mount.id,
|
|
468
|
-
attemptId: input.attemptId
|
|
469
|
-
});
|
|
470
|
-
const rootTree = graftMountTree({
|
|
471
|
-
workspacePath: input.workspacePath,
|
|
472
|
-
workspaceRelativePath: input.workspaceRelativePath,
|
|
473
|
-
basisHead: mergeBase,
|
|
474
|
-
mountTree: synthesized.tree
|
|
475
|
-
});
|
|
476
|
-
const message = JSON.stringify({
|
|
477
|
-
type: "workspace_projection_basis",
|
|
478
|
-
mountId: input.mount.id,
|
|
479
|
-
attemptId: input.attemptId
|
|
480
|
-
});
|
|
481
|
-
const oursCommit = requireObjectId(
|
|
482
|
-
gitText(
|
|
483
|
-
input.workspacePath,
|
|
484
|
-
["commit-tree", rootTree, "-p", mergeBase, "-m", message],
|
|
485
|
-
`commit synthesized workspace projection for mount ${input.mount.id}`
|
|
486
|
-
),
|
|
487
|
-
`Synthesized workspace projection commit for mount ${input.mount.id}`
|
|
488
|
-
);
|
|
489
|
-
return {
|
|
490
|
-
oursCommit,
|
|
491
|
-
mergeBase,
|
|
492
|
-
projectedFiles: synthesized.projectedFiles,
|
|
493
|
-
staleRewriteCleared: classified.cleared,
|
|
494
|
-
ledgerMerges: classified.merge
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
function mergeWorkspaceProjectionMount(input) {
|
|
498
|
-
const support = workspaceMergeProjectionSupport();
|
|
499
|
-
if (!support.supported) throw new Error(support.error);
|
|
500
|
-
const workspacePath = import_node_path.default.resolve(input.workspacePath);
|
|
501
|
-
const workspaceRelativePath = normalizeWorkspaceRelativePath(input.mount.workspaceRelativePath);
|
|
502
|
-
const basisHead = requireCommit(workspacePath, input.basisHead, `workspace projection basis for mount ${input.mount.id}`);
|
|
503
|
-
const currentHead = requireCommit(workspacePath, input.currentHead, "current workspace projection head");
|
|
504
|
-
const synthesized = synthesizeOursCommit({
|
|
505
|
-
workspacePath,
|
|
506
|
-
mount: input.mount,
|
|
507
|
-
workspaceRelativePath,
|
|
508
|
-
basisHead,
|
|
509
|
-
attemptId: input.attemptId,
|
|
510
|
-
...input.hydrationLedger ? { hydrationLedger: input.hydrationLedger } : {}
|
|
511
|
-
});
|
|
512
|
-
if ("staleRewritePaths" in synthesized) {
|
|
513
|
-
return { kind: "stale_rewrite", paths: synthesized.staleRewritePaths, staleRewriteCleared: synthesized.staleRewriteCleared };
|
|
514
|
-
}
|
|
515
|
-
const { oursCommit, mergeBase, projectedFiles, staleRewriteCleared, ledgerMerges } = synthesized;
|
|
516
|
-
const ledgerMergedPaths = ledgerMerges.map(({ relativePath }) => relativePath);
|
|
517
|
-
const theirsHead = hydrationLedgerTheirs({
|
|
518
|
-
workspacePath,
|
|
519
|
-
workspaceRelativePath,
|
|
520
|
-
currentHead,
|
|
521
|
-
merges: ledgerMerges,
|
|
522
|
-
mountId: input.mount.id,
|
|
523
|
-
attemptId: input.attemptId
|
|
524
|
-
});
|
|
525
|
-
const readAtMs = Date.now();
|
|
526
|
-
const inboundMountTree = mountSubtreeObjectId(
|
|
527
|
-
workspacePath,
|
|
528
|
-
theirsHead,
|
|
529
|
-
workspaceRelativePath,
|
|
530
|
-
`current workspace head subtree for mount ${input.mount.id}`
|
|
531
|
-
);
|
|
532
|
-
const inboundCommit = requireObjectId(
|
|
533
|
-
gitText(
|
|
534
|
-
workspacePath,
|
|
535
|
-
[
|
|
536
|
-
"commit-tree",
|
|
537
|
-
graftMountTree({ workspacePath, workspaceRelativePath, basisHead: mergeBase, mountTree: inboundMountTree }),
|
|
538
|
-
"-p",
|
|
539
|
-
mergeBase,
|
|
540
|
-
"-m",
|
|
541
|
-
JSON.stringify({ type: "workspace_projection_inbound", mountId: input.mount.id, attemptId: input.attemptId })
|
|
542
|
-
],
|
|
543
|
-
`commit inbound workspace projection for mount ${input.mount.id}`
|
|
544
|
-
),
|
|
545
|
-
`Inbound workspace projection commit for mount ${input.mount.id}`
|
|
546
|
-
);
|
|
547
|
-
const merged = gitResult(workspacePath, [
|
|
548
|
-
"merge-tree",
|
|
549
|
-
"--write-tree",
|
|
550
|
-
`--merge-base=${mergeBase}`,
|
|
551
|
-
"--name-only",
|
|
552
|
-
"-z",
|
|
553
|
-
"--no-messages",
|
|
554
|
-
oursCommit,
|
|
555
|
-
inboundCommit
|
|
556
|
-
]);
|
|
557
|
-
if (merged.exitCode !== 0 && merged.exitCode !== 1) {
|
|
558
|
-
const detail = merged.stderr.toString().trim() || merged.stdout.toString().trim() || `git exited ${merged.exitCode}`;
|
|
559
|
-
throw new Error(`Merge workspace projection for mount ${input.mount.id}: ${detail}`);
|
|
560
|
-
}
|
|
561
|
-
const records = nulRecords(merged.stdout);
|
|
562
|
-
const mergedTree = records.shift()?.toString() ?? "";
|
|
563
|
-
requireObjectId(mergedTree, `Merged workspace projection tree for mount ${input.mount.id}`);
|
|
564
|
-
if (merged.exitCode === 0) {
|
|
565
|
-
const resultTree = graftMountTree({
|
|
566
|
-
workspacePath,
|
|
567
|
-
workspaceRelativePath,
|
|
568
|
-
basisHead: currentHead,
|
|
569
|
-
mountTree: mountSubtreeObjectId(workspacePath, mergedTree, workspaceRelativePath, `merged subtree for mount ${input.mount.id}`)
|
|
570
|
-
});
|
|
571
|
-
return { kind: "clean", resultTree, oursCommit, projectedFiles, readAtMs, staleRewriteCleared, ledgerMergedPaths };
|
|
572
|
-
}
|
|
573
|
-
const conflictPaths = records.map((record) => record.toString()).sort();
|
|
574
|
-
return {
|
|
575
|
-
kind: "conflict",
|
|
576
|
-
oursCommit,
|
|
577
|
-
conflictPaths,
|
|
578
|
-
error: `Workspace projection for mount ${input.mount.id} conflicted with the current workspace head`,
|
|
579
|
-
projectedFiles,
|
|
580
|
-
readAtMs,
|
|
581
|
-
staleRewriteCleared,
|
|
582
|
-
ledgerMergedPaths
|
|
583
|
-
};
|
|
584
|
-
}
|
|
585
|
-
function materializeWorkspaceProjectionTree(input) {
|
|
586
|
-
const workspacePath = import_node_path.default.resolve(input.workspacePath);
|
|
587
|
-
const workspaceRelativePath = normalizeWorkspaceRelativePath(input.workspaceRelativePath);
|
|
588
|
-
const resultTree = requireObjectId(input.resultTree, "Workspace projection result tree");
|
|
589
|
-
const targetPath = import_node_path.default.join(workspacePath, ...workspaceRelativePath.split("/"));
|
|
590
|
-
(0, import_workspace_mount_boundary.assertManagedDirectoryPath)({
|
|
591
|
-
trustedRoot: workspacePath,
|
|
592
|
-
candidate: targetPath,
|
|
593
|
-
label: "Workspace merge-projection target"
|
|
594
|
-
});
|
|
595
|
-
git(workspacePath, ["cat-file", "-e", `${resultTree}^{tree}`], "resolve workspace merge-projection result tree");
|
|
596
|
-
const subtree = gitResult(workspacePath, ["cat-file", "-e", `${resultTree}:${workspaceRelativePath}`]);
|
|
597
|
-
if (subtree.exitCode !== 0) {
|
|
598
|
-
import_node_fs.default.rmSync(targetPath, { recursive: true, force: true });
|
|
599
|
-
return;
|
|
600
|
-
}
|
|
601
|
-
const subtreeType = gitText(
|
|
602
|
-
workspacePath,
|
|
603
|
-
["cat-file", "-t", `${resultTree}:${workspaceRelativePath}`],
|
|
604
|
-
"inspect workspace merge-projection result subtree"
|
|
605
|
-
);
|
|
606
|
-
if (subtreeType !== "tree") {
|
|
607
|
-
throw new Error(`Workspace merge-projection result is not a directory at ${workspaceRelativePath}`);
|
|
608
|
-
}
|
|
609
|
-
import_node_fs.default.rmSync(targetPath, { recursive: true, force: true });
|
|
610
|
-
git(
|
|
611
|
-
workspacePath,
|
|
612
|
-
["checkout", "--no-recurse-submodules", resultTree, "--", `:(literal)${workspaceRelativePath}`],
|
|
613
|
-
"materialize merged workspace projection subtree"
|
|
614
|
-
);
|
|
615
|
-
}
|
|
616
|
-
const workspaceMergeProjectionTestHarness = {
|
|
617
|
-
gitVersionIsSupported,
|
|
618
|
-
resetSupportProbe() {
|
|
619
|
-
cachedWorkspaceMergeProjectionSupport = null;
|
|
620
|
-
}
|
|
621
|
-
};
|
|
622
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
623
|
-
0 && (module.exports = {
|
|
624
|
-
materializeWorkspaceProjectionTree,
|
|
625
|
-
mergeWorkspaceProjectionMount,
|
|
626
|
-
workspaceMergeProjectionSupport,
|
|
627
|
-
workspaceMergeProjectionTestHarness
|
|
628
|
-
});
|