refactor: dedupe tracked-branch lookups, drop dead undo indirection#89
Merged
Conversation
No behaviour change; verified by the engine + model-invariant + e2e suites. - Add State.tracked and currentTracked helpers and route the engine's eight duplicated "branch %q is not tracked" lookups through them: fold/squash/onto share the CurrentBranch+tracked preamble, and delete/untrack/RestackBranch/needsRestackAgainst share the by-name lookup. The message now has a single source of truth. - Remove the checkoutAfterRestore variable in Undo: it was initialised to "" and never reassigned before its own always-true `== ""` guard, so it only obscured that the final checkout target is entry.CurrentBranch.
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.
What
Two behaviour-preserving simplifications in
internal/stackfound during a maintainability audit.1. Single source for the "not tracked" lookup. The pattern
b, ok := s.Get(name); if !ok { return …"branch %q is not tracked" }appeared 8× acrossengine.goandrestack.go. Adds:State.tracked(name)— the by-name lookup + canonical error (used by delete, untrack,RestackBranch,needsRestackAgainst).currentTracked(g, s)— theCurrentBranch+trackedpreamble shared by fold / squash / onto.2. Drop a dead variable in
Undo.checkoutAfterRestorewas initialised to""and never reassigned before its owncheckoutAfterRestore == ""guard (always true), so it only obscured that the final checkout target is simplyentry.CurrentBranch. Inlined.Why it's safe
No behaviour change. For the trunk,
currentTrackedstill returns the same "not tracked" errors.Getproduced (the trunk isn't inBranches). The undo change removes an always-true subcondition and inlines the identical target. Covered by the engine unit tests, the model/invariant test (thousands of random op sequences), and e2e.make cigreen — stdlib-only, lint 0 issues, race + e2e, coverage 86.5%. Net −37/+46 lines (the helpers carry doc comments; call sites shrink).