@young1lin/dsh-ui-gitworkbench 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +70 -0
- package/LICENSE +21 -0
- package/README.md +395 -0
- package/README_EN.md +74 -0
- package/cordis.patch.yml +7 -0
- package/lib/atomic-json.js +48 -0
- package/lib/client.js +15297 -0
- package/lib/commit-cache.js +68 -0
- package/lib/git-log.js +79 -0
- package/lib/git-ops.js +409 -0
- package/lib/index.js +1143 -0
- package/lib/style-store.js +123 -0
- package/lib/worktree.js +112 -0
- package/package.json +86 -0
- package/scripts/install.ps1 +240 -0
- package/scripts/install.sh +231 -0
- package/src/atomic-json.ts +55 -0
- package/src/client/GitWorkbenchPanel.module.css +1512 -0
- package/src/client/GitWorkbenchPanel.tsx +3446 -0
- package/src/client/commit-graph.ts +140 -0
- package/src/client/diff-model.ts +193 -0
- package/src/client/highlight.ts +257 -0
- package/src/client/index.ts +198 -0
- package/src/client/locales.ts +270 -0
- package/src/client/op-feedback.ts +65 -0
- package/src/client/stage-tree.ts +178 -0
- package/src/client/themes.ts +181 -0
- package/src/client/worktree-view.ts +193 -0
- package/src/commit-cache.ts +69 -0
- package/src/git-log.ts +92 -0
- package/src/git-ops.ts +490 -0
- package/src/index.ts +1172 -0
- package/src/style-store.ts +144 -0
- package/src/types/dsh-client-shim.d.ts +100 -0
- package/src/types/dsh-shim.d.ts +77 -0
- package/src/worktree.ts +142 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crash-safe JSON writes for this plugin's small state files under `~/.dsh`.
|
|
3
|
+
*
|
|
4
|
+
* IO is passed in rather than imported so the callers stay testable without a
|
|
5
|
+
* real filesystem, and so the one Windows-specific retry lives in a single place
|
|
6
|
+
* instead of once per state file.
|
|
7
|
+
*/
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
/** Backoff before each rename retry, in ms. */
|
|
10
|
+
const RENAME_RETRY_DELAYS = [25, 50, 100, 200, 400];
|
|
11
|
+
/**
|
|
12
|
+
* @param ms - milliseconds to wait.
|
|
13
|
+
* @returns a promise resolving after that delay.
|
|
14
|
+
*/
|
|
15
|
+
function delay(ms) {
|
|
16
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Write a JSON value so a crash can never leave a truncated file behind.
|
|
20
|
+
*
|
|
21
|
+
* The value is staged into `<path>.tmp` and renamed over the destination, which
|
|
22
|
+
* is atomic within a filesystem. On Windows that rename fails with EPERM while
|
|
23
|
+
* another handle briefly holds the destination open (a concurrent read, an
|
|
24
|
+
* antivirus scan, the search indexer); those locks are short-lived, so the
|
|
25
|
+
* rename is retried with backoff before the error is surfaced.
|
|
26
|
+
* @param ensureDir - creates the containing directory, recursively.
|
|
27
|
+
* @param writeText - writes a file's whole text.
|
|
28
|
+
* @param rename - renames a path over another.
|
|
29
|
+
* @param path - destination path.
|
|
30
|
+
* @param value - JSON-serializable value.
|
|
31
|
+
* @throws whatever `rename` threw, once the retries are exhausted.
|
|
32
|
+
*/
|
|
33
|
+
export async function saveJsonAtomic(ensureDir, writeText, rename, path, value) {
|
|
34
|
+
await ensureDir(join(path, '..'));
|
|
35
|
+
const tmp = `${path}.tmp`;
|
|
36
|
+
await writeText(tmp, `${JSON.stringify(value, null, 2)}\n`);
|
|
37
|
+
for (let attempt = 0;; attempt++) {
|
|
38
|
+
try {
|
|
39
|
+
await rename(tmp, path);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (attempt >= RENAME_RETRY_DELAYS.length)
|
|
44
|
+
throw error;
|
|
45
|
+
await delay(RENAME_RETRY_DELAYS[attempt]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|