historyList

tcmts.cli.changes.historyList · #anst6gly · term · runs anywhere

A branch's latest history entries, newest first (this branch's, unless one is named), as tcm history lists them.

import type { HistoryItem } from "#codebase/tcmts/cli/changes";
import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { shortHash } from "#codebase/tcmts/core/hash";

export function historyList(cb: Codebase, limit = 50, branch?: string): HistoryItem[] {
  return cb.store
    .causalLog(limit + 1, branch)
    .filter((c) => c.parents.length)
    .slice(0, limit)
    .map((c, back) => ({
      hash: c.hash,
      short: shortHash(c.hash),
      command: c.command,
      message: c.message,
      ts: c.ts,
      parents: c.parents,
      back,
    }));
}

uses

used by