clavarium 0.2.314-next.1 → 0.2.315-next.1
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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +5 -1
- package/server/gitpush.mjs +152 -51
- package/web/app.js +75 -32
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.315-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.315-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -59,6 +59,8 @@
|
|
|
59
59
|
* POST /api/updates/apply { version }: update to the version that is out (in the background)
|
|
60
60
|
* POST /api/updates/back { version }: go back to a release that is kept (in the background)
|
|
61
61
|
* GET /api/git/<name>/outgoing?target=<branch>&branch=<branch> what would go from the agent's branch, to that branch of the remote
|
|
62
|
+
* GET /api/git/<name>/known To send at once: what is known here, no remote asked, no repository read
|
|
63
|
+
* GET /api/git/<name>/outgoing-all To send: one fetch, one read, the branches that moved last reviewed
|
|
62
64
|
* GET /api/git/<name>/graph the branch diagram: branches and their last commits
|
|
63
65
|
* GET /api/git/<name>/commit?id=<sha> one commit, as a review shows it (&base=<sha>: the commits from base to it)
|
|
64
66
|
* POST /api/git/<name>/push {head, target?, sure?}: exactly that reviewed commit, to exactly that branch
|
|
@@ -381,10 +383,12 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
381
383
|
const answered = /^\/api\/conversations\/([^/]+)\/answerer\/log$/.exec(pathname);
|
|
382
384
|
if (answered && answerer) return send(200, answerer.log(decodeURIComponent(answered[1]))), true;
|
|
383
385
|
/* A repository: where its commits go, and what would go now. */
|
|
384
|
-
const repo = /^\/api\/git\/([a-z0-9-]{1,32})(\/outgoing|\/keep)?$/.exec(pathname);
|
|
386
|
+
const repo = /^\/api\/git\/([a-z0-9-]{1,32})(\/outgoing|\/outgoing-all|\/known|\/keep)?$/.exec(pathname);
|
|
385
387
|
const drawn = /^\/api\/git\/([a-z0-9-]{1,32})\/(graph|commit)$/.exec(pathname);
|
|
386
388
|
if (drawn && gitReview) return send(200, drawn[2] === 'graph' ? await gitReview.graph(drawn[1]) : await gitReview.commit(drawn[1], query.get('id'), query.get('base'))), true;
|
|
387
389
|
if (repo && repo[2] === '/keep' && gitKeeper) return send(200, gitKeeper.about(repo[1])), true;
|
|
390
|
+
if (repo && repo[2] === '/known' && gitReview) return send(200, await gitReview.known(repo[1])), true;
|
|
391
|
+
if (repo && repo[2] === '/outgoing-all' && gitReview) return send(200, await gitReview.outgoingAll(repo[1])), true;
|
|
388
392
|
if (repo && gitReview) return send(200, repo[2] ? await gitReview.outgoing(repo[1], { target: query.get('target') ?? undefined, branch: query.get('branch') ?? undefined }) : gitReview.settings(repo[1])), true;
|
|
389
393
|
const watched = /^\/api\/conversations\/([^/]+)\/signin$/.exec(pathname);
|
|
390
394
|
if (watched && signin) {
|
package/server/gitpush.mjs
CHANGED
|
@@ -40,6 +40,8 @@ export const UNCHANGED_MAX = 50;
|
|
|
40
40
|
/* A commit message is shown up to this many characters, and the cut is said. */
|
|
41
41
|
export const MESSAGE_MAX = 4000;
|
|
42
42
|
export const REVIEWS_KEPT = 20;
|
|
43
|
+
/* To send: besides the branch that moved last, how many others of a repository are looked at. */
|
|
44
|
+
export const BRANCHES_MORE = 7;
|
|
43
45
|
/* The branch diagram: so many commits, so many of the remote's branches. */
|
|
44
46
|
export const GRAPH_COMMITS = 40;
|
|
45
47
|
export const GRAPH_BRANCHES = 20;
|
|
@@ -69,6 +71,9 @@ export function escaped(text) {
|
|
|
69
71
|
(c) => (c === '\n' || c === '\t' ? c : `\\u{${c.codePointAt(0).toString(16)}}`));
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
/* A review's fields when there is nothing to show. */
|
|
75
|
+
const nothingOut = (remote) => ({ branches: [], agentBranches: [], dropped: [], targetExists: false, remoteTip: null, head: null, commits: [], count: 0, stat: '', diff: '', cut: false, guards: null, remote });
|
|
76
|
+
|
|
72
77
|
export class GitReview {
|
|
73
78
|
#store; #vault; #resources; #local; #access; #runner; #now; #listeners = []; #waivers = () => ({});
|
|
74
79
|
/* The refresh of each repository on its way: { run, waitMs }, by name. */
|
|
@@ -280,6 +285,8 @@ export class GitReview {
|
|
|
280
285
|
}
|
|
281
286
|
if (made) await this.#resources.shareOrigin(r.name).catch(() => {});
|
|
282
287
|
await this.#learnDefault(r, remote).catch(() => {});
|
|
288
|
+
/* When the reference was last brought up to date: the list shown at once says "as of" it. */
|
|
289
|
+
this.#store.put({ ...this.#record(r.name), name: r.name, fetchedAt: this.#now().toISOString() });
|
|
283
290
|
return said({ ok: true, message: 'Up to date with the remote.', rewritten, made, brought });
|
|
284
291
|
}
|
|
285
292
|
|
|
@@ -361,7 +368,7 @@ export class GitReview {
|
|
|
361
368
|
const asked = target === undefined || target === null || target === '' ? undefined : asBranch(target);
|
|
362
369
|
const pick = branch === undefined || branch === null || branch === '' ? undefined : asBranch(branch);
|
|
363
370
|
const remote = this.#remoteOf(r) ?? null;
|
|
364
|
-
const nothing =
|
|
371
|
+
const nothing = nothingOut(remote);
|
|
365
372
|
if (remote) {
|
|
366
373
|
const fresh = await this.refresh(r.name, { waitMs: REVIEW_WAIT_MS });
|
|
367
374
|
if (!fresh.ok) return { ...nothing, state: 'unreachable', branch: pick ?? null, target: asked ?? null, message: `The remote did not answer as expected: ${fresh.message}` };
|
|
@@ -372,61 +379,155 @@ export class GitReview {
|
|
|
372
379
|
throw error;
|
|
373
380
|
}
|
|
374
381
|
try {
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
const dropped = got.dropped.map((d) => ({ name: escaped(d.name), why: d.why }));
|
|
379
|
-
if (agentBranches.length === 0) return { ...nothing, dropped, state: 'empty', branch: null, target: asked ?? null, message: 'No branch of this repository can be sent: see the names that were not taken.' };
|
|
380
|
-
const chosen = pick ? agentBranches.find((b) => b.name === pick) : agentBranches[0];
|
|
382
|
+
const listed = this.#listed(r, got);
|
|
383
|
+
if (listed.agentBranches.length === 0) return { ...nothing, dropped: listed.dropped, state: 'empty', branch: null, target: asked ?? null, message: 'No branch of this repository can be sent: see the names that were not taken.' };
|
|
384
|
+
const chosen = pick ? listed.agentBranches.find((b) => b.name === pick) : listed.agentBranches[0];
|
|
381
385
|
if (!chosen) throw new Refusal(404, `The agent's repository has no branch ${pick}.`);
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
386
|
+
return await this.#look(r, got, listed, chosen, asked);
|
|
387
|
+
} finally { got.remove(); }
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/* TO SEND, A WHOLE REPOSITORY AT ONCE: one fetch (shared with any on
|
|
391
|
+
its way), ONE read of the agent's repository, then each of its
|
|
392
|
+
branches that moved last (up to 1 + `more`) compared in that same
|
|
393
|
+
workspace. The page asked one review per branch before, and each
|
|
394
|
+
read the whole repository again through the host program: the read
|
|
395
|
+
of the whole history, checked object by object, is what takes time,
|
|
396
|
+
not the comparison. { state: 'read' | 'empty' | 'unreachable',
|
|
397
|
+
message, remote, agentBranches, dropped, rows: [as outgoing()], more,
|
|
398
|
+
asOf }; `more`: how many branches were not looked at. A branch whose
|
|
399
|
+
comparison failed is a row { state: 'error', branch, message }. */
|
|
400
|
+
async outgoingAll(name, { more = BRANCHES_MORE } = {}) {
|
|
401
|
+
const r = this.#repository(name);
|
|
402
|
+
const remote = this.#remoteOf(r) ?? null;
|
|
403
|
+
const base = { remote, agentBranches: [], dropped: [], rows: [], more: 0, asOf: this.#now().toISOString() };
|
|
404
|
+
if (remote) {
|
|
405
|
+
const fresh = await this.refresh(r.name, { waitMs: REVIEW_WAIT_MS });
|
|
406
|
+
if (!fresh.ok) return { ...base, state: 'unreachable', message: `The remote did not answer as expected: ${fresh.message}` };
|
|
407
|
+
}
|
|
408
|
+
let got;
|
|
409
|
+
try { got = await this.#read(r); } catch (error) {
|
|
410
|
+
if (error instanceof GitFailure && error.kind === 'empty') return { ...base, state: 'empty', message: 'Nothing has been committed on a branch in this repository yet.' };
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
try {
|
|
414
|
+
const listed = this.#listed(r, got);
|
|
415
|
+
if (listed.agentBranches.length === 0) return { ...base, ...listed, state: 'empty', message: 'No branch of this repository can be sent: see the names that were not taken.' };
|
|
416
|
+
const chosen = listed.agentBranches.slice(0, 1 + Math.max(0, Math.floor(Number(more) || 0)));
|
|
417
|
+
const rows = [];
|
|
418
|
+
for (const b of chosen) {
|
|
419
|
+
try { rows.push(await this.#look(r, got, listed, b, undefined)); } catch (error) {
|
|
420
|
+
rows.push({ ...nothingOut(remote), state: 'error', branch: b.name, target: b.name, kind: error?.kind ?? null, message: error instanceof Refusal ? error.message : 'It could not be read.' });
|
|
416
421
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
const commitsText = n === null ? 'Commits (their number could not be counted)' : `${n} commit(s)`;
|
|
420
|
-
const message = state === 'up-to-date' ? `Everything committed here is already there, in ${to}.`
|
|
421
|
-
: state === 'diverged' ? `The remote's ${to} has ${behind ?? 'some'} commit(s) that this repository does not have: the tool must bring them in first (pull), then this can be sent.`
|
|
422
|
-
: !remoteTip ? (n !== 0 ? `${commitsText} would be sent to ${to}, a new branch on the remote.` : `${to} would be made on the remote, at a commit it already has: no new commit.`)
|
|
423
|
-
: `${commitsText} would be sent to ${to}.`;
|
|
424
|
-
if (state === 'ahead') this.#keep(r.name, { branch: chosen.name, head, target: to, remoteTip, count: n ?? undefined, confirm: shown.guards.confirm, at: asOf });
|
|
425
|
-
return { ...nothing, ...base0, ...shown, branches, targetExists: Boolean(remoteTip), remoteTip, state, message };
|
|
426
|
-
} finally { release(); }
|
|
422
|
+
}
|
|
423
|
+
return { ...base, ...listed, state: 'read', message: '', rows, more: listed.agentBranches.length - chosen.length, asOf: this.#now().toISOString() };
|
|
427
424
|
} finally { got.remove(); }
|
|
428
425
|
}
|
|
429
426
|
|
|
427
|
+
/* WHAT IS KNOWN HERE, AT ONCE: no remote asked, no repository read. The
|
|
428
|
+
agent's branches as the last read saw them, the remote's as the last
|
|
429
|
+
fetch left them in the reference, and for each branch the outcome of
|
|
430
|
+
its last review -- kept only while neither tip moved since. A branch
|
|
431
|
+
that moved is 'unknown' until the next review (its commits are in the
|
|
432
|
+
agent's machine: only a read brings them). { remote, readAt,
|
|
433
|
+
fetchedAt, branches, rows: [{ branch, head, movedAt, target,
|
|
434
|
+
remoteTip, targetExists, state, count, lookedAt }], more }. Nothing
|
|
435
|
+
here may be sent: Send reads and fetches again (send()). */
|
|
436
|
+
async known(name, { more = BRANCHES_MORE } = {}) {
|
|
437
|
+
const r = this.#repository(name);
|
|
438
|
+
const remote = this.#remoteOf(r) ?? null;
|
|
439
|
+
const record = this.#record(r.name);
|
|
440
|
+
const reference = this.#reference(r.name);
|
|
441
|
+
const remoteTips = remote && this.#resources.hasOrigin(r.name) ? await this.#tipsIn(reference).catch(() => new Map()) : new Map();
|
|
442
|
+
const all = Object.entries(record.tips ?? {}).map(([b, tip]) => ({ name: b, id: tip.id, movedAt: tip.movedAt ?? null }))
|
|
443
|
+
.sort((a, b) => String(b.movedAt).localeCompare(String(a.movedAt)) || a.name.localeCompare(b.name));
|
|
444
|
+
const chosen = all.slice(0, 1 + Math.max(0, Math.floor(Number(more) || 0)));
|
|
445
|
+
const rows = [];
|
|
446
|
+
for (const b of chosen) {
|
|
447
|
+
const last = record.looked?.[b.name];
|
|
448
|
+
const target = last?.target ?? b.name;
|
|
449
|
+
const remoteTip = remoteTips.get(target) ?? null;
|
|
450
|
+
const same = last && last.head === b.id && (last.remoteTip ?? null) === remoteTip;
|
|
451
|
+
let state = 'unknown';
|
|
452
|
+
if (!remote) state = 'no-remote';
|
|
453
|
+
else if (same) state = last.state;
|
|
454
|
+
/* Already on the remote's branch: seen in the reference alone. */
|
|
455
|
+
else if (remoteTip && (remoteTip === b.id || (await this.#has(reference, b.id) && await this.#isAncestor(reference, b.id, remoteTip)))) state = 'up-to-date';
|
|
456
|
+
rows.push({ branch: b.name, head: b.id, movedAt: b.movedAt, target, remoteTip, targetExists: Boolean(remoteTip), state, count: same ? last.count ?? null : state === 'up-to-date' ? 0 : null, lookedAt: last?.at ?? null });
|
|
457
|
+
}
|
|
458
|
+
return { remote, readAt: record.readAt ?? null, fetchedAt: record.fetchedAt ?? null, branches: [...remoteTips.keys()].sort().slice(0, BRANCHES_MAX), rows, more: all.length - chosen.length };
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/* The agent's branches of one read, the one that moved last first. */
|
|
462
|
+
#listed(r, got) {
|
|
463
|
+
const tips = this.tips(r.name);
|
|
464
|
+
const agentBranches = got.branches.map((b) => ({ name: b.name, id: b.id, movedAt: tips[b.name]?.movedAt ?? null }))
|
|
465
|
+
.sort((a, b) => String(b.movedAt).localeCompare(String(a.movedAt)) || a.name.localeCompare(b.name));
|
|
466
|
+
return { agentBranches, dropped: got.dropped.map((d) => ({ name: escaped(d.name), why: d.why })) };
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/* The outcome of a review, kept by branch for the list shown at once (known()). */
|
|
470
|
+
#remember(name, out, agentBranches) {
|
|
471
|
+
const record = this.#record(name);
|
|
472
|
+
const looked = {};
|
|
473
|
+
for (const b of agentBranches) if (record.looked?.[b.name]) looked[b.name] = record.looked[b.name];
|
|
474
|
+
looked[out.branch] = { head: out.head, target: out.target, remoteTip: out.remoteTip ?? null, state: out.state, count: out.count ?? null, at: out.asOf };
|
|
475
|
+
this.#store.put({ ...record, looked });
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/* One branch of a read, compared with the remote's: see outgoing(). */
|
|
479
|
+
async #look(r, got, { agentBranches, dropped }, chosen, asked) {
|
|
480
|
+
const remote = this.#remoteOf(r) ?? null;
|
|
481
|
+
const nothing = nothingOut(remote);
|
|
482
|
+
const ws = got.path;
|
|
483
|
+
const head = chosen.id;
|
|
484
|
+
const to = asked ?? chosen.name;
|
|
485
|
+
const asOf = this.#now().toISOString();
|
|
486
|
+
const base0 = { agentBranches, dropped, branch: chosen.name, target: to, head, remote, asOf };
|
|
487
|
+
if (!remote) {
|
|
488
|
+
const shown = await this.#compare(ws, { head, base: EMPTY_TREE, range: [head], negatives: [] });
|
|
489
|
+
return { ...nothing, ...base0, ...shown, state: 'no-remote', message: 'No address is set to send these commits to.' };
|
|
490
|
+
}
|
|
491
|
+
const reference = this.#reference(r.name);
|
|
492
|
+
const release = await this.#runner.lock(reference, REVIEW_WAIT_MS);
|
|
493
|
+
try {
|
|
494
|
+
this.#runner.borrow(ws, reference);
|
|
495
|
+
const remoteTips = await this.#tipsIn(reference);
|
|
496
|
+
const branches = [...remoteTips.keys()].sort().slice(0, BRANCHES_MAX);
|
|
497
|
+
const remoteTip = remoteTips.get(to) ?? null;
|
|
498
|
+
let shown; let behind = null; let inRemote = false; let containsRemote = true;
|
|
499
|
+
if (remoteTip) {
|
|
500
|
+
shown = await this.#compare(ws, { head, base: remoteTip, range: [head], negatives: [remoteTip] });
|
|
501
|
+
/* The state rests on ancestry, asked directly, never on a
|
|
502
|
+
count: a count that failed must not read as 0, "already
|
|
503
|
+
there", nor as "nothing behind". */
|
|
504
|
+
inRemote = await this.#ancestry(ws, head, remoteTip);
|
|
505
|
+
containsRemote = await this.#ancestry(ws, remoteTip, head);
|
|
506
|
+
const b = await this.#runner.in(ws, ['rev-list', '--count', '--end-of-options', remoteTip, `^${head}`], { deadlineMs: 120_000 });
|
|
507
|
+
const text = b.stdout.toString('latin1').trim();
|
|
508
|
+
behind = b.code === 0 && !b.killed && /^\d+$/.test(text) ? Number(text) : null;
|
|
509
|
+
} else {
|
|
510
|
+
/* A new branch: what would travel is what the remote has on
|
|
511
|
+
no branch at all; the changes are shown from where the
|
|
512
|
+
agent's branch left the remote's branch of its own name. */
|
|
513
|
+
const same = remoteTips.get(chosen.name);
|
|
514
|
+
const fork = same ? (await this.#runner.in(ws, ['merge-base', '--end-of-options', head, same])).stdout.toString('latin1').trim() : '';
|
|
515
|
+
shown = await this.#compare(ws, { head, base: isId(fork) ? fork : EMPTY_TREE, range: [head], negatives: [...remoteTips.values()] });
|
|
516
|
+
}
|
|
517
|
+
const state = !remoteTip ? 'ahead' : inRemote ? 'up-to-date' : !containsRemote ? 'diverged' : 'ahead';
|
|
518
|
+
const n = shown.count;
|
|
519
|
+
const commitsText = n === null ? 'Commits (their number could not be counted)' : `${n} commit(s)`;
|
|
520
|
+
const message = state === 'up-to-date' ? `Everything committed here is already there, in ${to}.`
|
|
521
|
+
: state === 'diverged' ? `The remote's ${to} has ${behind ?? 'some'} commit(s) that this repository does not have: the tool must bring them in first (pull), then this can be sent.`
|
|
522
|
+
: !remoteTip ? (n !== 0 ? `${commitsText} would be sent to ${to}, a new branch on the remote.` : `${to} would be made on the remote, at a commit it already has: no new commit.`)
|
|
523
|
+
: `${commitsText} would be sent to ${to}.`;
|
|
524
|
+
if (state === 'ahead') this.#keep(r.name, { branch: chosen.name, head, target: to, remoteTip, count: n ?? undefined, confirm: shown.guards.confirm, at: asOf });
|
|
525
|
+
const out = { ...nothing, ...base0, ...shown, branches, targetExists: Boolean(remoteTip), remoteTip, state, message };
|
|
526
|
+
this.#remember(r.name, out, agentBranches);
|
|
527
|
+
return out;
|
|
528
|
+
} finally { release(); }
|
|
529
|
+
}
|
|
530
|
+
|
|
430
531
|
/* The workspace of one read, with the remote's history lent to it when
|
|
431
532
|
there is one, for `work(ws, remoteTips)`; deleted after. */
|
|
432
533
|
async #withRead(r, work) {
|
package/web/app.js
CHANGED
|
@@ -4050,9 +4050,13 @@
|
|
|
4050
4050
|
of them all; one button sends them one after the other, each by the same route as its own review (the same commit,
|
|
4051
4051
|
the same target, the same guards). One refused does not hold the
|
|
4052
4052
|
others back: each says what became of it. */
|
|
4053
|
-
const STATE_SAID = { 'up-to-date': 'up to date', diverged: 'behind: its agent must pull first', 'no-remote': 'no remote', unreachable: 'remote not answering', empty: 'empty' };
|
|
4054
|
-
/* How many
|
|
4055
|
-
const
|
|
4053
|
+
const STATE_SAID = { unknown: 'changed: reading…', 'up-to-date': 'up to date', diverged: 'behind: its agent must pull first', 'no-remote': 'no remote', unreachable: 'remote not answering', empty: 'empty' };
|
|
4054
|
+
/* How many repositories are brought up to date with their remote at once, in the background. */
|
|
4055
|
+
const TS_PARALLEL = 3;
|
|
4056
|
+
/* `work(item)` for each, `n` at a time. */
|
|
4057
|
+
const inTurns = async (items, n, work) => { let i = 0; await Promise.all(Array.from({ length: Math.min(n, items.length) }, async () => { while (i < items.length) await work(items[i++]); })); };
|
|
4058
|
+
/* When a known row was true: the time today, else the day. */
|
|
4059
|
+
const asOfText = (at) => { const d = new Date(at); if (!at || Number.isNaN(d.getTime())) return 'not read yet'; return `as of ${d.toDateString() === new Date().toDateString() ? d.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : d.toLocaleDateString()}`; };
|
|
4056
4060
|
/* What a row is, for the filter: a branch the remote has and that is ahead of it, a branch it does not have, nothing to send. */
|
|
4057
4061
|
const kindOfRow = (out) => (out?.state !== 'ahead' ? 'none' : out.targetExists === false ? 'new' : 'update');
|
|
4058
4062
|
/* A branch that could not be read is not "nothing to send": it stays listed, under every filter, with why. */
|
|
@@ -4077,16 +4081,21 @@
|
|
|
4077
4081
|
let filter = 'update';
|
|
4078
4082
|
let sending = false; let checking = false;
|
|
4079
4083
|
let sure = '';
|
|
4080
|
-
let reposDone = 0; let reading = true;
|
|
4081
|
-
|
|
4082
|
-
const
|
|
4084
|
+
let reposDone = 0; let reading = true; const notLookedBy = new Map();
|
|
4085
|
+
/* Known rows not read yet, or whose branch moved since, stay in sight until their read says. */
|
|
4086
|
+
const shownRow = (r) => filter === 'all' || kindOfRow(r.out) === filter || unread(r.out) || (r.known && (!r.out || r.out.state === 'unknown'));
|
|
4087
|
+
const picked = () => rows.filter((r) => r.picked && !r.known && r.out?.state === 'ahead' && shownRow(r));
|
|
4083
4088
|
const label = (r) => (rows.filter((x) => x.name === r.name).length > 1 ? `${r.name} (${r.branch})` : r.name);
|
|
4084
4089
|
async function look(r) {
|
|
4085
4090
|
const query = new URLSearchParams();
|
|
4086
4091
|
if (r.branch) query.set('branch', r.branch);
|
|
4087
4092
|
if (r.target) query.set('target', r.target);
|
|
4088
4093
|
const [out, keep] = await Promise.all([readOrSay(`/git/${r.name}/outgoing${query.size ? `?${query}` : ''}`), r.keep ? r.keep : getJson(`/git/${r.name}/keep`, null)]);
|
|
4089
|
-
r
|
|
4094
|
+
apply(r, out, keep);
|
|
4095
|
+
}
|
|
4096
|
+
/* A row's fresh review: what the server knows of its checks comes with it. */
|
|
4097
|
+
function apply(r, out, keep) {
|
|
4098
|
+
r.out = out; r.keep = keep; r.known = false; r.branch = out.branch ?? r.branch; r.target = out.target ?? r.target; r.check = null;
|
|
4090
4099
|
/* What the server knows of this very commit and target: a check still running is followed again; the last
|
|
4091
4100
|
one that ran is shown with its age (left and come back, even the next day: nothing run again for nothing). */
|
|
4092
4101
|
if (out.state === 'ahead' && out.head) {
|
|
@@ -4122,10 +4131,11 @@
|
|
|
4122
4131
|
/* By repositories: how many there are is known from the start, how many branches each has is not. */
|
|
4123
4132
|
meter.hidden = !reading; meterFill.style.width = `${names.length ? Math.round((reposDone / names.length) * 100) : 100}%`;
|
|
4124
4133
|
progress.toggleAttribute('data-busy', reading);
|
|
4125
|
-
if (reading) { progress.dataset.tone = 'warn'; progress.textContent = `
|
|
4134
|
+
if (reading) { progress.dataset.tone = 'warn'; progress.textContent = `Checking with the remotes: ${reposDone} of ${names.length}`; }
|
|
4126
4135
|
else {
|
|
4127
4136
|
const failed = rows.filter((r) => unread(r.out)).length;
|
|
4128
|
-
const
|
|
4137
|
+
const notLooked = [...notLookedBy.values()].reduce((n, x) => n + x, 0);
|
|
4138
|
+
const tail = `${failed ? ` · ${failed} not read` : ' · all read'}${notLooked ? ` · ${notLooked} older branch${notLooked === 1 ? '' : 'es'} not looked at` : ''}`;
|
|
4129
4139
|
progress.dataset.tone = failed ? 'warn' : count('update') + count('new') ? 'ok' : '';
|
|
4130
4140
|
progress.textContent = count('update') + count('new') ? `${count('update')} to update · ${count('new')} new${tail}` : `Nothing to send${tail}`;
|
|
4131
4141
|
}
|
|
@@ -4167,15 +4177,17 @@
|
|
|
4167
4177
|
const out = r.out;
|
|
4168
4178
|
const ahead = out?.state === 'ahead';
|
|
4169
4179
|
row.classList.toggle('off', !ahead);
|
|
4170
|
-
const tick = el('input'); tick.type = 'checkbox'; tick.checked = r.picked; tick.disabled = !ahead || sending || checking; tick.setAttribute('aria-label', `Send ${label(r)}`);
|
|
4180
|
+
const tick = el('input'); tick.type = 'checkbox'; tick.checked = r.picked; tick.disabled = !ahead || r.known || sending || checking; tick.setAttribute('aria-label', `Send ${label(r)}`);
|
|
4171
4181
|
tick.addEventListener('change', () => { r.picked = tick.checked; sure = ''; paint(); if (!review.hidden) paintReview(); });
|
|
4172
|
-
const who = el('div', 'ts-who'); who.append(el('b', '', r.name), el('small', 'hint', out?.remote ? hostOf(out.remote) : out ? 'no remote' : ''));
|
|
4182
|
+
const who = el('div', 'ts-who'); who.append(el('b', '', r.name), el('small', 'hint', `${out?.remote ? hostOf(out.remote) : out ? 'no remote' : ''}${r.known ? ` · ${asOfText(r.asOf)}` : ''}`));
|
|
4173
4183
|
const way = el('div', 'ts-way');
|
|
4174
4184
|
/* Its own name even when it could not be read: which branch is missing is said. */
|
|
4175
4185
|
const named = out?.branch ?? (unread(out) ? r.branch : '');
|
|
4176
4186
|
if (named) {
|
|
4177
4187
|
const code = el('code', 'ts-branch', named); code.title = named; way.append(code);
|
|
4178
|
-
|
|
4188
|
+
/* Known only: where it goes is said; it is chosen once the row is read. */
|
|
4189
|
+
if (r.known && out.target) way.append(el('span', 'ts-arrow', '→'), el('code', 'ts-branch', out.target));
|
|
4190
|
+
else if (['ahead', 'up-to-date', 'diverged'].includes(out.state) && out.target) {
|
|
4179
4191
|
way.append(el('span', 'ts-arrow', '→'));
|
|
4180
4192
|
const to = el('select'); to.setAttribute('aria-label', `Where ${label(r)} goes`); to.disabled = sending || checking;
|
|
4181
4193
|
const names2 = [...(out.branches ?? [])]; if (!names2.includes(out.target)) names2.unshift(out.target);
|
|
@@ -4187,6 +4199,7 @@
|
|
|
4187
4199
|
}
|
|
4188
4200
|
const size = el('div', 'ts-size');
|
|
4189
4201
|
if (!out) size.append(el('span', 'hint busy', 'Reading...'));
|
|
4202
|
+
else if (ahead && r.known) size.append(el('span', '', out.targetExists === false ? 'new branch' : out.count === null || out.count === undefined ? 'some commits' : `${out.count} commit${out.count === 1 ? '' : 's'}`));
|
|
4190
4203
|
else if (ahead) {
|
|
4191
4204
|
const files = diffFiles(out.diff);
|
|
4192
4205
|
/* A branch the remote does not have: "new", not a count against a branch that is not there. */
|
|
@@ -4197,6 +4210,7 @@
|
|
|
4197
4210
|
if (r.sending) { const s2 = el('span', 'ts-running'); s2.append(el('span', 'warn', 'Sending…')); state.append(s2); }
|
|
4198
4211
|
else if (r.sent) state.append(el('b', r.sent.ok ? 'ok' : 'bad', r.sent.ok ? r.sent.text : '✗ Not sent'));
|
|
4199
4212
|
else if (!out) state.append('');
|
|
4213
|
+
else if (r.known && out.state !== 'unknown') state.append(el('span', 'hint busy', ahead ? 'checking…' : `${STATE_SAID[out.state] ?? out.state} · checking…`));
|
|
4200
4214
|
else if (!ahead) state.append(el('span', out.state === 'diverged' || out.state === 'unreachable' || out.state === 'error' ? 'bad' : 'hint', STATE_SAID[out.state] ?? out.message ?? out.state));
|
|
4201
4215
|
else if (!r.check) state.append(el('span', 'hint', r.picked ? 'to check' : ''));
|
|
4202
4216
|
else if (r.check.status === 'running') {
|
|
@@ -4369,32 +4383,61 @@
|
|
|
4369
4383
|
said.className = `status-line ts-said ${ok === p.length ? 'ok' : 'bad'}`; said.dataset.tone = ok === p.length ? 'ok' : 'bad'; said.hidden = false;
|
|
4370
4384
|
if (reviewStep) nav.drop(reviewStep);
|
|
4371
4385
|
/* What is left to send, read again; what became of each stays said. */
|
|
4372
|
-
|
|
4373
|
-
await Promise.all(rows.map((r) => look(r)));
|
|
4386
|
+
await inTurns([...new Set(p.map((r) => r.name))], TS_PARALLEL, (name) => readRepo(name));
|
|
4374
4387
|
/* What went is unticked: nothing is offered again for what is done. */
|
|
4375
|
-
for (const r of rows)
|
|
4388
|
+
for (const r of rows) if (r.sent?.ok) r.picked = false;
|
|
4376
4389
|
paint();
|
|
4377
4390
|
said.scrollIntoView({ block: 'nearest' });
|
|
4378
4391
|
});
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
await
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4392
|
+
/* ONE REPOSITORY READ AFRESH (one fetch, one read, its branches that moved last reviewed): its rows replaced
|
|
4393
|
+
where they were, each keeping what was said or ticked of the same commit. A branch with nothing to send is
|
|
4394
|
+
listed only when it is the one that moved last (or what became of its sending is said); one that could not be
|
|
4395
|
+
read always, with why. */
|
|
4396
|
+
async function readRepo(name) {
|
|
4397
|
+
const [all, keep] = await Promise.all([readOrSay(`/git/${name}/outgoing-all`), getJson(`/git/${name}/keep`, null)]);
|
|
4398
|
+
const before = rows.filter((x) => x.name === name);
|
|
4399
|
+
const at = rows.findIndex((x) => x.name === name);
|
|
4400
|
+
let fresh;
|
|
4401
|
+
if (Array.isArray(all.rows) && all.rows.length) {
|
|
4402
|
+
fresh = all.rows.filter((out, i) => i === 0 || out.state === 'ahead' || unread(out) || before.some((x) => x.branch === out.branch && x.sent)).map((out) => {
|
|
4403
|
+
const was = before.find((x) => x.branch === out.branch);
|
|
4404
|
+
const r = { name, out: null, keep, branch: out.branch, target: '', picked: false, check: null, sent: was?.sent ?? null, movedAt: (all.agentBranches ?? []).find((b) => b.name === out.branch)?.movedAt ?? null };
|
|
4405
|
+
apply(r, out, keep);
|
|
4406
|
+
/* Ticked by one rule for every row: a branch of the remote to update is ticked; a new one is not. */
|
|
4407
|
+
r.picked = was && !was.known && was.out?.head === out.head ? was.picked && out.state === 'ahead' : kindOfRow(out) === 'update';
|
|
4408
|
+
if (was?.check && was.out?.head === out.head && !r.check) r.check = was.check;
|
|
4409
|
+
return r;
|
|
4410
|
+
});
|
|
4411
|
+
notLookedBy.set(name, all.more ?? 0);
|
|
4412
|
+
} else {
|
|
4413
|
+
/* Not read (the remote did not answer, the read failed) or nothing in it: each known branch says so. */
|
|
4414
|
+
const out = { state: all.state ?? 'error', message: all.message, remote: all.remote ?? before[0]?.out?.remote ?? null };
|
|
4415
|
+
const known = before.filter((x) => x.branch);
|
|
4416
|
+
fresh = (known.length && unread(out) ? known : [{ name, branch: '' }]).map((x) => ({ name, out: { ...out, branch: x.branch || null }, keep, branch: x.branch, target: '', picked: false, check: null, sent: x.sent ?? null, known: false }));
|
|
4417
|
+
}
|
|
4418
|
+
rows.splice(at < 0 ? rows.length : at, before.length, ...fresh);
|
|
4388
4419
|
paint();
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4420
|
+
}
|
|
4421
|
+
/* AT ONCE: what is known here (the agent's branches as last read, the remote's as last fetched, the last review
|
|
4422
|
+
of each), no remote asked, no repository read; each row says as of when. Not sendable as it is. */
|
|
4423
|
+
paint();
|
|
4424
|
+
const known = await Promise.all(names.map(async (name) => [name, await getJson(`/git/${name}/known`, null)]));
|
|
4425
|
+
for (const [name, k] of known) {
|
|
4426
|
+
const list = k?.rows ?? [];
|
|
4427
|
+
if (list.length === 0) rows.push({ name, out: null, keep: null, branch: '', target: '', picked: false, check: null, sent: null, known: true });
|
|
4428
|
+
for (const x of list) {
|
|
4429
|
+
const out = { state: x.state, branch: x.branch, target: x.target, targetExists: x.targetExists, count: x.count, head: x.head, remote: k.remote, branches: k.branches };
|
|
4430
|
+
/* As the full read lists them: the one that moved last, then those with something to send. */
|
|
4431
|
+
if (x !== list[0] && x.state !== 'ahead' && x.state !== 'unknown') continue;
|
|
4432
|
+
rows.push({ name, out, keep: null, branch: x.branch, target: x.target, picked: false, check: null, sent: null, movedAt: x.movedAt, known: true, asOf: x.state === 'unknown' ? k.readAt : (k.fetchedAt ?? x.lookedAt) });
|
|
4433
|
+
}
|
|
4434
|
+
}
|
|
4435
|
+
paint();
|
|
4436
|
+
/* THEN, IN THE BACKGROUND: each repository brought up to date with its remote and read, a few at a time; its rows replaced as it comes. */
|
|
4437
|
+
await inTurns(names, TS_PARALLEL, async (name) => {
|
|
4438
|
+
try { await readRepo(name); } catch { /* said by its rows */ }
|
|
4396
4439
|
reposDone++; paint();
|
|
4397
|
-
})
|
|
4440
|
+
});
|
|
4398
4441
|
reading = false;
|
|
4399
4442
|
paint();
|
|
4400
4443
|
}
|