clavarium 0.2.300-next.1 → 0.2.301-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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.300-next.1",
3
+ "version": "0.2.301-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.300-next.1",
9
+ "version": "0.2.301-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.300-next.1",
3
+ "version": "0.2.301-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -71,6 +71,8 @@ export function escaped(text) {
71
71
 
72
72
  export class GitReview {
73
73
  #store; #vault; #resources; #local; #access; #runner; #now; #listeners = []; #waivers = () => ({});
74
+ /* The refresh of each repository on its way: { run, waitMs }, by name. */
75
+ #refreshing = new Map();
74
76
 
75
77
  /* `localRemotes`: lets a remote be a directory of this machine. For tests only.
76
78
  `runner`: the git runner (gitrunner.mjs); its reads go through the host program. */
@@ -204,8 +206,22 @@ export class GitReview {
204
206
  The only writer of the reference. */
205
207
  async refresh(name, { waitMs = SEND_WAIT_MS } = {}) {
206
208
  const r = this.#repository(name);
207
- const release = await this.#runner.lock(this.#reference(r.name), waitMs);
208
- try { return await this.#refreshLocked(r); } finally { release(); }
209
+ /* One on its way already, that waits at least as long as this one
210
+ would: its fetch is shared, not made again behind it. A page that
211
+ reviews several branches of a repository at once (To send) would
212
+ otherwise line up one fetch per branch behind the reference's lock,
213
+ and the last ones be refused as busy -- and drop out of the list. */
214
+ const going = this.#refreshing.get(r.name);
215
+ if (going && going.waitMs >= waitMs) return going.run;
216
+ const run = (async () => {
217
+ const release = await this.#runner.lock(this.#reference(r.name), waitMs);
218
+ try { return await this.#refreshLocked(r); } finally { release(); }
219
+ })();
220
+ const entry = { run, waitMs };
221
+ this.#refreshing.set(r.name, entry);
222
+ const done = () => { if (this.#refreshing.get(r.name) === entry) this.#refreshing.delete(r.name); };
223
+ run.then(done, done);
224
+ return run;
209
225
  }
210
226
  /* `ours`: { branch, head } just pushed from here: what it brings back is not news from the remote. */
211
227
  async #refreshLocked(r, ours = null) {
package/web/app.js CHANGED
@@ -3554,7 +3554,8 @@
3554
3554
  const r = await fetch(`${API}${path}`);
3555
3555
  const j = await r.json().catch(() => ({}));
3556
3556
  if (r.ok) return j;
3557
- if (!(r.status === 503 && j.down === true)) return { state: 'error', message: j.error || 'It could not be read.' };
3557
+ /* Down for a moment, or its repository busy (another read holds it): asked again. */
3558
+ if (!(r.status === 503 && (j.down === true || j.kind === 'busy'))) return { state: 'error', message: j.error || 'It could not be read.' };
3558
3559
  } catch { return { state: 'error', message: 'It could not be read.' }; }
3559
3560
  await new Promise((ok) => setTimeout(ok, 1500 * (i + 1)));
3560
3561
  }
@@ -3974,6 +3975,8 @@
3974
3975
  const BRANCHES_MORE = 7;
3975
3976
  /* 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. */
3976
3977
  const kindOfRow = (out) => (out?.state !== 'ahead' ? 'none' : out.targetExists === false ? 'new' : 'update');
3978
+ /* A branch that could not be read is not "nothing to send": it stays listed, under every filter, with why. */
3979
+ const unread = (out) => out?.state === 'error' || out?.state === 'unreachable';
3977
3980
  const TS_FILTERS = [['update', 'To update'], ['new', 'New branches'], ['all', 'All']];
3978
3981
  /* Three steps: every branch read (said as it goes, nothing checked yet); filtered and ticked; the checks of what is
3979
3982
  ticked, on a click; then Send. */
@@ -3995,7 +3998,7 @@
3995
3998
  let sending = false; let checking = false;
3996
3999
  let sure = '';
3997
4000
  let reposDone = 0; let reading = true;
3998
- const shownRow = (r) => filter === 'all' || kindOfRow(r.out) === filter;
4001
+ const shownRow = (r) => filter === 'all' || kindOfRow(r.out) === filter || unread(r.out);
3999
4002
  const picked = () => rows.filter((r) => r.picked && r.out?.state === 'ahead' && shownRow(r));
4000
4003
  const label = (r) => (rows.filter((x) => x.name === r.name).length > 1 ? `${r.name} (${r.branch})` : r.name);
4001
4004
  async function look(r) {
@@ -4040,7 +4043,12 @@
4040
4043
  meter.hidden = !reading; meterFill.style.width = `${names.length ? Math.round((reposDone / names.length) * 100) : 100}%`;
4041
4044
  progress.toggleAttribute('data-busy', reading);
4042
4045
  if (reading) { progress.dataset.tone = 'warn'; progress.textContent = `Reading the repositories: ${reposDone} of ${names.length}${rows.length ? ` · ${rows.length} branch${rows.length === 1 ? '' : 'es'} found` : ''}`; }
4043
- else { progress.dataset.tone = count('update') + count('new') ? 'ok' : ''; progress.textContent = count('update') + count('new') ? `${count('update')} to update · ${count('new')} new · all read` : 'Nothing to send · all read'; }
4046
+ else {
4047
+ const failed = rows.filter((r) => unread(r.out)).length;
4048
+ const tail = failed ? ` · ${failed} not read` : ' · all read';
4049
+ progress.dataset.tone = failed ? 'warn' : count('update') + count('new') ? 'ok' : '';
4050
+ progress.textContent = count('update') + count('new') ? `${count('update')} to update · ${count('new')} new${tail}` : `Nothing to send${tail}`;
4051
+ }
4044
4052
  filters.replaceChildren(...TS_FILTERS.map(([key, word]) => {
4045
4053
  const n = key === 'all' ? rows.length : count(key);
4046
4054
  const b = el('button', '', `${word} ${n}`); b.type = 'button'; b.dataset.filter = key; b.setAttribute('aria-pressed', String(filter === key));
@@ -4083,8 +4091,10 @@
4083
4091
  tick.addEventListener('change', () => { r.picked = tick.checked; sure = ''; paint(); if (!review.hidden) paintReview(); });
4084
4092
  const who = el('div', 'ts-who'); who.append(el('b', '', r.name), el('small', 'hint', out?.remote ? hostOf(out.remote) : out ? 'no remote' : ''));
4085
4093
  const way = el('div', 'ts-way');
4086
- if (out?.branch) {
4087
- const code = el('code', 'ts-branch', out.branch); code.title = out.branch; way.append(code);
4094
+ /* Its own name even when it could not be read: which branch is missing is said. */
4095
+ const named = out?.branch ?? (unread(out) ? r.branch : '');
4096
+ if (named) {
4097
+ const code = el('code', 'ts-branch', named); code.title = named; way.append(code);
4088
4098
  if (['ahead', 'up-to-date', 'diverged'].includes(out.state) && out.target) {
4089
4099
  way.append(el('span', 'ts-arrow', '→'));
4090
4100
  const to = el('select'); to.setAttribute('aria-label', `Where ${label(r)} goes`); to.disabled = sending || checking;
@@ -4300,7 +4310,7 @@
4300
4310
  const r = { name, out: null, keep: first.keep, branch: b.name, target: '', picked: false, check: null, sent: null, movedAt: b.movedAt };
4301
4311
  await look(r);
4302
4312
  /* Ticked by one rule for every row: a branch of the remote to update is ticked; a new one is not. */
4303
- if (r.out?.state === 'ahead') { r.picked = kindOfRow(r.out) === 'update'; rows.splice(rows.findLastIndex((x) => x.name === name) + 1, 0, r); }
4313
+ if (r.out?.state === 'ahead' || unread(r.out)) { r.picked = kindOfRow(r.out) === 'update'; rows.splice(rows.findLastIndex((x) => x.name === name) + 1, 0, r); }
4304
4314
  paint();
4305
4315
  }));
4306
4316
  reposDone++; paint();