Lines 8–21 at 318 (were 8–19 at 2)
88import type { Env, Output } from "./commands.ts"; 99import { findRoot, readConfig } from "./config.ts"; 1010import { relativeTo } from "./folder.ts"; 11+import { type GitOrigin, gitOrigin, issueLinks } from "./git-origin.ts"; 12+import { byWhom, type TrailStep, type WhyAnswer } from "./history-answers.ts"; 1214function open(env: Env): { root: string; api: Api; agent: string } { 1315 const root = findRoot(env.cwd); 1416 if (root === undefined) 15− throw new UsageError(`${env.cwd} is not in an abso folder (no .avcs/config.json here or above)`);
16− const config = readConfig(root, env.env);
17+ throw new UsageError(`${env.cwd} is not in an abso folder (no .abso/config.json here or above)`); 18+ const config = readConfig(root, env.env, env.tokenFile === true); 1719 return { root, api: new Api(config), agent: config.agent }; Lines 48–87 at 318 (were 46–54 at 2)
4850function published(p: Publish | null): string { 49− return p === null ? "not published" : `version ${p.version} by ${p.agent} (${when(p.time)}): "${p.message}"`;
51+ return p === null ? "not pushed" : `version ${p.version} by ${byWhom(p)} (${when(p.time)}): "${p.message}"`; 54+/** published, with an imported push's git lines taken off its message (gitLines says them). */ 55+function pushed(p: Publish | null, issues: string | undefined): string { 56+ const origin = p ? gitOrigin(p, issues) : undefined; 57+ return p && origin ? published({ ...p, message: origin.message }) : published(p); 60+function gitLines(o: GitOrigin): string[] { 61+ return [` From git: commit ${o.commit}${o.author ? ` by ${o.author}` : ""}${o.time ? `, ${o.time}` : ""}.`]; 64+/** "1 formatting change and 2 moves": what why skipped. */ 65+function skippedKinds(steps: readonly TrailStep[]): string { 66+ const moves = steps.filter((s) => s.movedFrom !== undefined).length; 67+ const formatting = steps.length - moves; 69+ ...(formatting > 0 ? [`${formatting} formatting change${formatting === 1 ? "" : "s"}`] : []), 70+ ...(moves > 0 ? [`${moves} move${moves === 1 ? "" : "s"}`] : []), 74+/** A trail step in a few words: its version (or that it isn't pushed), who, and the first line of why. */ 75+function stepName(s: TrailStep, long = false): string { 76+ const first = (s.publish ? (gitOrigin(s.publish)?.message ?? s.publish.message) : s.message).split("\n")[0]!; 77+ const subject = first.length > 100 ? `${first.slice(0, 97).trimEnd()}...` : first; 78+ const where = s.publish === null ? "not pushed" : `version ${s.publish.version}`; 79+ const who = s.publish ? byWhom(s.publish) : s.author; 81+ ? `${where} by ${who} (${when(s.publish?.time ?? s.time)}): "${subject}"` 82+ : `${where} (${who}, "${subject}")`; 5285export async function runBlame(args: Parsed, env: Env): Promise<Output> { 5386 if (args.positionals.length !== 1) 5487 throw new UsageError("blame takes one file: abso blame <file> [--from <n>] [--to <n>]"); Lines 104–114 at 318 (were 71–77 at 2)
71104 for (const a of b.atoms) { 72105 if (a.publish === null) continue; 73106 const own = a.message && a.message !== a.publish.message ? ` (the change itself: "${a.message}")` : ""; 74− const line = ` v${a.publish.version} by ${a.publish.agent}, ${when(a.publish.time)}: ${a.publish.message}${own}`;
107+ const origin = gitOrigin(a.publish); 108+ const message = origin 109+ ? `${origin.message.split("\n")[0]} (from git commit ${origin.commit.slice(0, 12)}${origin.author ? ` by ${origin.author}` : ""})` 110+ : a.publish.message; 111+ const line = ` v${a.publish.version} by ${byWhom(a.publish)}, ${when(a.publish.time)}: ${message}${own}`; 75112 if (!versions.has(a.publish.version) || own) versions.set(a.publish.version, line); Lines 127–135 at 318 (were 90–98 at 2)
91128 (l) => ` ${String(l.n).padStart(digits)} ${tag(l).padEnd(tagWidth)} ${l.author.padEnd(width)} ${l.text}`, 93− ...(unpublished ? ["", "* not published yet: your own unpublished change."] : []),
130+ ...(unpublished ? ["", "* not pushed yet: your own unpushed change."] : []), 95− "Publishes:",
96133 ...[...versions].sort(([x], [y]) => x - y).map(([, line]) => line), 98135 return { text: lines.join("\n"), json: { ...b } }; Lines 148–217 at 318 (were 111–127 at 2)
111148 throw new UsageError("why takes a file and a line: abso why <file>:<line>"); 112149 const { root, api, agent } = open(env); 113150 const file = fileArg(root, env.cwd, typed); 114− const w = await api.why(file, lineNumber(raw, "the line")!, viewOf(args, agent));
151+ const rawAt = str(args, "at"); 152+ if (rawAt !== undefined && !/^\d+$/.test(rawAt)) 153+ throw new UsageError(`--at is a version number (got ${JSON.stringify(rawAt)})`); 154+ const at = rawAt === undefined ? undefined : Number(rawAt); 155+ const view = viewOf(args, agent); 156+ if (at !== undefined && "agent" in view) 157+ throw new UsageError("--mine reads your view as it is now; it takes no --at"); 158+ const w = await api.why(file, lineNumber(raw, "the line")!, view, at); 159+ if (at !== undefined && w.version !== at) 160+ throw new UsageError(`this server doesn't read why at a version yet; abso blame ${w.file} --version ${at} does`); 161+ return { text: whyText(w, { at, all: bool(args, "all") }), json: { ...w } }; 165+ * What abso why prints for an answer. The line's changes (abso-core issue 166+ * 20): the newest one that changed what it does leads, past formatting-only 167+ * ones, unless `all`. 169+export function whyText(w: WhyAnswer, { at, all = false }: { at?: number; all?: boolean } = {}): string { 170+ const trail = w.trail ?? []; 171+ const lead = (all ? trail[0] : trail.find((s) => !s.formatting)) ?? trail[0]; 172+ const leadAt = lead === undefined ? 0 : trail.indexOf(lead); 173+ const skipped = trail.slice(0, leadAt); 174+ const earlier = trail.slice(leadAt + 1).filter((s) => all || !s.formatting); 175+ const origin = lead?.publish ? gitOrigin(lead.publish, w.gitIssues) : undefined; 116− `${w.file} line ${w.line}: ${w.text}`,
117− `Written by ${w.change.author} (${when(w.change.time)}), published in ${published(w.publish)}.`,
118− ...(w.change.message ? [`The change says: "${w.change.message}"`] : []),
177+ `${w.file} line ${w.line}${at !== undefined ? ` at version ${at}` : ""}: ${w.text}`, 178+ ...(lead === undefined || leadAt === 0 179+ ? [`Written by ${w.change.author} (${when(w.change.time)}), pushed in ${pushed(w.publish, w.gitIssues)}.`] 181+ `Written by ${lead.author} (${when(lead.time)}), pushed in ${pushed(lead.publish, w.gitIssues)}.`, 182+ ...(lead.text.trim() !== w.text.trim() ? [` It read: ${lead.text.trim()}`] : []), 184+ ...(origin ? gitLines(origin) : []), 185+ ...issueLinks(`${w.text}\n${origin?.message ?? ""}`, origin?.issues).map((l) => ` ${l}`), 186+ ...(skipped.length > 0 188+ `Skipped ${skippedKinds(skipped)} since: ${skipped.map((s) => `${stepName(s)}${s.movedFrom ? `, moved from ${s.movedFrom}` : ""}`).join("; ")}. abso why --all shows ${skipped.length === 1 ? "it" : "them"}.`, 191+ ...(earlier.length > 0 193+ "Earlier changes, newest first:", 194+ ...earlier.flatMap((s, i) => { 195+ const newer = i === 0 ? lead! : earlier[i - 1]!; 196+ const o = s.publish ? gitOrigin(s.publish, w.gitIssues) : undefined; 198+ ` ${stepName(s, true)}${s.movedFrom ? ` (moved from ${s.movedFrom})` : s.formatting ? " (formatting only)" : ""}${o ? `, from git commit ${o.commit.slice(0, 12)}${o.author ? ` by ${o.author}` : ""}` : ""}`, 199+ ...(s.text.trim() !== newer.text.trim() ? [` It read: ${s.text.trim()}`] : []), 204+ ...(w.trailMore ? [" (it goes back further than why follows)"] : []), 205+ ...(w.change.message && leadAt === 0 ? [`The change says: "${w.change.message}"`] : []), 119206 ...(w.settled.length > 0 121− "It settled a collision between:",
209+ ? `It was kept when ${w.settledBy.author} settled a collision between:` 210+ : "It settled a collision between:", 123212 (s) => ` ${s.author}, ${published(s.publish)}${s.message ? ` (the change: "${s.message}")` : ""}`, 214+ ...(w.held ? [` ${w.held.agent}, a held push: "${w.held.message}"`] : []), 127217 ...(w.reasons.length > 0 Lines 227–233 at 318 (were 137–143 at 2)
140− return { text: lines.join("\n"), json: { ...w } };
230+ return lines.join("\n"); 143233function ranges(rs: readonly [number, number][]): string { Lines 245–251 at 318 (were 155–161 at 2)
157247 * abso who <file...>: for each file, who last changed it, who has unpublished 158− * changes in it, and whose starting note names it (#37, Artist 1: "is anyone
248+ * changes in it, and whose starting note names it (#37: "is anyone 159249 * in here right now?" before touching someone's file). 161251export async function runWho(args: Parsed, env: Env): Promise<Output> { Lines 262–275 at 318 (were 172–185 at 2)
175− ? ` last changed in version ${last.version} by ${last.agent}, ${when(last.time)}: ${last.message}`
176− : " in no published version yet",
265+ ? ` last changed in version ${last.version} by ${byWhom(last)}, ${when(last.time)}: ${last.message}` 266+ : " in no pushed version yet", 177267 ...(drafts.length > 0 180− ` ${s.agent}${s.agent === agent ? " (you)" : ""} has unpublished changes at lines ${ranges(s.lines) || "(none left)"}, last at ${when(s.lastEdit)}`,
270+ ` ${s.agent}${s.agent === agent ? " (you)" : ""} has unpushed changes at lines ${ranges(s.lines) || "(none left)"}, last at ${when(s.lastEdit)}`, 182− : [" nobody has unpublished changes in it"]),
272+ : [" nobody has unpushed changes in it"]), 185275 ` ${n.agent}${n.agent === agent ? " (you)" : ""} started "${n.text}"${n.draft ? ` in draft ${n.draft}` : ""}, ${when(n.time)}`, Lines 292–298 at 318 (were 202–208 at 2)
202292 const starting = notes.length > 0 ? ["Starting on:", ...notes] : []; 203293 if (files.length === 0) 205− text: [`Nobody has unpublished changes. Shared is at version ${w.version}.`, ...starting].join("\n"),
295+ text: [`Nobody has unpushed changes. Shared is at version ${w.version}.`, ...starting].join("\n"), 208298 const lines = [...starting, `Who's working where (shared is at version ${w.version}):`];