@laoyuehanni/dsh-git-worktree 0.4.2 → 0.4.3
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 +10 -0
- package/README.zh.md +10 -0
- package/lib/client.js +171 -25
- package/lib/client.js.map +1 -1
- package/lib/git.d.ts +12 -2
- package/lib/git.js +22 -10
- package/lib/routes.js +5 -2
- package/package.json +1 -1
package/lib/git.d.ts
CHANGED
|
@@ -191,6 +191,14 @@ export declare function removeWorktree(exec: Exec, repoRoot: string, worktreePat
|
|
|
191
191
|
* facts the sidebar grouping needs and nothing else (no branch list, no
|
|
192
192
|
* worktree list — {@link probeRepo} stays the full-facts path for the chip).
|
|
193
193
|
*
|
|
194
|
+
* All three facts come from ONE `git rev-parse` invocation: the sidebar
|
|
195
|
+
* probes every registered workspace on each mount, and on Windows every git
|
|
196
|
+
* call is a process spawn, so three sequential spawns per directory made the
|
|
197
|
+
* startup probe cost scale with the workspace count directly. `rev-parse`
|
|
198
|
+
* evaluates each flag in turn and prints one line per answer, so
|
|
199
|
+
* `--show-toplevel`, `--git-common-dir`, and `--abbrev-ref HEAD` fold into a
|
|
200
|
+
* single process.
|
|
201
|
+
*
|
|
194
202
|
* `repoRoot` — the grouping key — is derived from `--git-common-dir`, which
|
|
195
203
|
* names the SHARED `<repo>/.git` from every worktree of the repository: the
|
|
196
204
|
* main checkout reports it directly, a linked worktree reports the path back
|
|
@@ -198,8 +206,10 @@ export declare function removeWorktree(exec: Exec, repoRoot: string, worktreePat
|
|
|
198
206
|
* together, wherever the linked folder physically lives.
|
|
199
207
|
* `main` is decided without `worktree list`: a directory is the main worktree
|
|
200
208
|
* exactly when its own toplevel holds that shared .git.
|
|
201
|
-
* `branch`
|
|
202
|
-
*
|
|
209
|
+
* `branch` uses `--abbrev-ref HEAD`, whose detached/unborn output is git's
|
|
210
|
+
* synthetic `HEAD` — normalized to null HERE so no consumer downstream ever
|
|
211
|
+
* string-compares against it (the same contract the old `branch
|
|
212
|
+
* --show-current` empty output mapped to).
|
|
203
213
|
* @param exec - executor seam.
|
|
204
214
|
* @param path - absolute directory the workspace reports.
|
|
205
215
|
* @returns the facts, or undefined outside any git repository (a missing git
|
package/lib/git.js
CHANGED
|
@@ -415,6 +415,14 @@ export async function removeWorktree(exec, repoRoot, worktreePath, force, dirExi
|
|
|
415
415
|
* facts the sidebar grouping needs and nothing else (no branch list, no
|
|
416
416
|
* worktree list — {@link probeRepo} stays the full-facts path for the chip).
|
|
417
417
|
*
|
|
418
|
+
* All three facts come from ONE `git rev-parse` invocation: the sidebar
|
|
419
|
+
* probes every registered workspace on each mount, and on Windows every git
|
|
420
|
+
* call is a process spawn, so three sequential spawns per directory made the
|
|
421
|
+
* startup probe cost scale with the workspace count directly. `rev-parse`
|
|
422
|
+
* evaluates each flag in turn and prints one line per answer, so
|
|
423
|
+
* `--show-toplevel`, `--git-common-dir`, and `--abbrev-ref HEAD` fold into a
|
|
424
|
+
* single process.
|
|
425
|
+
*
|
|
418
426
|
* `repoRoot` — the grouping key — is derived from `--git-common-dir`, which
|
|
419
427
|
* names the SHARED `<repo>/.git` from every worktree of the repository: the
|
|
420
428
|
* main checkout reports it directly, a linked worktree reports the path back
|
|
@@ -422,29 +430,33 @@ export async function removeWorktree(exec, repoRoot, worktreePath, force, dirExi
|
|
|
422
430
|
* together, wherever the linked folder physically lives.
|
|
423
431
|
* `main` is decided without `worktree list`: a directory is the main worktree
|
|
424
432
|
* exactly when its own toplevel holds that shared .git.
|
|
425
|
-
* `branch`
|
|
426
|
-
*
|
|
433
|
+
* `branch` uses `--abbrev-ref HEAD`, whose detached/unborn output is git's
|
|
434
|
+
* synthetic `HEAD` — normalized to null HERE so no consumer downstream ever
|
|
435
|
+
* string-compares against it (the same contract the old `branch
|
|
436
|
+
* --show-current` empty output mapped to).
|
|
427
437
|
* @param exec - executor seam.
|
|
428
438
|
* @param path - absolute directory the workspace reports.
|
|
429
439
|
* @returns the facts, or undefined outside any git repository (a missing git
|
|
430
440
|
* binary surfaces the same way — a non-zero exit through the seam).
|
|
431
441
|
*/
|
|
432
442
|
export async function probeWorkspaceGit(exec, path) {
|
|
433
|
-
const
|
|
434
|
-
if (
|
|
443
|
+
const out = await gitMaybe(exec, path, ['rev-parse', '--show-toplevel', '--git-common-dir', '--abbrev-ref', 'HEAD']);
|
|
444
|
+
if (out === undefined)
|
|
435
445
|
return undefined;
|
|
436
|
-
const
|
|
437
|
-
const
|
|
438
|
-
|
|
446
|
+
const lines = out.split('\n').map(line => line.trim());
|
|
447
|
+
const top = lines[0] ?? '';
|
|
448
|
+
const commonDir = lines[1] ?? '';
|
|
449
|
+
const branchName = lines[2] ?? '';
|
|
450
|
+
if (top === '' || commonDir === '')
|
|
439
451
|
return undefined;
|
|
452
|
+
const toplevel = normalize(top);
|
|
440
453
|
// Git outputs carry forward slashes on Windows — normalize every derived
|
|
441
454
|
// path so consumers can compare against join()-built ones.
|
|
442
|
-
const gitDir = normalize(resolve(path, commonDir
|
|
443
|
-
const branchName = (await gitMaybe(exec, path, ['branch', '--show-current']))?.trim() ?? '';
|
|
455
|
+
const gitDir = normalize(resolve(path, commonDir));
|
|
444
456
|
return {
|
|
445
457
|
repoRoot: dirname(gitDir),
|
|
446
458
|
repoName: basename(dirname(gitDir)),
|
|
447
|
-
branch: branchName === '' ? null : branchName,
|
|
459
|
+
branch: branchName === '' || branchName === 'HEAD' ? null : branchName,
|
|
448
460
|
main: normalize(resolve(toplevel, '.git')) === gitDir,
|
|
449
461
|
};
|
|
450
462
|
}
|
package/lib/routes.js
CHANGED
|
@@ -26,8 +26,11 @@ function fail(status, error) {
|
|
|
26
26
|
}
|
|
27
27
|
/** Upper bound on distinct paths one /group request may probe. */
|
|
28
28
|
const GROUP_PATHS_LIMIT = 256;
|
|
29
|
-
/** Probes per in-flight batch — polite on Windows, where each git call is a
|
|
30
|
-
|
|
29
|
+
/** Probes per in-flight batch — polite on Windows, where each git call is a
|
|
30
|
+
* process spawn. The probe itself is a single `rev-parse` per directory, so
|
|
31
|
+
* the batch can ride wider than the old three-spawn shape without stacking
|
|
32
|
+
* an unreasonable number of concurrent git processes. */
|
|
33
|
+
const GROUP_BATCH_SIZE = 16;
|
|
31
34
|
/**
|
|
32
35
|
* POST /group — git belonging facts for a batch of workspace directories.
|
|
33
36
|
* Deduplicates, validates, probes in bounded batches, and answers 200 with
|