checkpoint/strategy: collapse duplicated mirror patterns

main

Commit

pfleidi3mo ago

New helpers absorb three duplicated patterns:

  • CommittedRefs.PrimaryAsRead returns a copy with Read=Primary; the two attach guards (checkpointHasSessionMetadata, checkpointPresentLocally) use it instead of mutating a local copy.
  • AdvanceLocalRef dispatches to AdvanceCommittedPrimary for Primary and plain SetReference otherwise; the advance closures in fetchAndRebaseRefCommon and ReconcileDisconnectedMetadataRef each collapse to a one-liner.
  • (*GitStore).setPrimaryRef collapses five SetReference+Errorf write sites in committed.go.

AdvanceCommittedPrimary no longer reads Primary back after writing it: the mirror path is split into MirrorCommittedMetadataRef (reads first, for callers without a hash) and setMirrorTo (writes a known hash). Saves one repo.Reference lookup per committed write.

Four sites that had a store in scope now reuse store.Refs() instead of re-running ResolveCommittedRefs(ctx) — each call hits settings.json on disk plus a git subprocess. Sites: condensation finalize, attribution finalize, transcript finalize, explain getBranchCheckpoints.

A test fixture switches from hand-built v1-only CommittedRefs to DefaultV1Refs.

Entire-Checkpoint: 7324f71f4c46

Checkpoints

Streamline Checkpoint Version Mirroring with refs.Primary

Claude Code
View session
Checkpoint 1