]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: export type State
authorIan Alexander <jitsu@google.com>
Wed, 20 Aug 2025 23:12:20 +0000 (19:12 -0400)
committerIan Alexander <jitsu@google.com>
Mon, 6 Oct 2025 19:52:05 +0000 (12:52 -0700)
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 <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

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

index 498ff7433ea6feaf0cd2ab61e68c0f09e23a7ebc..5192fe0fc8cc587c481ba51e83924bfd12a00c83 100644 (file)
@@ -96,7 +96,7 @@ func EnterWorkspace(ctx context.Context) (exit func(), err error) {
        }
 
        // Reset the state to a clean state.
-       oldstate := setState(state{})
+       oldstate := setState(State{})
        ForceUseModules = true
 
        // Load in workspace mode.
@@ -401,11 +401,11 @@ func WorkFilePath() string {
 // Reset clears all the initialized, cached state about the use of modules,
 // so that we can start over.
 func Reset() {
-       setState(state{})
+       setState(State{})
 }
 
-func setState(s state) state {
-       oldState := state{
+func setState(s State) State {
+       oldState := State{
                initialized:     initialized,
                forceUseModules: ForceUseModules,
                rootMode:        RootMode,
@@ -429,7 +429,7 @@ func setState(s state) state {
        return oldState
 }
 
-type state struct {
+type State struct {
        initialized     bool
        forceUseModules bool
        rootMode        Root
@@ -441,6 +441,10 @@ type state struct {
        modfetchState   modfetch.State
 }
 
+func NewState() *State { return &State{} }
+
+var LoaderState = NewState()
+
 // Init determines whether module mode is enabled, locates the root of the
 // current module (if any), sets environment variables for Git subprocesses, and
 // configures the cfg, codehost, load, modfetch, and search packages for use