Simplify the history package#2567
Merged
dgageot merged 3 commits intodocker:mainfrom Apr 28, 2026
Merged
Conversation
gtardif
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tidy up
pkg/historyso it's easier to read and maintain, withoutchanging any user-facing behaviour or the on-disk file format.
What changed
load(): replaced the manual byte counting / line splitting /strconv.Unquoteparser withbytes.Lines+json.Unmarshal,symmetric with how entries are written.
addInMemorysoAddandloadshare the "remove prior occurrence + append" logic instead of
carrying two different implementations.
LatestMatch: usesslices.Backwardfor cleaner backwarditeration.
New(opts ...Opt)+Opt+WithBaseDir+ privateoptionsstruct collapsed into a singleNew(baseDir string). Empty string falls back to the user's homedirectory.
current == -1cursor sentinel: the cursor is nowalways a valid index in
[0, len(Messages)], which kills a specialcase in
Previous().SetCurrentclamps to[0, len(Messages)], eliminating latentout-of-bounds panics in
Previous/Nextif a caller ever passed aninvalid index.
and the persistence/migration helpers are grouped at the bottom.
json:"messages"struct tag (the file format isone JSON-encoded string per line, the struct itself is never
marshalled).
SetCurrentwithout-of-range values.