versionsOf
uses tcmts.share.NameTrees, which uses tcmts.store.unpacked, which uses node:zlib
The versions a name has had on the current branch: each hash it pointed at, newest first, with the history entry
that pointed it there (its title and time), read back scan entries along first parents.
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { NameTrees } from "#codebase/tcmts/share"; import { entryTitle } from "#codebase/tcmts/store"; export function versionsOf( cb: Codebase, name: string, scan = 500, ): { hash: string; causal: string; title: string; ts: number }[] { const trees = new NameTrees(cb.store); const out: { hash: string; causal: string; title: string; ts: number }[] = []; let c = cb.store.causal(cb.store.head()); for (let i = 0; c && i < scan; i++) { const parent = c.parents[0] ? cb.store.causal(c.parents[0]) : undefined; let now: string[]; let before: string[]; try { now = trees.hashesAt(c.namespace, name); before = parent ? trees.hashesAt(parent.namespace, name) : []; } catch { // (history this codebase doesn't hold all of: what's read so far is all there is) break; } for (const h of now) if (!before.includes(h) && !out.some((o) => o.hash === h)) out.push({ hash: h, causal: c.hash, title: entryTitle(c), ts: c.ts }); c = parent; } return out; }