Temper.History.Prune (temper v0.3.0)

Copy Markdown View Source

Selective retention for history files — the pure core behind mix temper.clean --older-than and --keep-shas.

A retention criterion only ever drops lines it can positively match: age drops a line only when it carries a readable timestamp older than the cutoff, and SHA retention only when it carries a SHA outside the kept set. Everything else — suite summaries under SHA retention, null-SHA records, future kinds — survives: what a criterion cannot read, it cannot claim. Corrupt lines (unreadable JSON) are the one exception: a rewrite is the chance to drop them, counted, exactly as mix temper.merge does.

Part of the functional core: lines in, lines out, no side effects.

Summary

Types

Each file's kept lines in order, plus counts of what was dropped.

Functions

Applies the retention criteria to every file's lines.

Types

result()

@type result() :: %{
  files: [{Path.t(), [String.t()]}],
  pruned: non_neg_integer(),
  corrupt: non_neg_integer()
}

Each file's kept lines in order, plus counts of what was dropped.

Functions

prune(files, opts)

@spec prune(
  [{Path.t(), [String.t()]}],
  keyword()
) :: result()

Applies the retention criteria to every file's lines.

Options (a nil value disables that criterion):

  • :cutoff — a DateTime; lines whose "at" is older are dropped
  • :keep_shas — how many of the most recently recorded distinct SHAs to keep, ranked by each SHA's newest line across all files

Lines must arrive trimmed; blank lines vanish without counting.