@cerbur/clutch-dsh-worktree 0.1.12 → 0.1.14
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 +312 -433
- package/README.zh.md +265 -348
- package/assets/screenshots/screenshots-dashboard.png +0 -0
- package/assets/screenshots/screenshots-git-reviewer.png +0 -0
- package/lib/client/WorktreeSurface.d.ts.map +1 -1
- package/lib/client/WorktreeSurface.js +140 -18
- package/lib/client/WorktreeSurface.js.map +1 -1
- package/lib/client/context/WorktreeHeroContext.d.ts +4 -3
- package/lib/client/context/WorktreeHeroContext.d.ts.map +1 -1
- package/lib/client/context/WorktreeHeroContext.js +29 -11
- package/lib/client/context/WorktreeHeroContext.js.map +1 -1
- package/lib/client/dashboard/WorktreeDashboard.d.ts +9 -2
- package/lib/client/dashboard/WorktreeDashboard.d.ts.map +1 -1
- package/lib/client/dashboard/WorktreeDashboard.js +165 -14
- package/lib/client/dashboard/WorktreeDashboard.js.map +1 -1
- package/lib/client/dashboard/dashboard-navigation.d.ts +35 -0
- package/lib/client/dashboard/dashboard-navigation.d.ts.map +1 -0
- package/lib/client/dashboard/dashboard-navigation.js +48 -0
- package/lib/client/dashboard/dashboard-navigation.js.map +1 -0
- package/lib/client/dashboard/dashboard-overlay.d.ts +7 -2
- package/lib/client/dashboard/dashboard-overlay.d.ts.map +1 -1
- package/lib/client/dashboard/dashboard-overlay.js +81 -16
- package/lib/client/dashboard/dashboard-overlay.js.map +1 -1
- package/lib/client/dashboard/dashboard-selection.d.ts +5 -3
- package/lib/client/dashboard/dashboard-selection.d.ts.map +1 -1
- package/lib/client/dashboard/dashboard-selection.js +3 -2
- package/lib/client/dashboard/dashboard-selection.js.map +1 -1
- package/lib/client/dashboard/git/GitChangedFiles.d.ts +11 -0
- package/lib/client/dashboard/git/GitChangedFiles.d.ts.map +1 -0
- package/lib/client/dashboard/git/GitChangedFiles.js +101 -0
- package/lib/client/dashboard/git/GitChangedFiles.js.map +1 -0
- package/lib/client/dashboard/git/GitCommitList.d.ts +15 -0
- package/lib/client/dashboard/git/GitCommitList.d.ts.map +1 -0
- package/lib/client/dashboard/git/GitCommitList.js +55 -0
- package/lib/client/dashboard/git/GitCommitList.js.map +1 -0
- package/lib/client/dashboard/git/GitDiffView.d.ts +10 -0
- package/lib/client/dashboard/git/GitDiffView.d.ts.map +1 -0
- package/lib/client/dashboard/git/GitDiffView.js +65 -0
- package/lib/client/dashboard/git/GitDiffView.js.map +1 -0
- package/lib/client/dashboard/git/GitFileTypeIcon.d.ts +8 -0
- package/lib/client/dashboard/git/GitFileTypeIcon.d.ts.map +1 -0
- package/lib/client/dashboard/git/GitFileTypeIcon.js +24 -0
- package/lib/client/dashboard/git/GitFileTypeIcon.js.map +1 -0
- package/lib/client/dashboard/git/GitLineStats.d.ts +10 -0
- package/lib/client/dashboard/git/GitLineStats.d.ts.map +1 -0
- package/lib/client/dashboard/git/GitLineStats.js +9 -0
- package/lib/client/dashboard/git/GitLineStats.js.map +1 -0
- package/lib/client/dashboard/git/WorktreeGitOverview.d.ts +31 -0
- package/lib/client/dashboard/git/WorktreeGitOverview.d.ts.map +1 -0
- package/lib/client/dashboard/git/WorktreeGitOverview.js +89 -0
- package/lib/client/dashboard/git/WorktreeGitOverview.js.map +1 -0
- package/lib/client/dashboard/git/WorktreeGitPanel.d.ts +16 -0
- package/lib/client/dashboard/git/WorktreeGitPanel.d.ts.map +1 -0
- package/lib/client/dashboard/git/WorktreeGitPanel.js +126 -0
- package/lib/client/dashboard/git/WorktreeGitPanel.js.map +1 -0
- package/lib/client/dashboard/git/file-address.d.ts +2 -0
- package/lib/client/dashboard/git/file-address.d.ts.map +1 -0
- package/lib/client/dashboard/git/file-address.js +16 -0
- package/lib/client/dashboard/git/file-address.js.map +1 -0
- package/lib/client/dashboard/git/git-column-split.d.ts +34 -0
- package/lib/client/dashboard/git/git-column-split.d.ts.map +1 -0
- package/lib/client/dashboard/git/git-column-split.js +41 -0
- package/lib/client/dashboard/git/git-column-split.js.map +1 -0
- package/lib/client/dashboard/git/git-diff-parser.d.ts +24 -0
- package/lib/client/dashboard/git/git-diff-parser.d.ts.map +1 -0
- package/lib/client/dashboard/git/git-diff-parser.js +56 -0
- package/lib/client/dashboard/git/git-diff-parser.js.map +1 -0
- package/lib/client/dashboard/git/git-facts.d.ts +22 -0
- package/lib/client/dashboard/git/git-facts.d.ts.map +1 -0
- package/lib/client/dashboard/git/git-facts.js +37 -0
- package/lib/client/dashboard/git/git-facts.js.map +1 -0
- package/lib/client/dashboard/git/git-file-tree.d.ts +16 -0
- package/lib/client/dashboard/git/git-file-tree.d.ts.map +1 -0
- package/lib/client/dashboard/git/git-file-tree.js +52 -0
- package/lib/client/dashboard/git/git-file-tree.js.map +1 -0
- package/lib/client/dashboard/git/git-state-cache.d.ts +49 -0
- package/lib/client/dashboard/git/git-state-cache.d.ts.map +1 -0
- package/lib/client/dashboard/git/git-state-cache.js +80 -0
- package/lib/client/dashboard/git/git-state-cache.js.map +1 -0
- package/lib/client/dashboard/git/useGitPaneSplit.d.ts +33 -0
- package/lib/client/dashboard/git/useGitPaneSplit.d.ts.map +1 -0
- package/lib/client/dashboard/git/useGitPaneSplit.js +119 -0
- package/lib/client/dashboard/git/useGitPaneSplit.js.map +1 -0
- package/lib/client/dashboard/git/useWorktreeGitState.d.ts +60 -0
- package/lib/client/dashboard/git/useWorktreeGitState.d.ts.map +1 -0
- package/lib/client/dashboard/git/useWorktreeGitState.js +650 -0
- package/lib/client/dashboard/git/useWorktreeGitState.js.map +1 -0
- package/lib/client/dashboard/open-in-app-controller.d.ts +1 -0
- package/lib/client/dashboard/open-in-app-controller.d.ts.map +1 -1
- package/lib/client/dashboard/open-in-app-controller.js +6 -24
- package/lib/client/dashboard/open-in-app-controller.js.map +1 -1
- package/lib/client/dashboard/vscode-url.d.ts.map +1 -1
- package/lib/client/dashboard/vscode-url.js +6 -3
- package/lib/client/dashboard/vscode-url.js.map +1 -1
- package/lib/client/entry.d.ts.map +1 -1
- package/lib/client/entry.js +28 -0
- package/lib/client/entry.js.map +1 -1
- package/lib/client/locales.d.ts +158 -0
- package/lib/client/locales.d.ts.map +1 -1
- package/lib/client/locales.js +172 -14
- package/lib/client/locales.js.map +1 -1
- package/lib/client/session/session-view.d.ts +10 -0
- package/lib/client/session/session-view.d.ts.map +1 -1
- package/lib/client/session/session-view.js +57 -0
- package/lib/client/session/session-view.js.map +1 -1
- package/lib/client/session/worktree-session-order.d.ts +2 -5
- package/lib/client/session/worktree-session-order.d.ts.map +1 -1
- package/lib/client/session/worktree-session-order.js +35 -10
- package/lib/client/session/worktree-session-order.js.map +1 -1
- package/lib/client/session/worktree-session-position.d.ts +2 -1
- package/lib/client/session/worktree-session-position.d.ts.map +1 -1
- package/lib/client/session/worktree-session-position.js +10 -3
- package/lib/client/session/worktree-session-position.js.map +1 -1
- package/lib/client/session/worktree-session.d.ts +2 -0
- package/lib/client/session/worktree-session.d.ts.map +1 -1
- package/lib/client/session/worktree-session.js +15 -3
- package/lib/client/session/worktree-session.js.map +1 -1
- package/lib/client/surface/actions/useDragActions.d.ts +33 -2
- package/lib/client/surface/actions/useDragActions.d.ts.map +1 -1
- package/lib/client/surface/actions/useDragActions.js +66 -18
- package/lib/client/surface/actions/useDragActions.js.map +1 -1
- package/lib/client/surface/components/ActiveWorktree.js +2 -2
- package/lib/client/surface/components/ActiveWorktree.js.map +1 -1
- package/lib/client/surface/components/ArchivedWorktree.js +2 -2
- package/lib/client/surface/components/ArchivedWorktree.js.map +1 -1
- package/lib/client/surface/components/ArchivedWorktrees.js +2 -2
- package/lib/client/surface/components/ArchivedWorktrees.js.map +1 -1
- package/lib/client/surface/components/SurfaceContent.d.ts +1 -1
- package/lib/client/surface/components/SurfaceContent.d.ts.map +1 -1
- package/lib/client/surface/components/SurfaceContent.js +1 -1
- package/lib/client/surface/components/SurfaceContent.js.map +1 -1
- package/lib/client/surface/components/SurfaceHeader.d.ts +1 -1
- package/lib/client/surface/components/SurfaceHeader.d.ts.map +1 -1
- package/lib/client/surface/components/SurfaceHeader.js +12 -3
- package/lib/client/surface/components/SurfaceHeader.js.map +1 -1
- package/lib/client/surface/components/WorkspaceTree.js +4 -4
- package/lib/client/surface/components/WorkspaceTree.js.map +1 -1
- package/lib/client/surface/components/rows.d.ts +2 -2
- package/lib/client/surface/components/rows.d.ts.map +1 -1
- package/lib/client/surface/components/rows.js +14 -9
- package/lib/client/surface/components/rows.js.map +1 -1
- package/lib/client/surface/selectors.d.ts +10 -0
- package/lib/client/surface/selectors.d.ts.map +1 -1
- package/lib/client/surface/selectors.js +14 -0
- package/lib/client/surface/selectors.js.map +1 -1
- package/lib/client/surface/state/useSessionExpansion.d.ts +2 -1
- package/lib/client/surface/state/useSessionExpansion.d.ts.map +1 -1
- package/lib/client/surface/state/useSessionExpansion.js +26 -13
- package/lib/client/surface/state/useSessionExpansion.js.map +1 -1
- package/lib/client/surface/state/useSessionOrdering.d.ts +1 -1
- package/lib/client/surface/state/useSessionOrdering.d.ts.map +1 -1
- package/lib/client/surface/state/useSessionOrdering.js +23 -8
- package/lib/client/surface/state/useSessionOrdering.js.map +1 -1
- package/lib/client/surface/types.d.ts +15 -3
- package/lib/client/surface/types.d.ts.map +1 -1
- package/lib/client/view/worktree-expand-state.d.ts +1 -1
- package/lib/client/view/worktree-expand-state.d.ts.map +1 -1
- package/lib/client/view/worktree-expand-state.js +8 -1
- package/lib/client/view/worktree-expand-state.js.map +1 -1
- package/lib/client/view/worktree-view-read.d.ts +3 -1
- package/lib/client/view/worktree-view-read.d.ts.map +1 -1
- package/lib/client/view/worktree-view-read.js +9 -2
- package/lib/client/view/worktree-view-read.js.map +1 -1
- package/lib/client/worktree-connection.d.ts +5 -0
- package/lib/client/worktree-connection.d.ts.map +1 -1
- package/lib/client/worktree-connection.js +14 -0
- package/lib/client/worktree-connection.js.map +1 -1
- package/lib/client.js +3520 -321
- package/lib/client.js.map +1 -1
- package/lib/contract/index.contract.js +10 -0
- package/lib/contract/index.contract.js.map +1 -1
- package/lib/contract/index.d.ts +155 -1
- package/lib/contract/index.d.ts.map +1 -1
- package/lib/contract/index.js +20 -0
- package/lib/contract/index.js.map +1 -1
- package/lib/contract/windows-path.d.ts +11 -0
- package/lib/contract/windows-path.d.ts.map +1 -0
- package/lib/contract/windows-path.js +41 -0
- package/lib/contract/windows-path.js.map +1 -0
- package/lib/host/remote.d.ts.map +1 -1
- package/lib/host/remote.js +5 -0
- package/lib/host/remote.js.map +1 -1
- package/lib/host/service.d.ts +18 -1
- package/lib/host/service.d.ts.map +1 -1
- package/lib/host/service.js +30 -0
- package/lib/host/service.js.map +1 -1
- package/lib/host/worktree-instructions.js +2 -2
- package/lib/host/worktree-instructions.js.map +1 -1
- package/lib/host/worktree-permission-manager.d.ts.map +1 -1
- package/lib/host/worktree-permission-manager.js +5 -1
- package/lib/host/worktree-permission-manager.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/manage/manager-git-history.d.ts +17 -0
- package/lib/manage/manager-git-history.d.ts.map +1 -0
- package/lib/manage/manager-git-history.js +884 -0
- package/lib/manage/manager-git-history.js.map +1 -0
- package/lib/manage/manager-sessions.js +1 -1
- package/lib/manage/manager-sessions.js.map +1 -1
- package/lib/manage/manager-support.d.ts +3 -2
- package/lib/manage/manager-support.d.ts.map +1 -1
- package/lib/manage/manager-support.js +5 -13
- package/lib/manage/manager-support.js.map +1 -1
- package/lib/manage/manager-worktree-lifecycle.d.ts.map +1 -1
- package/lib/manage/manager-worktree-lifecycle.js +11 -3
- package/lib/manage/manager-worktree-lifecycle.js.map +1 -1
- package/lib/manage/manager-worktrees.d.ts.map +1 -1
- package/lib/manage/manager-worktrees.js +24 -0
- package/lib/manage/manager-worktrees.js.map +1 -1
- package/lib/manage/manager.d.ts +18 -1
- package/lib/manage/manager.d.ts.map +1 -1
- package/lib/manage/manager.js +74 -16
- package/lib/manage/manager.js.map +1 -1
- package/lib/provider/git/adapter.d.ts +54 -1
- package/lib/provider/git/adapter.d.ts.map +1 -1
- package/lib/provider/git/adapter.js +824 -2
- package/lib/provider/git/adapter.js.map +1 -1
- package/lib/provider/index.d.ts +2 -2
- package/lib/provider/index.d.ts.map +1 -1
- package/lib/provider/index.js +1 -1
- package/lib/provider/index.js.map +1 -1
- package/lib/provider/mutation-token.d.ts +1 -1
- package/lib/provider/mutation-token.d.ts.map +1 -1
- package/lib/provider/mutation-token.js +1 -0
- package/lib/provider/mutation-token.js.map +1 -1
- package/lib/provider/path-identity.d.ts +8 -0
- package/lib/provider/path-identity.d.ts.map +1 -0
- package/lib/provider/path-identity.js +62 -0
- package/lib/provider/path-identity.js.map +1 -0
- package/lib/provider/sidecar/mutation-lock.d.ts +4 -1
- package/lib/provider/sidecar/mutation-lock.d.ts.map +1 -1
- package/lib/provider/sidecar/mutation-lock.js +5 -11
- package/lib/provider/sidecar/mutation-lock.js.map +1 -1
- package/lib/provider/sidecar/process-liveness.d.ts +12 -0
- package/lib/provider/sidecar/process-liveness.d.ts.map +1 -0
- package/lib/provider/sidecar/process-liveness.js +39 -0
- package/lib/provider/sidecar/process-liveness.js.map +1 -0
- package/lib/provider/sidecar/repository.d.ts +1 -1
- package/lib/provider/sidecar/repository.d.ts.map +1 -1
- package/lib/provider/sidecar/repository.js +3 -2
- package/lib/provider/sidecar/repository.js.map +1 -1
- package/lib/provider/sidecar/sidecar-durability.d.ts +9 -0
- package/lib/provider/sidecar/sidecar-durability.d.ts.map +1 -0
- package/lib/provider/sidecar/sidecar-durability.js +36 -0
- package/lib/provider/sidecar/sidecar-durability.js.map +1 -0
- package/lib/provider/sidecar/sidecar-persistence.d.ts.map +1 -1
- package/lib/provider/sidecar/sidecar-persistence.js +2 -27
- package/lib/provider/sidecar/sidecar-persistence.js.map +1 -1
- package/lib/provider/sidecar/sidecar-schema.d.ts +16 -3
- package/lib/provider/sidecar/sidecar-schema.d.ts.map +1 -1
- package/lib/provider/sidecar/sidecar-schema.js +124 -25
- package/lib/provider/sidecar/sidecar-schema.js.map +1 -1
- package/lib/provider/transaction/operations/create.d.ts.map +1 -1
- package/lib/provider/transaction/operations/create.js +21 -6
- package/lib/provider/transaction/operations/create.js.map +1 -1
- package/lib/provider/transaction/recovery/failure-recovery.d.ts.map +1 -1
- package/lib/provider/transaction/recovery/failure-recovery.js +11 -4
- package/lib/provider/transaction/recovery/failure-recovery.js.map +1 -1
- package/lib/provider/transaction/recovery/recover.d.ts.map +1 -1
- package/lib/provider/transaction/recovery/recover.js +9 -11
- package/lib/provider/transaction/recovery/recover.js.map +1 -1
- package/lib/provider/transaction/support/inspection.d.ts +0 -2
- package/lib/provider/transaction/support/inspection.d.ts.map +1 -1
- package/lib/provider/transaction/support/inspection.js +0 -4
- package/lib/provider/transaction/support/inspection.js.map +1 -1
- package/lib/provider/transaction/support/journal.d.ts.map +1 -1
- package/lib/provider/transaction/support/journal.js +2 -0
- package/lib/provider/transaction/support/journal.js.map +1 -1
- package/lib/provider/transaction/support/paths.d.ts +2 -1
- package/lib/provider/transaction/support/paths.d.ts.map +1 -1
- package/lib/provider/transaction/support/paths.js +2 -12
- package/lib/provider/transaction/support/paths.js.map +1 -1
- package/lib/provider/transaction/types.d.ts +1 -0
- package/lib/provider/transaction/types.d.ts.map +1 -1
- package/lib/provider/types.d.ts +58 -8
- package/lib/provider/types.d.ts.map +1 -1
- package/lib/provider/types.js +1 -1
- package/lib/provider/types.js.map +1 -1
- package/lib/typert.host.js +337 -35
- package/lib/typert.remote-client.d.ts +11 -1
- package/lib/typert.remote-client.d.ts.map +1 -1
- package/lib/typert.remote-client.js +337 -35
- package/package.json +3 -1
- package/assets/screenshots/screenshots-dashboard.webp +0 -0
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
import { useEffect, useMemo, useSyncExternalStore } from 'react';
|
|
2
|
+
import { WORKTREE_GIT_WORKING_TREE } from '../../../contract/index.js';
|
|
3
|
+
import { isMainWorktreeId } from './git-facts.js';
|
|
4
|
+
import { MAX_DIFF_CACHE, MAX_FILE_CACHE, canonicalizeCommits, diffCacheKey, fileForPath, gitCacheKey, isLiveCacheKey, isLiveTarget, sameTarget, summarySelection, trimCache, } from './git-state-cache.js';
|
|
5
|
+
function asError(error) {
|
|
6
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
7
|
+
}
|
|
8
|
+
function normalizeBranch(branch) {
|
|
9
|
+
const normalized = branch?.trim();
|
|
10
|
+
return normalized === undefined || normalized.length === 0 ? undefined : normalized;
|
|
11
|
+
}
|
|
12
|
+
function emptyState(defaultBaselineBranch, main) {
|
|
13
|
+
return {
|
|
14
|
+
branches: { status: 'idle' },
|
|
15
|
+
baselineBranch: normalizeBranch(defaultBaselineBranch),
|
|
16
|
+
history: { status: 'idle' },
|
|
17
|
+
view: main ? 'commits' : 'summary',
|
|
18
|
+
includeWorkingTree: false,
|
|
19
|
+
selectedCommits: [],
|
|
20
|
+
commitMultiSelect: false,
|
|
21
|
+
files: { status: 'idle' },
|
|
22
|
+
diff: { status: 'idle' },
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create the browser-safe Git Dashboard state machine. Construction is inert;
|
|
27
|
+
* the caller explicitly starts history loading on first Git-tab activation.
|
|
28
|
+
*/
|
|
29
|
+
export function createWorktreeGitStateController(input) {
|
|
30
|
+
// Main reads the Workspace-root HEAD history directly; Worktree reads still
|
|
31
|
+
// require either an explicit baseline branch or an immutable acquisition commit.
|
|
32
|
+
const main = isMainWorktreeId(input.worktreeId);
|
|
33
|
+
const capturedBaseline = input.capturedBaseline === true;
|
|
34
|
+
const canRead = (baselineBranch) => main || capturedBaseline || baselineBranch !== undefined;
|
|
35
|
+
let state = emptyState(input.defaultBaselineBranch, main);
|
|
36
|
+
let disposed = false;
|
|
37
|
+
let branchesLoaded = false;
|
|
38
|
+
let branchesRequest = 0;
|
|
39
|
+
let historyLoaded = false;
|
|
40
|
+
let historyRequest = 0;
|
|
41
|
+
let filesRequest = 0;
|
|
42
|
+
let diffRequest = 0;
|
|
43
|
+
let branchesInFlight;
|
|
44
|
+
let historyInFlight;
|
|
45
|
+
const filesInFlight = new Map();
|
|
46
|
+
const diffInFlight = new Map();
|
|
47
|
+
const listeners = new Set();
|
|
48
|
+
const filesCache = new Map();
|
|
49
|
+
const diffCache = new Map();
|
|
50
|
+
const emit = () => {
|
|
51
|
+
if (disposed)
|
|
52
|
+
return;
|
|
53
|
+
for (const listener of listeners)
|
|
54
|
+
listener();
|
|
55
|
+
};
|
|
56
|
+
const update = (next) => {
|
|
57
|
+
if (disposed)
|
|
58
|
+
return;
|
|
59
|
+
state = next;
|
|
60
|
+
emit();
|
|
61
|
+
};
|
|
62
|
+
const invalidateWorkingTreeCache = () => {
|
|
63
|
+
for (const key of filesCache.keys()) {
|
|
64
|
+
if (isLiveCacheKey(key))
|
|
65
|
+
filesCache.delete(key);
|
|
66
|
+
}
|
|
67
|
+
for (const key of diffCache.keys()) {
|
|
68
|
+
if (isLiveCacheKey(key))
|
|
69
|
+
diffCache.delete(key);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const retireLiveInFlight = () => {
|
|
73
|
+
let retired = false;
|
|
74
|
+
for (const key of filesInFlight.keys()) {
|
|
75
|
+
if (isLiveCacheKey(key)) {
|
|
76
|
+
filesInFlight.delete(key);
|
|
77
|
+
retired = true;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const key of diffInFlight.keys()) {
|
|
81
|
+
if (isLiveCacheKey(key)) {
|
|
82
|
+
diffInFlight.delete(key);
|
|
83
|
+
retired = true;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return retired;
|
|
87
|
+
};
|
|
88
|
+
const currentTarget = () => {
|
|
89
|
+
if (state.view === 'summary') {
|
|
90
|
+
return { kind: 'selection', selection: summarySelection(state.includeWorkingTree) };
|
|
91
|
+
}
|
|
92
|
+
if (state.selectedCommit === undefined)
|
|
93
|
+
return undefined;
|
|
94
|
+
if (state.selectedCommit !== WORKTREE_GIT_WORKING_TREE &&
|
|
95
|
+
state.selectedCommits.length > 1) {
|
|
96
|
+
return { kind: 'selection', selection: { kind: 'commits', commits: state.selectedCommits } };
|
|
97
|
+
}
|
|
98
|
+
return { kind: 'commit', commit: state.selectedCommit };
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Stale-response guard. A completion only publishes while it is still the
|
|
102
|
+
* newest request for the same baseline, projection, and selected path.
|
|
103
|
+
*/
|
|
104
|
+
const isCurrentRequest = (request, latestRequest, baselineBranch, target, selectedPath) => {
|
|
105
|
+
if (disposed || request !== latestRequest || state.baselineBranch !== baselineBranch)
|
|
106
|
+
return false;
|
|
107
|
+
const active = currentTarget();
|
|
108
|
+
if (active === undefined || !sameTarget(active, target))
|
|
109
|
+
return false;
|
|
110
|
+
return selectedPath === undefined || state.selectedPath === selectedPath;
|
|
111
|
+
};
|
|
112
|
+
const requestFiles = (baseBranch, history, target) => {
|
|
113
|
+
const key = gitCacheKey(baseBranch, history, target);
|
|
114
|
+
const existing = filesInFlight.get(key);
|
|
115
|
+
if (existing !== undefined)
|
|
116
|
+
return existing;
|
|
117
|
+
if (input.manager === undefined)
|
|
118
|
+
return Promise.reject(new Error('Git manager unavailable'));
|
|
119
|
+
const request = target.kind === 'commit'
|
|
120
|
+
? { commit: target.commit }
|
|
121
|
+
: { selection: target.selection };
|
|
122
|
+
let promise;
|
|
123
|
+
try {
|
|
124
|
+
promise = input.manager.listWorktreeCommitFiles({
|
|
125
|
+
workspaceId: input.workspaceId,
|
|
126
|
+
worktreeId: input.worktreeId,
|
|
127
|
+
...request,
|
|
128
|
+
baseBranch,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
promise = Promise.reject(error);
|
|
133
|
+
}
|
|
134
|
+
filesInFlight.set(key, promise);
|
|
135
|
+
void promise.then(() => {
|
|
136
|
+
if (filesInFlight.get(key) === promise)
|
|
137
|
+
filesInFlight.delete(key);
|
|
138
|
+
}, () => {
|
|
139
|
+
if (filesInFlight.get(key) === promise)
|
|
140
|
+
filesInFlight.delete(key);
|
|
141
|
+
});
|
|
142
|
+
return promise;
|
|
143
|
+
};
|
|
144
|
+
const requestDiff = (baseBranch, history, target, diffPath) => {
|
|
145
|
+
const key = diffCacheKey(baseBranch, history, target, diffPath);
|
|
146
|
+
const existing = diffInFlight.get(key);
|
|
147
|
+
if (existing !== undefined)
|
|
148
|
+
return existing;
|
|
149
|
+
if (input.manager === undefined)
|
|
150
|
+
return Promise.reject(new Error('Git manager unavailable'));
|
|
151
|
+
const request = target.kind === 'commit'
|
|
152
|
+
? { commit: target.commit }
|
|
153
|
+
: { selection: target.selection };
|
|
154
|
+
let promise;
|
|
155
|
+
try {
|
|
156
|
+
promise = input.manager.getWorktreeCommitFileDiff({
|
|
157
|
+
workspaceId: input.workspaceId,
|
|
158
|
+
worktreeId: input.worktreeId,
|
|
159
|
+
...request,
|
|
160
|
+
path: diffPath,
|
|
161
|
+
baseBranch,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
promise = Promise.reject(error);
|
|
166
|
+
}
|
|
167
|
+
diffInFlight.set(key, promise);
|
|
168
|
+
void promise.then(() => {
|
|
169
|
+
if (diffInFlight.get(key) === promise)
|
|
170
|
+
diffInFlight.delete(key);
|
|
171
|
+
}, () => {
|
|
172
|
+
if (diffInFlight.get(key) === promise)
|
|
173
|
+
diffInFlight.delete(key);
|
|
174
|
+
});
|
|
175
|
+
return promise;
|
|
176
|
+
};
|
|
177
|
+
const loadDiff = async (target, selectedPath, diffPath) => {
|
|
178
|
+
const baselineBranch = state.baselineBranch;
|
|
179
|
+
if (!canRead(baselineBranch))
|
|
180
|
+
return;
|
|
181
|
+
const request = ++diffRequest;
|
|
182
|
+
const key = diffCacheKey(baselineBranch, state.history, target, diffPath);
|
|
183
|
+
const cached = isLiveTarget(target) ? undefined : diffCache.get(key);
|
|
184
|
+
if (cached !== undefined) {
|
|
185
|
+
update({ ...state, selectedPath, diff: { status: 'ready', value: cached } });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
update({ ...state, selectedPath, diff: { status: 'loading' } });
|
|
189
|
+
try {
|
|
190
|
+
const value = await requestDiff(baselineBranch, state.history, target, diffPath);
|
|
191
|
+
if (!isCurrentRequest(request, diffRequest, baselineBranch, target, selectedPath))
|
|
192
|
+
return;
|
|
193
|
+
if (!isLiveTarget(target)) {
|
|
194
|
+
diffCache.set(key, value);
|
|
195
|
+
trimCache(diffCache, MAX_DIFF_CACHE);
|
|
196
|
+
}
|
|
197
|
+
update({ ...state, diff: { status: 'ready', value } });
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (!isCurrentRequest(request, diffRequest, baselineBranch, target, selectedPath))
|
|
201
|
+
return;
|
|
202
|
+
update({ ...state, diff: { status: 'error', error: asError(error) } });
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const applyFiles = (target, value) => {
|
|
206
|
+
const selectedPath = value.files[0]?.path;
|
|
207
|
+
update({
|
|
208
|
+
...state,
|
|
209
|
+
files: { status: 'ready', value },
|
|
210
|
+
selectedPath,
|
|
211
|
+
diff: { status: 'idle' },
|
|
212
|
+
});
|
|
213
|
+
if (selectedPath !== undefined)
|
|
214
|
+
void loadDiff(target, selectedPath, selectedPath);
|
|
215
|
+
};
|
|
216
|
+
const loadFiles = async (target, preserveReady = false) => {
|
|
217
|
+
const baselineBranch = state.baselineBranch;
|
|
218
|
+
if (!canRead(baselineBranch))
|
|
219
|
+
return;
|
|
220
|
+
const request = ++filesRequest;
|
|
221
|
+
++diffRequest;
|
|
222
|
+
const key = gitCacheKey(baselineBranch, state.history, target);
|
|
223
|
+
const cached = isLiveTarget(target) ? undefined : filesCache.get(key);
|
|
224
|
+
if (cached !== undefined) {
|
|
225
|
+
applyFiles(target, cached);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const previousFiles = state.files.status === 'ready' ? state.files : undefined;
|
|
229
|
+
if (!preserveReady || previousFiles === undefined) {
|
|
230
|
+
update({ ...state, files: { status: 'loading' }, selectedPath: undefined, diff: { status: 'idle' } });
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
update({ ...state, files: { ...previousFiles, refreshing: true } });
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
const value = await requestFiles(baselineBranch, state.history, target);
|
|
237
|
+
if (!isCurrentRequest(request, filesRequest, baselineBranch, target))
|
|
238
|
+
return;
|
|
239
|
+
if (!isLiveTarget(target)) {
|
|
240
|
+
filesCache.set(key, value);
|
|
241
|
+
trimCache(filesCache, MAX_FILE_CACHE);
|
|
242
|
+
}
|
|
243
|
+
applyFiles(target, value);
|
|
244
|
+
}
|
|
245
|
+
catch (error) {
|
|
246
|
+
if (!isCurrentRequest(request, filesRequest, baselineBranch, target))
|
|
247
|
+
return;
|
|
248
|
+
if (preserveReady && previousFiles !== undefined) {
|
|
249
|
+
update({ ...state, files: { status: 'ready', value: previousFiles.value, error: asError(error) } });
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
update({ ...state, files: { status: 'error', error: asError(error) }, selectedPath: undefined, diff: { status: 'idle' } });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
const resetTarget = (next) => {
|
|
257
|
+
retireLiveInFlight();
|
|
258
|
+
++filesRequest;
|
|
259
|
+
++diffRequest;
|
|
260
|
+
update({
|
|
261
|
+
...state,
|
|
262
|
+
...next,
|
|
263
|
+
files: { status: 'idle' },
|
|
264
|
+
selectedPath: undefined,
|
|
265
|
+
diff: { status: 'idle' },
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
const selectBaselineBranch = (branch) => {
|
|
269
|
+
if (disposed || main)
|
|
270
|
+
return;
|
|
271
|
+
const nextBranch = normalizeBranch(branch);
|
|
272
|
+
if (state.baselineBranch === nextBranch)
|
|
273
|
+
return;
|
|
274
|
+
++historyRequest;
|
|
275
|
+
++filesRequest;
|
|
276
|
+
++diffRequest;
|
|
277
|
+
historyInFlight = undefined;
|
|
278
|
+
historyLoaded = false;
|
|
279
|
+
filesInFlight.clear();
|
|
280
|
+
diffInFlight.clear();
|
|
281
|
+
filesCache.clear();
|
|
282
|
+
diffCache.clear();
|
|
283
|
+
update({
|
|
284
|
+
...state,
|
|
285
|
+
baselineBranch: nextBranch,
|
|
286
|
+
history: { status: 'idle' },
|
|
287
|
+
view: 'summary',
|
|
288
|
+
selectedCommit: undefined,
|
|
289
|
+
selectedCommits: [],
|
|
290
|
+
files: { status: 'idle' },
|
|
291
|
+
selectedPath: undefined,
|
|
292
|
+
diff: { status: 'idle' },
|
|
293
|
+
});
|
|
294
|
+
// Clearing an explicit selection falls back to the captured baseline, so it
|
|
295
|
+
// must re-read rather than leave the previous branch projection on screen.
|
|
296
|
+
if (nextBranch !== undefined || capturedBaseline)
|
|
297
|
+
void loadHistory();
|
|
298
|
+
};
|
|
299
|
+
const selectSummary = () => {
|
|
300
|
+
if (disposed || main || !canRead(state.baselineBranch))
|
|
301
|
+
return;
|
|
302
|
+
const target = { kind: 'selection', selection: summarySelection(state.includeWorkingTree) };
|
|
303
|
+
resetTarget({ view: 'summary', selectedCommit: undefined, selectedCommits: [] });
|
|
304
|
+
void loadFiles(target);
|
|
305
|
+
};
|
|
306
|
+
const setIncludeWorkingTree = (includeWorkingTree) => {
|
|
307
|
+
if (disposed || main || state.includeWorkingTree === includeWorkingTree)
|
|
308
|
+
return;
|
|
309
|
+
if (state.view !== 'summary' || !canRead(state.baselineBranch)) {
|
|
310
|
+
update({ ...state, includeWorkingTree });
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
const target = { kind: 'selection', selection: summarySelection(includeWorkingTree) };
|
|
314
|
+
resetTarget({ includeWorkingTree });
|
|
315
|
+
void loadFiles(target);
|
|
316
|
+
};
|
|
317
|
+
const selectView = (view) => {
|
|
318
|
+
if (view === 'summary') {
|
|
319
|
+
selectSummary();
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (disposed || !canRead(state.baselineBranch))
|
|
323
|
+
return;
|
|
324
|
+
const selectedCommit = state.selectedCommit;
|
|
325
|
+
const selectedCommits = state.selectedCommits;
|
|
326
|
+
if (state.view === 'commits' && state.files.status === 'ready')
|
|
327
|
+
return;
|
|
328
|
+
resetTarget({ view: 'commits' });
|
|
329
|
+
if (selectedCommit === undefined)
|
|
330
|
+
return;
|
|
331
|
+
const target = selectedCommit !== WORKTREE_GIT_WORKING_TREE && selectedCommits.length > 1
|
|
332
|
+
? { kind: 'selection', selection: { kind: 'commits', commits: selectedCommits } }
|
|
333
|
+
: { kind: 'commit', commit: selectedCommit };
|
|
334
|
+
void loadFiles(target);
|
|
335
|
+
};
|
|
336
|
+
const selectCommit = (commit) => {
|
|
337
|
+
if (disposed || !canRead(state.baselineBranch))
|
|
338
|
+
return;
|
|
339
|
+
const history = state.history.status === 'ready' ? state.history.value : undefined;
|
|
340
|
+
if (history !== undefined && !history.commits.some((candidate) => candidate.sha === commit))
|
|
341
|
+
return;
|
|
342
|
+
const target = { kind: 'commit', commit };
|
|
343
|
+
const selectedCommits = commit === WORKTREE_GIT_WORKING_TREE ? [] : [commit];
|
|
344
|
+
if (state.view === 'commits' && state.selectedCommit === commit && state.files.status === 'ready' && state.selectedCommits.length <= 1)
|
|
345
|
+
return;
|
|
346
|
+
resetTarget({ view: 'commits', selectedCommit: commit, selectedCommits });
|
|
347
|
+
void loadFiles(target);
|
|
348
|
+
};
|
|
349
|
+
const toggleCommit = (commit) => {
|
|
350
|
+
if (disposed || !canRead(state.baselineBranch) || commit === WORKTREE_GIT_WORKING_TREE)
|
|
351
|
+
return;
|
|
352
|
+
const history = state.history.status === 'ready' ? state.history.value : undefined;
|
|
353
|
+
if (history === undefined || !history.commits.some((candidate) => candidate.sha === commit && candidate.sha !== WORKTREE_GIT_WORKING_TREE))
|
|
354
|
+
return;
|
|
355
|
+
const selected = state.selectedCommits.includes(commit)
|
|
356
|
+
? state.selectedCommits.filter((candidate) => candidate !== commit)
|
|
357
|
+
: [...state.selectedCommits, commit];
|
|
358
|
+
const canonical = canonicalizeCommits(history, selected);
|
|
359
|
+
if (canonical.length === 0) {
|
|
360
|
+
resetTarget({ view: 'commits', selectedCommit: undefined, selectedCommits: [] });
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
const selectedCommit = canonical.includes(commit) ? commit : canonical[canonical.length - 1];
|
|
364
|
+
const target = canonical.length > 1
|
|
365
|
+
? { kind: 'selection', selection: { kind: 'commits', commits: canonical } }
|
|
366
|
+
: { kind: 'commit', commit: selectedCommit };
|
|
367
|
+
resetTarget({ view: 'commits', selectedCommit, selectedCommits: canonical });
|
|
368
|
+
void loadFiles(target);
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Switch between replace-on-click and additive selection. Turning multi-select
|
|
372
|
+
* off collapses an aggregate target back to its primary commit so the files and
|
|
373
|
+
* diff panes keep matching the visible selection.
|
|
374
|
+
*/
|
|
375
|
+
const setCommitMultiSelect = (enabled) => {
|
|
376
|
+
if (disposed || state.commitMultiSelect === enabled)
|
|
377
|
+
return;
|
|
378
|
+
if (enabled) {
|
|
379
|
+
update({ ...state, commitMultiSelect: true });
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const primary = state.selectedCommit;
|
|
383
|
+
const aggregated = state.view === 'commits' && primary !== undefined && state.selectedCommits.length > 1;
|
|
384
|
+
if (!aggregated) {
|
|
385
|
+
update({
|
|
386
|
+
...state,
|
|
387
|
+
commitMultiSelect: false,
|
|
388
|
+
selectedCommits: primary === undefined ? [] : [primary],
|
|
389
|
+
});
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
// selectCommit must still observe the aggregate selection; collapsing it first
|
|
393
|
+
// would trip the "already showing this commit" guard and keep the union files.
|
|
394
|
+
update({ ...state, commitMultiSelect: false });
|
|
395
|
+
selectCommit(primary);
|
|
396
|
+
};
|
|
397
|
+
const clearCommitSelection = () => {
|
|
398
|
+
if (disposed || !canRead(state.baselineBranch))
|
|
399
|
+
return;
|
|
400
|
+
resetTarget({ view: 'commits', selectedCommit: undefined, selectedCommits: [] });
|
|
401
|
+
};
|
|
402
|
+
const selectPath = (selectedPath) => {
|
|
403
|
+
if (disposed || state.files.status !== 'ready')
|
|
404
|
+
return;
|
|
405
|
+
const target = currentTarget();
|
|
406
|
+
if (target === undefined)
|
|
407
|
+
return;
|
|
408
|
+
const changedFile = fileForPath(state.files.value, selectedPath);
|
|
409
|
+
if (changedFile === undefined)
|
|
410
|
+
return;
|
|
411
|
+
++diffRequest;
|
|
412
|
+
void loadDiff(target, selectedPath, changedFile.path);
|
|
413
|
+
};
|
|
414
|
+
const loadBranches = (refresh = false) => {
|
|
415
|
+
if (disposed || main)
|
|
416
|
+
return Promise.resolve();
|
|
417
|
+
if (branchesInFlight !== undefined)
|
|
418
|
+
return branchesInFlight;
|
|
419
|
+
if (!refresh && branchesLoaded)
|
|
420
|
+
return Promise.resolve();
|
|
421
|
+
const request = ++branchesRequest;
|
|
422
|
+
const previous = state.branches;
|
|
423
|
+
if (refresh && previous.status === 'ready') {
|
|
424
|
+
update({ ...state, branches: { status: 'ready', value: previous.value, refreshing: true } });
|
|
425
|
+
}
|
|
426
|
+
else if (refresh && previous.status === 'error' && previous.previous !== undefined) {
|
|
427
|
+
update({ ...state, branches: { status: 'ready', value: previous.previous, refreshing: true } });
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
update({ ...state, branches: { status: 'loading' } });
|
|
431
|
+
}
|
|
432
|
+
const run = async () => {
|
|
433
|
+
if (input.manager?.listBranches === undefined) {
|
|
434
|
+
if (!disposed && request === branchesRequest) {
|
|
435
|
+
branchesLoaded = true;
|
|
436
|
+
update({ ...state, branches: { status: 'ready', value: [] } });
|
|
437
|
+
}
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
440
|
+
try {
|
|
441
|
+
const value = await input.manager.listBranches({ workspaceId: input.workspaceId });
|
|
442
|
+
if (disposed || request !== branchesRequest)
|
|
443
|
+
return;
|
|
444
|
+
branchesLoaded = true;
|
|
445
|
+
update({ ...state, branches: { status: 'ready', value } });
|
|
446
|
+
}
|
|
447
|
+
catch (error) {
|
|
448
|
+
if (disposed || request !== branchesRequest)
|
|
449
|
+
return;
|
|
450
|
+
branchesLoaded = false;
|
|
451
|
+
const nextError = asError(error);
|
|
452
|
+
if (previous.status === 'ready') {
|
|
453
|
+
update({ ...state, branches: { status: 'ready', value: previous.value, error: nextError } });
|
|
454
|
+
}
|
|
455
|
+
else if (previous.status === 'error' && previous.previous !== undefined) {
|
|
456
|
+
update({ ...state, branches: { status: 'ready', value: previous.previous, error: nextError } });
|
|
457
|
+
}
|
|
458
|
+
else {
|
|
459
|
+
update({ ...state, branches: { status: 'error', error: nextError } });
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const promise = run().finally(() => {
|
|
464
|
+
if (branchesInFlight === promise)
|
|
465
|
+
branchesInFlight = undefined;
|
|
466
|
+
});
|
|
467
|
+
branchesInFlight = promise;
|
|
468
|
+
return promise;
|
|
469
|
+
};
|
|
470
|
+
const loadHistory = (refresh = false) => {
|
|
471
|
+
if (disposed || !canRead(state.baselineBranch))
|
|
472
|
+
return Promise.resolve();
|
|
473
|
+
if (historyInFlight !== undefined)
|
|
474
|
+
return historyInFlight;
|
|
475
|
+
if (!refresh && historyLoaded)
|
|
476
|
+
return Promise.resolve();
|
|
477
|
+
const baselineBranch = state.baselineBranch;
|
|
478
|
+
const request = ++historyRequest;
|
|
479
|
+
const previous = state.history;
|
|
480
|
+
const refreshesWorkingTree = refresh && state.selectedCommit === WORKTREE_GIT_WORKING_TREE;
|
|
481
|
+
if (refresh) {
|
|
482
|
+
const retiredLiveReads = retireLiveInFlight();
|
|
483
|
+
if (retiredLiveReads) {
|
|
484
|
+
++filesRequest;
|
|
485
|
+
++diffRequest;
|
|
486
|
+
if (state.files.status === 'loading') {
|
|
487
|
+
update({ ...state, files: { status: 'idle' }, selectedPath: undefined, diff: { status: 'idle' } });
|
|
488
|
+
}
|
|
489
|
+
else if (state.diff.status === 'loading') {
|
|
490
|
+
update({ ...state, diff: { status: 'idle' } });
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (refreshesWorkingTree)
|
|
495
|
+
invalidateWorkingTreeCache();
|
|
496
|
+
if (refresh && previous.status === 'ready') {
|
|
497
|
+
update({ ...state, history: { status: 'ready', value: previous.value, refreshing: true } });
|
|
498
|
+
}
|
|
499
|
+
else if (refresh && previous.status === 'error' && previous.previous !== undefined) {
|
|
500
|
+
update({ ...state, history: { status: 'ready', value: previous.previous, refreshing: true } });
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
503
|
+
update({ ...state, history: { status: 'loading' } });
|
|
504
|
+
}
|
|
505
|
+
const run = async () => {
|
|
506
|
+
if (input.manager === undefined) {
|
|
507
|
+
const error = new Error('Git manager unavailable');
|
|
508
|
+
if (!disposed && request === historyRequest) {
|
|
509
|
+
historyLoaded = true;
|
|
510
|
+
update({ ...state, history: { status: 'error', error } });
|
|
511
|
+
}
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
try {
|
|
515
|
+
const value = await input.manager.listWorktreeCommits({
|
|
516
|
+
workspaceId: input.workspaceId,
|
|
517
|
+
worktreeId: input.worktreeId,
|
|
518
|
+
baseBranch: baselineBranch,
|
|
519
|
+
});
|
|
520
|
+
if (disposed || request !== historyRequest || state.baselineBranch !== baselineBranch)
|
|
521
|
+
return;
|
|
522
|
+
historyLoaded = true;
|
|
523
|
+
const selectedCommits = state.view === 'summary'
|
|
524
|
+
? []
|
|
525
|
+
: canonicalizeCommits(value, state.selectedCommits);
|
|
526
|
+
const selectedCommitStillExists = state.view !== 'summary' &&
|
|
527
|
+
state.selectedCommit !== undefined &&
|
|
528
|
+
value.commits.some((commit) => commit.sha === state.selectedCommit);
|
|
529
|
+
const nextSelectedCommit = state.view === 'summary'
|
|
530
|
+
? undefined
|
|
531
|
+
: selectedCommitStillExists
|
|
532
|
+
? state.selectedCommit
|
|
533
|
+
: selectedCommits[0] ?? value.commits[0]?.sha;
|
|
534
|
+
const nextSelectedCommits = state.view === 'summary'
|
|
535
|
+
? []
|
|
536
|
+
: selectedCommits.length > 0
|
|
537
|
+
? selectedCommits
|
|
538
|
+
: nextSelectedCommit !== undefined && nextSelectedCommit !== WORKTREE_GIT_WORKING_TREE
|
|
539
|
+
? [nextSelectedCommit]
|
|
540
|
+
: [];
|
|
541
|
+
update({
|
|
542
|
+
...state,
|
|
543
|
+
history: { status: 'ready', value },
|
|
544
|
+
selectedCommits: nextSelectedCommits,
|
|
545
|
+
selectedCommit: nextSelectedCommit,
|
|
546
|
+
});
|
|
547
|
+
if (state.view === 'summary') {
|
|
548
|
+
void loadFiles({ kind: 'selection', selection: summarySelection(state.includeWorkingTree) }, true);
|
|
549
|
+
}
|
|
550
|
+
else if (nextSelectedCommit === undefined) {
|
|
551
|
+
resetTarget({ selectedCommit: undefined, selectedCommits: [] });
|
|
552
|
+
}
|
|
553
|
+
else if (!selectedCommitStillExists || selectedCommits.length !== state.selectedCommits.length || refreshesWorkingTree) {
|
|
554
|
+
const target = nextSelectedCommit !== WORKTREE_GIT_WORKING_TREE && selectedCommits.length > 1
|
|
555
|
+
? { kind: 'selection', selection: { kind: 'commits', commits: selectedCommits } }
|
|
556
|
+
: { kind: 'commit', commit: nextSelectedCommit };
|
|
557
|
+
void loadFiles(target, refreshesWorkingTree);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
if (disposed || request !== historyRequest || state.baselineBranch !== baselineBranch)
|
|
562
|
+
return;
|
|
563
|
+
historyLoaded = true;
|
|
564
|
+
const nextError = asError(error);
|
|
565
|
+
if (previous.status === 'ready') {
|
|
566
|
+
update({ ...state, history: { status: 'ready', value: previous.value, error: nextError } });
|
|
567
|
+
}
|
|
568
|
+
else if (previous.status === 'error' && previous.previous !== undefined) {
|
|
569
|
+
update({ ...state, history: { status: 'ready', value: previous.previous, error: nextError } });
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
update({ ...state, history: { status: 'error', error: nextError } });
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
const promise = run().finally(() => {
|
|
577
|
+
if (historyInFlight === promise)
|
|
578
|
+
historyInFlight = undefined;
|
|
579
|
+
});
|
|
580
|
+
historyInFlight = promise;
|
|
581
|
+
return promise;
|
|
582
|
+
};
|
|
583
|
+
const controller = {
|
|
584
|
+
getSnapshot: () => state,
|
|
585
|
+
subscribe: (listener) => {
|
|
586
|
+
listeners.add(listener);
|
|
587
|
+
return () => listeners.delete(listener);
|
|
588
|
+
},
|
|
589
|
+
loadBranches: () => loadBranches(false),
|
|
590
|
+
loadHistory: () => loadHistory(false),
|
|
591
|
+
refresh: () => {
|
|
592
|
+
const branchesTask = loadBranches(true);
|
|
593
|
+
const historyTask = loadHistory(true);
|
|
594
|
+
return Promise.all([branchesTask, historyTask]).then(() => undefined);
|
|
595
|
+
},
|
|
596
|
+
selectBaselineBranch,
|
|
597
|
+
selectView,
|
|
598
|
+
selectSummary,
|
|
599
|
+
setIncludeWorkingTree,
|
|
600
|
+
selectCommit,
|
|
601
|
+
toggleCommit,
|
|
602
|
+
setCommitMultiSelect,
|
|
603
|
+
clearCommitSelection,
|
|
604
|
+
selectPath,
|
|
605
|
+
dispose: () => {
|
|
606
|
+
if (disposed)
|
|
607
|
+
return;
|
|
608
|
+
disposed = true;
|
|
609
|
+
++branchesRequest;
|
|
610
|
+
++historyRequest;
|
|
611
|
+
++filesRequest;
|
|
612
|
+
++diffRequest;
|
|
613
|
+
listeners.clear();
|
|
614
|
+
},
|
|
615
|
+
};
|
|
616
|
+
return controller;
|
|
617
|
+
}
|
|
618
|
+
/** React adapter; the first Git history request starts in the mount effect. */
|
|
619
|
+
export function useWorktreeGitState(input) {
|
|
620
|
+
const controller = useMemo(() => createWorktreeGitStateController(input), [
|
|
621
|
+
input.manager,
|
|
622
|
+
input.workspaceId,
|
|
623
|
+
input.worktreeId,
|
|
624
|
+
input.defaultBaselineBranch,
|
|
625
|
+
input.capturedBaseline,
|
|
626
|
+
]);
|
|
627
|
+
const snapshot = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
|
|
628
|
+
useEffect(() => {
|
|
629
|
+
void controller.loadBranches();
|
|
630
|
+
void controller.loadHistory();
|
|
631
|
+
return controller.dispose;
|
|
632
|
+
}, [controller]);
|
|
633
|
+
return {
|
|
634
|
+
...snapshot,
|
|
635
|
+
loadBranches: controller.loadBranches,
|
|
636
|
+
loadHistory: controller.loadHistory,
|
|
637
|
+
refresh: controller.refresh,
|
|
638
|
+
selectBaselineBranch: controller.selectBaselineBranch,
|
|
639
|
+
selectView: controller.selectView,
|
|
640
|
+
selectSummary: controller.selectSummary,
|
|
641
|
+
setIncludeWorkingTree: controller.setIncludeWorkingTree,
|
|
642
|
+
selectCommit: controller.selectCommit,
|
|
643
|
+
toggleCommit: controller.toggleCommit,
|
|
644
|
+
setCommitMultiSelect: controller.setCommitMultiSelect,
|
|
645
|
+
clearCommitSelection: controller.clearCommitSelection,
|
|
646
|
+
selectPath: controller.selectPath,
|
|
647
|
+
dispose: controller.dispose,
|
|
648
|
+
};
|
|
649
|
+
}
|
|
650
|
+
//# sourceMappingURL=useWorktreeGitState.js.map
|