Skip to content

feat(config): add in-place Reload for refreshed reads - #298

Open
babakks wants to merge 3 commits into
trunkfrom
babakks/add-refresh-token-support
Open

babakks wants to merge 3 commits into
trunkfrom
babakks/add-refresh-token-support

Conversation

@babakks

@babakks babakks commented Sep 14, 2026

Copy link
Copy Markdown
Member

Description

Lets gh re-read its configuration from disk in place, which the refreshable-token stack in cli/cli needs to load the latest stored credential before spending a single-use refresh token.

The main addition is config.Reload: it re-reads the gh config files and swaps the entries of the cached *Config under a write lock, so every existing holder of that pointer observes the new values without being handed a new pointer. Like config.Read, Reload is a package-level var, so consumers and tests can replace it. Unwritten in-memory changes are discarded by the refresh, so callers persist first if they need them. deepCopy now takes the read lock so an in-place entries swap cannot race a concurrent read.

Two small drive-by fixes replace deprecated APIs: reflect.Ptr becomes reflect.Pointer, and the unix-socket transport uses DialContext/DialTLSContext instead of the deprecated Dial/DialTLS.

How did you test this change?

Unit tests in pkg/config cover Reload: it refreshes values in place, keeps the same *Config pointer, and discards unwritten changes. Existing tests pass.

@babakks
babakks requested a review from a team as a code owner September 14, 2026 23:35
@babakks
babakks requested review from williammartin and removed request for a team September 14, 2026 23:35
babakks and others added 3 commits September 15, 2026 00:37
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Add Reload, which re-reads the gh config files from disk and refreshes the
config returned by Read in place. Keeping the cached *Config pointer stable
lets every existing holder observe the new values, which keeps auth host and
token resolution (which reads through Read) consistent with callers that
reload under a lock.

Reload is a package-level var, like Read, so consumers and tests can replace it.

Lock deepCopy so the in-place entries swap cannot race a concurrent read.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f5c79efc-51d8-4913-8961-701522797f9e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant