carbonless-review 0.5.0 → 0.6.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build-info.json +2 -2
- package/dist/release-notes.json +72 -1
- package/dist/server/catFile.js +47 -0
- package/dist/server/clone.js +63 -4
- package/dist/server/git.js +101 -10
- package/dist/server/maintenance.js +311 -0
- package/dist/server/serve.js +7 -0
- package/dist/server/winTree.js +181 -0
- package/dist/shared/hunkPairs.js +81 -25
- package/dist/shared/linePairing.js +417 -10
- package/dist/shared/proseFile.js +29 -0
- package/dist/shared/releaseNotes.js +39 -6
- package/dist/shared/whatsNew.js +1 -21
- package/dist/web/assets/FilesPage-BqtcHppk.js +28 -0
- package/dist/web/assets/OverviewPage-uVJqr1wH.js +3 -0
- package/dist/web/assets/{ProgressBar-Dv4C8YgG.js → ProgressBar-BKyCZm0c.js} +2 -2
- package/dist/web/assets/ThreadStatus-CXBOAUy_.js +1 -0
- package/dist/web/assets/VerdictCard-CJAg8myD.js +1 -0
- package/dist/web/assets/{VerdictPage-rR3JQj2p.js → VerdictPage-JCILxv3V.js} +1 -1
- package/dist/web/assets/{WriteWarnings-DRgcrSd5.js → WriteWarnings-DSlpjYmL.js} +1 -1
- package/dist/web/assets/index-C5j0nCVA.js +14 -0
- package/dist/web/assets/index-CBR3gpPD.css +2 -0
- package/dist/web/assets/{sticky-BwNmOiBE.js → sticky-D6zof7vN.js} +1 -1
- package/dist/web/assets/{wordWorker-Chjwk_KW.js → wordWorker-BVR8gtjc.js} +1 -1
- package/dist/web/index.html +4 -4
- package/package.json +74 -876
- package/dist/web/assets/FilesPage-gnMVObbZ.js +0 -28
- package/dist/web/assets/OverviewPage-GSoSktuJ.js +0 -3
- package/dist/web/assets/ThreadStatus-CduHw-m2.js +0 -1
- package/dist/web/assets/VerdictCard-xqdSpX9U.js +0 -1
- package/dist/web/assets/index-CT2flTBE.js +0 -14
- package/dist/web/assets/index-CtIs4q8y.css +0 -2
package/dist/build-info.json
CHANGED
package/dist/release-notes.json
CHANGED
|
@@ -1,7 +1,78 @@
|
|
|
1
1
|
[
|
|
2
2
|
{
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"date": null,
|
|
5
|
+
"notes": [
|
|
6
|
+
{
|
|
7
|
+
"id": "CAR-130",
|
|
8
|
+
"kind": "new",
|
|
9
|
+
"prs": [
|
|
10
|
+
273
|
|
11
|
+
],
|
|
12
|
+
"text": "A line split into several, or several joined into one, now reads as one group with a bracket, marking only the text that changed."
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "CAR-325",
|
|
16
|
+
"kind": "improved",
|
|
17
|
+
"prs": [
|
|
18
|
+
272
|
|
19
|
+
],
|
|
20
|
+
"text": "Reviews stay fast as fetches and review data pile up: crb packs its clones of your repositories in the background once a day while they're idle."
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"id": "CAR-350",
|
|
24
|
+
"kind": "improved",
|
|
25
|
+
"prs": [
|
|
26
|
+
301
|
|
27
|
+
],
|
|
28
|
+
"text": "Shorter release notes. Each note shows a one-line summary, with details on expand."
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "CAR-344",
|
|
32
|
+
"kind": "fixed",
|
|
33
|
+
"prs": [
|
|
34
|
+
286
|
|
35
|
+
],
|
|
36
|
+
"text": "Numbered lists in rendered Markdown now count up like on GitHub."
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "CAR-343",
|
|
40
|
+
"kind": "fixed",
|
|
41
|
+
"prs": [
|
|
42
|
+
291
|
|
43
|
+
],
|
|
44
|
+
"text": "Since view: an SVG shown as Image whose mode was put back since now shows that change's row and box under the picture, instead of only the picture while the bar says \"1 to read\"."
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "CAR-349",
|
|
48
|
+
"kind": "fixed",
|
|
49
|
+
"prs": [
|
|
50
|
+
300
|
|
51
|
+
],
|
|
52
|
+
"text": "On Windows, a git that crb stops (maintenance giving way to an open, a timeout) no longer leaves a stray process running and holding the clone."
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "CAR-352",
|
|
56
|
+
"kind": "fixed",
|
|
57
|
+
"prs": [
|
|
58
|
+
304
|
|
59
|
+
],
|
|
60
|
+
"text": "On Windows, opening a review no longer fails with a permission error when crb has just finished with the same repo."
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"id": "CAR-353",
|
|
64
|
+
"kind": "fixed",
|
|
65
|
+
"prs": [
|
|
66
|
+
305
|
|
67
|
+
],
|
|
68
|
+
"text": "On Windows, clone maintenance now runs at idle CPU priority, so it gives way to other work on the machine."
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"uncovered": []
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"version": "0.5.0",
|
|
75
|
+
"date": "2026-11-29",
|
|
5
76
|
"notes": [
|
|
6
77
|
{
|
|
7
78
|
"id": "CAR-139",
|
package/dist/server/catFile.js
CHANGED
|
@@ -301,6 +301,9 @@ export async function readObject(repo, name, signal) {
|
|
|
301
301
|
name.includes("\0")) {
|
|
302
302
|
return readAlone(repo, name, signal);
|
|
303
303
|
}
|
|
304
|
+
// Paused (clone maintenance): no process held open beside a repack.
|
|
305
|
+
if (paused.has(repo))
|
|
306
|
+
return readAlone(repo, name, signal);
|
|
304
307
|
return processOf(repo).read(name, signal);
|
|
305
308
|
}
|
|
306
309
|
/** A full ref name the shared process takes: `refs/…`, plain characters. */
|
|
@@ -315,6 +318,9 @@ export function readRef(repo, ref, signal) {
|
|
|
315
318
|
if (!REF_NAME.test(ref) || ref.includes("..") || ref.includes("//")) {
|
|
316
319
|
return Promise.reject(new GitError(`Not a ref name: ${ref}`));
|
|
317
320
|
}
|
|
321
|
+
// Paused (clone maintenance): no process held open beside a repack.
|
|
322
|
+
if (paused.has(repo))
|
|
323
|
+
return readAlone(repo, ref, signal);
|
|
318
324
|
return processOf(repo).read(ref, signal);
|
|
319
325
|
}
|
|
320
326
|
/**
|
|
@@ -342,6 +348,47 @@ export async function closeCatFiles() {
|
|
|
342
348
|
p.close();
|
|
343
349
|
await Promise.all([...ending]);
|
|
344
350
|
}
|
|
351
|
+
/** Clones whose reads each run a `cat-file` of their own for now, and by how many pausers. */
|
|
352
|
+
const paused = new Map();
|
|
353
|
+
/**
|
|
354
|
+
* Keeps `repo` without a long-running process until the returned resume is
|
|
355
|
+
* called (clone maintenance: on Windows an open reader keeps a repack from
|
|
356
|
+
* deleting the packs it rolled up). From the call on, every read of the
|
|
357
|
+
* clone runs a `cat-file` of its own that exits when answered, so no read
|
|
358
|
+
* can start a long one meanwhile. The process up now answers every read
|
|
359
|
+
* it has (never failed for the pause), then closes; this settles once it
|
|
360
|
+
* has exited, or at once when `signal` aborts (the pause stays until
|
|
361
|
+
* resumed; the process closes itself once idle).
|
|
362
|
+
*/
|
|
363
|
+
export async function pauseCatFile(repo, signal) {
|
|
364
|
+
paused.set(repo, (paused.get(repo) ?? 0) + 1);
|
|
365
|
+
let resumed = false;
|
|
366
|
+
const resume = () => {
|
|
367
|
+
if (resumed)
|
|
368
|
+
return;
|
|
369
|
+
resumed = true;
|
|
370
|
+
const left = (paused.get(repo) ?? 1) - 1;
|
|
371
|
+
if (left > 0)
|
|
372
|
+
paused.set(repo, left);
|
|
373
|
+
else
|
|
374
|
+
paused.delete(repo);
|
|
375
|
+
};
|
|
376
|
+
const up = processes.get(repo);
|
|
377
|
+
if (up) {
|
|
378
|
+
processes.delete(repo);
|
|
379
|
+
while (!up.dead && !up.idle && !signal?.aborted) {
|
|
380
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
381
|
+
}
|
|
382
|
+
if (up.idle) {
|
|
383
|
+
up.close();
|
|
384
|
+
await Promise.race([
|
|
385
|
+
up.exited,
|
|
386
|
+
new Promise((r) => signal?.addEventListener("abort", () => r(), { once: true })),
|
|
387
|
+
]);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return resume;
|
|
391
|
+
}
|
|
345
392
|
/** How many clones have a process up (tests). */
|
|
346
393
|
export const catFileCount = () => processes.size;
|
|
347
394
|
//# sourceMappingURL=catFile.js.map
|
package/dist/server/clone.js
CHANGED
|
@@ -41,6 +41,8 @@ const LOCK_DEFAULTS = {
|
|
|
41
41
|
timeoutMs: 120_000,
|
|
42
42
|
staleMs: 10 * 60_000,
|
|
43
43
|
heartbeatMs: 30_000,
|
|
44
|
+
// About 5 s: each look waits 100 ms or more.
|
|
45
|
+
maxRefusals: 50,
|
|
44
46
|
};
|
|
45
47
|
const readLock = (lock) => readFile(lock, "utf8").then((text) => text, () => undefined);
|
|
46
48
|
/** Lock content is `<host> <pid> <token>`; older or foreign content has no pid. */
|
|
@@ -76,6 +78,15 @@ async function removeIfUnchanged(lock, content) {
|
|
|
76
78
|
}
|
|
77
79
|
/** This process's holder of each repo lock: what a waiter shows. */
|
|
78
80
|
const lockHolders = new Map();
|
|
81
|
+
/** The holders that give way to a waiter (LockOptions.onWaiter), by repo. */
|
|
82
|
+
const yielders = new Map();
|
|
83
|
+
/** When this process last took or released each repo's lock. */
|
|
84
|
+
const lockUsed = new Map();
|
|
85
|
+
/**
|
|
86
|
+
* When this process last held `path`'s lock (taken or released, epoch ms),
|
|
87
|
+
* or undefined: how maintenance tells a clone in use from an idle one.
|
|
88
|
+
*/
|
|
89
|
+
export const repoLockLastUsed = (path) => lockUsed.get(path);
|
|
79
90
|
/**
|
|
80
91
|
* Runs `fn` while holding `<path>.lock`, so concurrent crb processes never
|
|
81
92
|
* clone or fetch into the same repository at once. The holder refreshes the
|
|
@@ -83,7 +94,10 @@ const lockHolders = new Map();
|
|
|
83
94
|
* when its process on this host is gone (Ctrl-C, crash).
|
|
84
95
|
*/
|
|
85
96
|
export async function withRepoLock(path, fn, options = {}) {
|
|
86
|
-
const { timeoutMs, staleMs, heartbeatMs } = {
|
|
97
|
+
const { timeoutMs, staleMs, heartbeatMs, maxRefusals } = {
|
|
98
|
+
...LOCK_DEFAULTS,
|
|
99
|
+
...options,
|
|
100
|
+
};
|
|
87
101
|
const lock = `${path}.lock`;
|
|
88
102
|
const mine = `${hostname()} ${process.pid} ${randomUUID()}\n`;
|
|
89
103
|
await mkdir(dirname(lock), { recursive: true });
|
|
@@ -91,10 +105,23 @@ export async function withRepoLock(path, fn, options = {}) {
|
|
|
91
105
|
// Waiting for another holder: what it does now, when it is this
|
|
92
106
|
// process's (activity.ts); another crb's reads as the lock's wait.
|
|
93
107
|
let endWait = null;
|
|
108
|
+
// Windows refusals in a row; a holder's lock (EEXIST) ends the run.
|
|
109
|
+
let refusals = 0;
|
|
94
110
|
try {
|
|
95
111
|
for (;;) {
|
|
96
|
-
|
|
112
|
+
const created = await tryCreate(lock, mine);
|
|
113
|
+
if (created === true)
|
|
97
114
|
break;
|
|
115
|
+
refusals = created === false ? 0 : refusals + 1;
|
|
116
|
+
// Still refused well past a delete-pending moment: a real
|
|
117
|
+
// permission problem, said as such rather than waited on.
|
|
118
|
+
if (created !== false && refusals >= maxRefusals)
|
|
119
|
+
throw created;
|
|
120
|
+
// A holder that gives way (maintenance) stops for us; asked on
|
|
121
|
+
// every look, in case it took the lock just as we came.
|
|
122
|
+
const yielder = yielders.get(path);
|
|
123
|
+
yielders.delete(path);
|
|
124
|
+
yielder?.();
|
|
98
125
|
endWait ??= beginStep("wait", "crb: repo lock", undefined, () => lockHolders.get(path));
|
|
99
126
|
const [content, mtime] = await Promise.all([
|
|
100
127
|
readLock(lock),
|
|
@@ -106,6 +133,10 @@ export async function withRepoLock(path, fn, options = {}) {
|
|
|
106
133
|
continue;
|
|
107
134
|
}
|
|
108
135
|
if (Date.now() >= deadline) {
|
|
136
|
+
// Refused at the deadline: said as such, not as a lock to
|
|
137
|
+
// delete (maintenance, which never waits, reads it as busy).
|
|
138
|
+
if (created !== false)
|
|
139
|
+
throw created;
|
|
109
140
|
throw new GitError(`Timed out waiting for ${lock}. If no other crb is running, delete it.`);
|
|
110
141
|
}
|
|
111
142
|
await sleep(100);
|
|
@@ -119,6 +150,10 @@ export async function withRepoLock(path, fn, options = {}) {
|
|
|
119
150
|
// waits on it, so it shows it too.
|
|
120
151
|
const holder = new Activity();
|
|
121
152
|
lockHolders.set(path, holder);
|
|
153
|
+
lockUsed.set(path, Date.now());
|
|
154
|
+
const { onWaiter } = options;
|
|
155
|
+
if (onWaiter)
|
|
156
|
+
yielders.set(path, onWaiter);
|
|
122
157
|
const heartbeat = setInterval(() => {
|
|
123
158
|
const now = new Date();
|
|
124
159
|
readLock(lock).then((c) => {
|
|
@@ -133,20 +168,44 @@ export async function withRepoLock(path, fn, options = {}) {
|
|
|
133
168
|
finally {
|
|
134
169
|
if (lockHolders.get(path) === holder)
|
|
135
170
|
lockHolders.delete(path);
|
|
171
|
+
if (onWaiter && yielders.get(path) === onWaiter)
|
|
172
|
+
yielders.delete(path);
|
|
173
|
+
lockUsed.set(path, Date.now());
|
|
136
174
|
clearInterval(heartbeat);
|
|
137
175
|
if ((await readLock(lock)) === mine)
|
|
138
176
|
await rm(lock, { force: true });
|
|
139
177
|
}
|
|
140
178
|
}
|
|
141
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Whether a refused create of the lock (its error code) means the lock is
|
|
181
|
+
* someone else's for now, to wait for. EEXIST anywhere. On Windows also
|
|
182
|
+
* EPERM and EACCES: a lock just removed while another handle (a reader's
|
|
183
|
+
* look, a virus scan) still had it open stays "delete pending" a moment,
|
|
184
|
+
* and creating it again is refused so (CAR-352). Elsewhere those mean a
|
|
185
|
+
* cache dir crb can't write, which waiting won't fix: they fail at once,
|
|
186
|
+
* as does every other error (ENOENT, ENOSPC, EROFS…).
|
|
187
|
+
*/
|
|
188
|
+
export function lockCreateBusy(code, platform = process.platform) {
|
|
189
|
+
if (code === "EEXIST")
|
|
190
|
+
return true;
|
|
191
|
+
return platform === "win32" && (code === "EPERM" || code === "EACCES");
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Creates `lock` with `content`: true once it's ours; false if someone
|
|
195
|
+
* else holds it; a Windows refusal (lockCreateBusy) to wait on like a
|
|
196
|
+
* holder, thrown if it outlasts the wait.
|
|
197
|
+
*/
|
|
142
198
|
async function tryCreate(lock, content) {
|
|
143
199
|
let handle;
|
|
144
200
|
try {
|
|
145
201
|
handle = await open(lock, "wx");
|
|
146
202
|
}
|
|
147
203
|
catch (error) {
|
|
148
|
-
|
|
204
|
+
const code = error.code;
|
|
205
|
+
if (code === "EEXIST")
|
|
149
206
|
return false;
|
|
207
|
+
if (lockCreateBusy(code))
|
|
208
|
+
return error;
|
|
150
209
|
throw error;
|
|
151
210
|
}
|
|
152
211
|
try {
|
package/dist/server/git.js
CHANGED
|
@@ -2,6 +2,7 @@ import { spawn } from "node:child_process";
|
|
|
2
2
|
import { beginCall } from "./activity.js";
|
|
3
3
|
import { noteSpawn } from "./spawnWatch.js";
|
|
4
4
|
import { argsSummary, tracer } from "./trace.js";
|
|
5
|
+
import { killWindowsTree } from "./winTree.js";
|
|
5
6
|
export class GitError extends Error {
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
@@ -49,8 +50,22 @@ export function inheritedEnv() {
|
|
|
49
50
|
}
|
|
50
51
|
return env;
|
|
51
52
|
}
|
|
52
|
-
/**
|
|
53
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Kills a detached child's whole process group (the child alone if that
|
|
55
|
+
* fails). On Windows the tree goes, then a sweep for what it was starting
|
|
56
|
+
* as it went (winTree.ts): the promise settles once that is done too.
|
|
57
|
+
* `exiting`: crb is on its way out, so the sweep is started detached and
|
|
58
|
+
* outlives it (else it would go with crb, leaving what it was after).
|
|
59
|
+
*/
|
|
60
|
+
function killGroup(child, exiting = false) {
|
|
61
|
+
if (process.platform === "win32") {
|
|
62
|
+
// No process groups: the tree goes (a repack's pack-objects, an
|
|
63
|
+
// alias's shell), else they outlive git holding the clone's files.
|
|
64
|
+
const { killed, swept } = killWindowsTree(child, startedAt.get(child) ?? Date.now(), { detached: exiting });
|
|
65
|
+
if (!killed)
|
|
66
|
+
child.kill("SIGKILL");
|
|
67
|
+
return swept;
|
|
68
|
+
}
|
|
54
69
|
try {
|
|
55
70
|
if (child.pid === undefined)
|
|
56
71
|
throw new Error("not started");
|
|
@@ -59,7 +74,10 @@ function killGroup(child) {
|
|
|
59
74
|
catch {
|
|
60
75
|
child.kill("SIGKILL");
|
|
61
76
|
}
|
|
77
|
+
return Promise.resolve();
|
|
62
78
|
}
|
|
79
|
+
/** When each timed git started: a Windows sweep's lower bound. */
|
|
80
|
+
const startedAt = new WeakMap();
|
|
63
81
|
/**
|
|
64
82
|
* Timed gits still running. They are in their own process groups, so a
|
|
65
83
|
* Ctrl-C to crb no longer reaches them: crb kills them on its way out.
|
|
@@ -72,13 +90,19 @@ const running = new Map();
|
|
|
72
90
|
export function gitChildren() {
|
|
73
91
|
return [...running.values()].map((args) => `git ${args.join(" ")}`.slice(0, 160));
|
|
74
92
|
}
|
|
75
|
-
/**
|
|
93
|
+
/**
|
|
94
|
+
* Kills every timed git still running, with its children. On crb's way
|
|
95
|
+
* out: a Windows sweep runs on by itself, detached.
|
|
96
|
+
*/
|
|
76
97
|
export function killDetachedGits() {
|
|
77
98
|
for (const child of detached)
|
|
78
|
-
killGroup(child);
|
|
99
|
+
void killGroup(child, true);
|
|
79
100
|
detached.clear();
|
|
80
101
|
}
|
|
81
|
-
|
|
102
|
+
/** `at`: taken before the spawn, so a Windows sweep's window opens before
|
|
103
|
+
* the first process of the tree (a low-priority git's wrapper) starts. */
|
|
104
|
+
function trackDetached(child, at) {
|
|
105
|
+
startedAt.set(child, at);
|
|
82
106
|
detached.add(child);
|
|
83
107
|
child.on("close", () => detached.delete(child));
|
|
84
108
|
if (!killOnExit) {
|
|
@@ -87,6 +111,43 @@ function trackDetached(child) {
|
|
|
87
111
|
process.on("exit", killDetachedGits);
|
|
88
112
|
}
|
|
89
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Windows: sets its own priority, then runs the command it is given with
|
|
116
|
+
* this process's stdio and exits with its code (lowPriorityCommand).
|
|
117
|
+
*/
|
|
118
|
+
const LOW_PRIORITY_WRAPPER = [
|
|
119
|
+
'try { require("node:os").setPriority(19); } catch {}',
|
|
120
|
+
"const [command, ...args] = process.argv.slice(1);",
|
|
121
|
+
'const c = require("node:child_process").spawn(command, args, { stdio: "inherit", windowsHide: true });',
|
|
122
|
+
'c.on("error", (e) => { process.stderr.write(e.message + "\\n"); process.exit(127); });',
|
|
123
|
+
'c.on("exit", (code) => process.exit(code ?? 1));',
|
|
124
|
+
].join("\n");
|
|
125
|
+
/** Set once `nice` was found missing (ENOENT): low priority then runs plain git. */
|
|
126
|
+
let niceMissing = false;
|
|
127
|
+
/**
|
|
128
|
+
* How to start `git <args>` at the lowest CPU priority from its first
|
|
129
|
+
* process on (CAR-353): what it starts (pack-objects, an alias's shell)
|
|
130
|
+
* inherits it. Setting it on the pid after spawn came too late: git could
|
|
131
|
+
* have started a child at normal priority by then. POSIX: under `nice`
|
|
132
|
+
* (plain git if there is none). Windows has none, so a node wrapper lowers
|
|
133
|
+
* its own priority class first (a child's class follows a below-normal
|
|
134
|
+
* parent's), then starts git; without NODE_OPTIONS, which is crb's, not
|
|
135
|
+
* the wrapper's (a broken one would stop it before git starts). CPU only:
|
|
136
|
+
* no I/O priority.
|
|
137
|
+
*/
|
|
138
|
+
export function lowPriorityCommand(gitArgs, platform = process.platform, env = {}) {
|
|
139
|
+
if (platform === "win32") {
|
|
140
|
+
const { NODE_OPTIONS: _crbs, ...rest } = env;
|
|
141
|
+
return {
|
|
142
|
+
command: process.execPath,
|
|
143
|
+
args: ["-e", LOW_PRIORITY_WRAPPER, "--", "git", ...gitArgs],
|
|
144
|
+
env: rest,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (niceMissing)
|
|
148
|
+
return { command: "git", args: gitArgs, env };
|
|
149
|
+
return { command: "nice", args: ["-n", "19", "git", ...gitArgs], env };
|
|
150
|
+
}
|
|
90
151
|
/** Spans of each git run, when $CRB_TRACE_DIR is set (trace.ts). */
|
|
91
152
|
const traced = tracer();
|
|
92
153
|
/** git's subcommand in `args` (after `-c k=v` options). */
|
|
@@ -177,8 +238,14 @@ export function runGitFull(repoPath, args, opts = {}) {
|
|
|
177
238
|
})
|
|
178
239
|
: null;
|
|
179
240
|
noteSpawn("git", args, name);
|
|
180
|
-
const
|
|
181
|
-
|
|
241
|
+
const gitArgs = ["-C", repoPath, ...args];
|
|
242
|
+
const env = { ...inheritedEnv(), ...opts.env };
|
|
243
|
+
const run = opts.lowPriority
|
|
244
|
+
? lowPriorityCommand(gitArgs, process.platform, env)
|
|
245
|
+
: { command: "git", args: gitArgs, env };
|
|
246
|
+
const spawnedAt = Date.now();
|
|
247
|
+
const child = spawn(run.command, run.args, {
|
|
248
|
+
env: run.env,
|
|
182
249
|
stdio: ["pipe", "pipe", "pipe"],
|
|
183
250
|
// A timed git gets its own process group, so the timeout kills its
|
|
184
251
|
// children too (a credential helper, an alias, a remote helper).
|
|
@@ -189,7 +256,7 @@ export function runGitFull(repoPath, args, opts = {}) {
|
|
|
189
256
|
windowsHide: true,
|
|
190
257
|
});
|
|
191
258
|
if (opts.timeoutMs !== undefined && !opts.attached)
|
|
192
|
-
trackDetached(child);
|
|
259
|
+
trackDetached(child, spawnedAt);
|
|
193
260
|
running.set(child, args);
|
|
194
261
|
child.on("close", () => running.delete(child));
|
|
195
262
|
child.on("error", () => running.delete(child));
|
|
@@ -202,13 +269,25 @@ export function runGitFull(repoPath, args, opts = {}) {
|
|
|
202
269
|
timedOut = true;
|
|
203
270
|
endStep();
|
|
204
271
|
span?.end({ exit: "killed" }, message);
|
|
272
|
+
let swept = Promise.resolve();
|
|
205
273
|
if (opts.timeoutMs !== undefined && !opts.attached)
|
|
206
|
-
killGroup(child);
|
|
274
|
+
swept = killGroup(child);
|
|
207
275
|
else
|
|
208
276
|
child.kill("SIGKILL");
|
|
209
277
|
child.stdout.destroy();
|
|
210
278
|
child.stderr.destroy();
|
|
211
|
-
|
|
279
|
+
if (opts.waitForExit) {
|
|
280
|
+
// Its tree too: what git was starting as it went (Windows).
|
|
281
|
+
const exited = child.exitCode === null
|
|
282
|
+
? new Promise((r) => {
|
|
283
|
+
child.once("close", () => r());
|
|
284
|
+
child.once("error", () => r());
|
|
285
|
+
})
|
|
286
|
+
: Promise.resolve();
|
|
287
|
+
void Promise.all([exited, swept]).then(() => fail(message));
|
|
288
|
+
}
|
|
289
|
+
else
|
|
290
|
+
fail(message);
|
|
212
291
|
};
|
|
213
292
|
const timer = opts.timeoutMs === undefined
|
|
214
293
|
? undefined
|
|
@@ -223,6 +302,18 @@ export function runGitFull(repoPath, args, opts = {}) {
|
|
|
223
302
|
span?.end(undefined, error.message);
|
|
224
303
|
clearTimeout(timer);
|
|
225
304
|
opts.signal?.removeEventListener("abort", onAbort);
|
|
305
|
+
if (run.command === "nice" &&
|
|
306
|
+
error.code === "ENOENT" &&
|
|
307
|
+
!timedOut) {
|
|
308
|
+
// No `nice` here: git at normal priority, as before CAR-353,
|
|
309
|
+
// rather than no maintenance at all.
|
|
310
|
+
niceMissing = true;
|
|
311
|
+
// Settled by the retry: the failed spawn's close says nothing.
|
|
312
|
+
timedOut = true;
|
|
313
|
+
process.stderr.write("crb: no `nice` on PATH: maintenance's git runs at normal priority\n");
|
|
314
|
+
runGitFull(repoPath, args, opts).then(resolve, reject);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
226
317
|
fail(error.message);
|
|
227
318
|
});
|
|
228
319
|
child.on("close", (code) => {
|