mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/go: make setState work with any State instance
This commit updates the setState function to work with any state object in preparation for converting it to a method. This commit is part of the overall effort to eliminate global modloader state. Change-Id: I6d485156e7c4c83ff608f941b68e6d928418bd8f Reviewed-on: https://go-review.googlesource.com/c/go/+/712700 Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
a420aa221e
commit
386d81151d
1 changed files with 19 additions and 19 deletions
|
|
@ -81,7 +81,7 @@ func EnterWorkspace(ctx context.Context) (exit func(), err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the state to a clean state.
|
// Reset the state to a clean state.
|
||||||
oldstate := setState(State{})
|
oldstate := setState(LoaderState, State{})
|
||||||
LoaderState.ForceUseModules = true
|
LoaderState.ForceUseModules = true
|
||||||
|
|
||||||
// Load in workspace mode.
|
// Load in workspace mode.
|
||||||
|
|
@ -93,7 +93,7 @@ func EnterWorkspace(ctx context.Context) (exit func(), err error) {
|
||||||
LoaderState.requirements = requirementsFromModFiles(LoaderState, ctx, LoaderState.MainModules.workFile, slices.Collect(maps.Values(LoaderState.MainModules.modFiles)), nil)
|
LoaderState.requirements = requirementsFromModFiles(LoaderState, ctx, LoaderState.MainModules.workFile, slices.Collect(maps.Values(LoaderState.MainModules.modFiles)), nil)
|
||||||
|
|
||||||
return func() {
|
return func() {
|
||||||
setState(oldstate)
|
setState(LoaderState, oldstate)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,31 +378,31 @@ func WorkFilePath(loaderstate *State) string {
|
||||||
// Reset clears all the initialized, cached state about the use of modules,
|
// Reset clears all the initialized, cached state about the use of modules,
|
||||||
// so that we can start over.
|
// so that we can start over.
|
||||||
func Reset() {
|
func Reset() {
|
||||||
setState(State{})
|
setState(LoaderState, State{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func setState(s State) State {
|
func setState(s *State, new State) State {
|
||||||
oldState := State{
|
oldState := State{
|
||||||
initialized: LoaderState.initialized,
|
initialized: s.initialized,
|
||||||
ForceUseModules: LoaderState.ForceUseModules,
|
ForceUseModules: s.ForceUseModules,
|
||||||
RootMode: LoaderState.RootMode,
|
RootMode: s.RootMode,
|
||||||
modRoots: LoaderState.modRoots,
|
modRoots: s.modRoots,
|
||||||
modulesEnabled: cfg.ModulesEnabled,
|
modulesEnabled: cfg.ModulesEnabled,
|
||||||
MainModules: LoaderState.MainModules,
|
MainModules: s.MainModules,
|
||||||
requirements: LoaderState.requirements,
|
requirements: s.requirements,
|
||||||
}
|
}
|
||||||
LoaderState.initialized = s.initialized
|
s.initialized = new.initialized
|
||||||
LoaderState.ForceUseModules = s.ForceUseModules
|
s.ForceUseModules = new.ForceUseModules
|
||||||
LoaderState.RootMode = s.RootMode
|
s.RootMode = new.RootMode
|
||||||
LoaderState.modRoots = s.modRoots
|
s.modRoots = new.modRoots
|
||||||
cfg.ModulesEnabled = s.modulesEnabled
|
cfg.ModulesEnabled = new.modulesEnabled
|
||||||
LoaderState.MainModules = s.MainModules
|
s.MainModules = new.MainModules
|
||||||
LoaderState.requirements = s.requirements
|
s.requirements = new.requirements
|
||||||
LoaderState.workFilePath = s.workFilePath
|
s.workFilePath = new.workFilePath
|
||||||
// The modfetch package's global state is used to compute
|
// The modfetch package's global state is used to compute
|
||||||
// the go.sum file, so save and restore it along with the
|
// the go.sum file, so save and restore it along with the
|
||||||
// modload state.
|
// modload state.
|
||||||
oldState.modfetchState = modfetch.SetState(s.modfetchState)
|
oldState.modfetchState = modfetch.SetState(new.modfetchState)
|
||||||
return oldState
|
return oldState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue