Skip to content

Commit 2441645

Browse files
committed
cmd/go: export type State
Export the type `State` and add global variable `LoaderState` in preparation for refactoring usage of other global variables in the modload package. This commit is part of the overall effort to eliminate global modloader state. [git-generate] cd src/cmd/go/internal/modload rf 'mv state State' rf 'add State func NewState() *State { return &State{} }' rf 'add init.go:/NewState/+0 var LoaderState = NewState()' Change-Id: I0ec6199ba3e05927bec12f11a60383d1b51b111a Reviewed-on: https://go-review.googlesource.com/c/go/+/698055 Reviewed-by: Michael Matloob <[email protected]> Reviewed-by: Michael Matloob <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent c2fb151 commit 2441645

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/cmd/go/internal/modload/init.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func EnterWorkspace(ctx context.Context) (exit func(), err error) {
9696
}
9797

9898
// Reset the state to a clean state.
99-
oldstate := setState(state{})
99+
oldstate := setState(State{})
100100
ForceUseModules = true
101101

102102
// Load in workspace mode.
@@ -401,11 +401,11 @@ func WorkFilePath() string {
401401
// Reset clears all the initialized, cached state about the use of modules,
402402
// so that we can start over.
403403
func Reset() {
404-
setState(state{})
404+
setState(State{})
405405
}
406406

407-
func setState(s state) state {
408-
oldState := state{
407+
func setState(s State) State {
408+
oldState := State{
409409
initialized: initialized,
410410
forceUseModules: ForceUseModules,
411411
rootMode: RootMode,
@@ -429,7 +429,7 @@ func setState(s state) state {
429429
return oldState
430430
}
431431

432-
type state struct {
432+
type State struct {
433433
initialized bool
434434
forceUseModules bool
435435
rootMode Root
@@ -441,6 +441,10 @@ type state struct {
441441
modfetchState modfetch.State
442442
}
443443

444+
func NewState() *State { return &State{} }
445+
446+
var LoaderState = NewState()
447+
444448
// Init determines whether module mode is enabled, locates the root of the
445449
// current module (if any), sets environment variables for Git subprocesses, and
446450
// configures the cfg, codehost, load, modfetch, and search packages for use

0 commit comments

Comments
 (0)