]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modload: replace references to modfetch.Fetcher_
authorIan Alexander <jitsu@google.com>
Mon, 24 Nov 2025 17:19:55 +0000 (12:19 -0500)
committerIan Alexander <jitsu@google.com>
Wed, 26 Nov 2025 03:16:43 +0000 (19:16 -0800)
This commit replaces references of modfetch.Fetcher_ with
modload.State.Fetcher() in the modload package.  Note that the
constructor `NewState` still intentionally references the global
variable.  This will be refactored in a later commit.

Change-Id: Ia8cfb41a81b0e29043694bc0f0f33f5a2f4920c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/724243
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/build.go
src/cmd/go/internal/modload/buildlist.go
src/cmd/go/internal/modload/edit.go
src/cmd/go/internal/modload/import.go
src/cmd/go/internal/modload/init.go
src/cmd/go/internal/modload/load.go
src/cmd/go/internal/modload/modfile.go
src/cmd/go/internal/modload/mvs.go
src/cmd/go/internal/modload/query.go
src/cmd/go/internal/modload/search.go

index ab4245a563cbde2d8fb1c6906f6da45c14b322e4..e89a34e0ce9f42c400762eed93c7d7d89db16e40 100644 (file)
@@ -103,7 +103,7 @@ func ModuleInfo(loaderstate *State, ctx context.Context, path string) *modinfo.M
                v, ok = rs.rootSelected(loaderstate, path)
        }
        if !ok {
-               mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               mg, err := rs.Graph(loaderstate, ctx)
                if err != nil {
                        base.Fatal(err)
                }
@@ -329,7 +329,7 @@ func moduleInfo(loaderstate *State, ctx context.Context, rs *Requirements, m mod
 
                checksumOk := func(suffix string) bool {
                        return rs == nil || m.Version == "" || !mustHaveSums(loaderstate) ||
-                               modfetch.HaveSum(modfetch.Fetcher_, module.Version{Path: m.Path, Version: m.Version + suffix})
+                               modfetch.HaveSum(loaderstate.Fetcher(), module.Version{Path: m.Path, Version: m.Version + suffix})
                }
 
                mod := module.Version{Path: m.Path, Version: m.Version}
@@ -355,7 +355,7 @@ func moduleInfo(loaderstate *State, ctx context.Context, rs *Requirements, m mod
                if m.GoVersion == "" && checksumOk("/go.mod") {
                        // Load the go.mod file to determine the Go version, since it hasn't
                        // already been populated from rawGoVersion.
-                       if summary, err := rawGoModSummary(modfetch.Fetcher_, loaderstate, mod); err == nil && summary.goVersion != "" {
+                       if summary, err := rawGoModSummary(loaderstate, mod); err == nil && summary.goVersion != "" {
                                m.GoVersion = summary.goVersion
                        }
                }
index e086c5b351e40916f8e1b0b1cec42eb269ebe7b2..37c2a6c759f0db761fbc0b480877aa663171091e 100644 (file)
@@ -20,7 +20,6 @@ import (
        "cmd/go/internal/base"
        "cmd/go/internal/cfg"
        "cmd/go/internal/gover"
-       "cmd/go/internal/modfetch"
        "cmd/go/internal/mvs"
        "cmd/internal/par"
 
@@ -270,9 +269,9 @@ func (rs *Requirements) hasRedundantRoot(loaderstate *State) bool {
 //
 // If the requirements of any relevant module fail to load, Graph also
 // returns a non-nil error of type *mvs.BuildListError.
-func (rs *Requirements) Graph(fetcher_ *modfetch.Fetcher, loaderstate *State, ctx context.Context) (*ModuleGraph, error) {
+func (rs *Requirements) Graph(loaderstate *State, ctx context.Context) (*ModuleGraph, error) {
        rs.graphOnce.Do(func() {
-               mg, mgErr := readModGraph(fetcher_, loaderstate, ctx, rs.pruning, rs.rootModules, nil)
+               mg, mgErr := readModGraph(loaderstate, ctx, rs.pruning, rs.rootModules, nil)
                rs.graph.Store(&cachedGraph{mg, mgErr})
        })
        cached := rs.graph.Load()
@@ -308,7 +307,7 @@ var readModGraphDebugOnce sync.Once
 //
 // Unlike LoadModGraph, readModGraph does not attempt to diagnose or update
 // inconsistent roots.
-func readModGraph(f *modfetch.Fetcher, loaderstate *State, ctx context.Context, pruning modPruning, roots []module.Version, unprune map[module.Version]bool) (*ModuleGraph, error) {
+func readModGraph(loaderstate *State, ctx context.Context, pruning modPruning, roots []module.Version, unprune map[module.Version]bool) (*ModuleGraph, error) {
        mustHaveGoRoot(roots)
        if pruning == pruned {
                // Enable diagnostics for lazy module loading
@@ -368,7 +367,7 @@ func readModGraph(f *modfetch.Fetcher, loaderstate *State, ctx context.Context,
        // m's go.mod file indicates that it supports graph pruning.
        loadOne := func(m module.Version) (*modFileSummary, error) {
                return mg.loadCache.Do(m, func() (*modFileSummary, error) {
-                       summary, err := goModSummary(f, loaderstate, m)
+                       summary, err := goModSummary(loaderstate, m)
 
                        mu.Lock()
                        if err == nil {
@@ -573,7 +572,7 @@ func LoadModGraph(loaderstate *State, ctx context.Context, goVersion string) (*M
                        rs = newRequirements(loaderstate, unpruned, rs.rootModules, rs.direct)
                }
 
-               return rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               return rs.Graph(loaderstate, ctx)
        }
 
        rs, mg, err := expandGraph(loaderstate, ctx, rs)
@@ -596,7 +595,7 @@ func LoadModGraph(loaderstate *State, ctx context.Context, goVersion string) (*M
 // expandGraph returns non-nil requirements and a non-nil graph regardless of
 // errors. On error, the roots might not be updated to be consistent.
 func expandGraph(loaderstate *State, ctx context.Context, rs *Requirements) (*Requirements, *ModuleGraph, error) {
-       mg, mgErr := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+       mg, mgErr := rs.Graph(loaderstate, ctx)
        if mgErr != nil {
                // Without the graph, we can't update the roots: we don't know which
                // versions of transitive dependencies would be selected.
@@ -618,7 +617,7 @@ func expandGraph(loaderstate *State, ctx context.Context, rs *Requirements) (*Re
                        return rs, mg, rsErr
                }
                rs = newRS
-               mg, mgErr = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               mg, mgErr = rs.Graph(loaderstate, ctx)
        }
 
        return rs, mg, mgErr
@@ -860,7 +859,7 @@ func tidyPrunedRoots(loaderstate *State, ctx context.Context, mainModule module.
 
        for len(queue) > 0 {
                roots = tidy.rootModules
-               mg, err := tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               mg, err := tidy.Graph(loaderstate, ctx)
                if err != nil {
                        return nil, err
                }
@@ -898,7 +897,7 @@ func tidyPrunedRoots(loaderstate *State, ctx context.Context, mainModule module.
        }
 
        roots = tidy.rootModules
-       _, err := tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
+       _, err := tidy.Graph(loaderstate, ctx)
        if err != nil {
                return nil, err
        }
@@ -940,7 +939,7 @@ func tidyPrunedRoots(loaderstate *State, ctx context.Context, mainModule module.
                if len(roots) > len(tidy.rootModules) {
                        module.Sort(roots)
                        tidy = newRequirements(loaderstate, pruned, roots, tidy.direct)
-                       _, err = tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                       _, err = tidy.Graph(loaderstate, ctx)
                        if err != nil {
                                return nil, err
                        }
@@ -1122,7 +1121,7 @@ func updatePrunedRoots(loaderstate *State, ctx context.Context, direct map[strin
 
                        rs = newRequirements(loaderstate, pruned, roots, direct)
                        var err error
-                       mg, err = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                       mg, err = rs.Graph(loaderstate, ctx)
                        if err != nil {
                                return rs, err
                        }
@@ -1136,7 +1135,7 @@ func updatePrunedRoots(loaderstate *State, ctx context.Context, direct map[strin
                                // We've already loaded the full module graph, which includes the
                                // requirements of all of the root modules — even the transitive
                                // requirements, if they are unpruned!
-                               mg, _ = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                               mg, _ = rs.Graph(loaderstate, ctx)
                        } else if cfg.BuildMod == "vendor" {
                                // We can't spot-check the requirements of other modules because we
                                // don't in general have their go.mod files available in the vendor
@@ -1149,7 +1148,7 @@ func updatePrunedRoots(loaderstate *State, ctx context.Context, direct map[strin
                                // inconsistent in some way; we need to load the full module graph
                                // so that we can fix the roots properly.
                                var err error
-                               mg, err = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                               mg, err = rs.Graph(loaderstate, ctx)
                                if err != nil {
                                        return rs, err
                                }
@@ -1236,7 +1235,7 @@ func spotCheckRoots(loaderstate *State, ctx context.Context, rs *Requirements, m
                                return
                        }
 
-                       summary, err := goModSummary(modfetch.Fetcher_, loaderstate, m)
+                       summary, err := goModSummary(loaderstate, m)
                        if err != nil {
                                cancel()
                                return
@@ -1369,7 +1368,7 @@ func tidyUnprunedRoots(loaderstate *State, ctx context.Context, mainModule modul
 //  4. Every version in add is selected at its given version unless upgraded by
 //     (the dependencies of) an existing root or another module in add.
 func updateUnprunedRoots(loaderstate *State, ctx context.Context, direct map[string]bool, rs *Requirements, add []module.Version) (*Requirements, error) {
-       mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+       mg, err := rs.Graph(loaderstate, ctx)
        if err != nil {
                // We can't ignore errors in the module graph even if the user passed the -e
                // flag to try to push past them. If we can't load the complete module
@@ -1488,7 +1487,7 @@ func convertPruning(loaderstate *State, ctx context.Context, rs *Requirements, p
        // root set! “Include the transitive dependencies of every module in the build
        // list” is exactly what happens in a pruned module if we promote every module
        // in the build list to a root.
-       mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+       mg, err := rs.Graph(loaderstate, ctx)
        if err != nil {
                return rs, err
        }
index cdf641c9e4ec88f1d6107bdd4e8ff72c526fc216..8038a77b0b35d8be6f3ddb18a85e79e6fcf4c548 100644 (file)
@@ -5,11 +5,6 @@
 package modload
 
 import (
-       "cmd/go/internal/cfg"
-       "cmd/go/internal/gover"
-       "cmd/go/internal/modfetch"
-       "cmd/go/internal/mvs"
-       "cmd/internal/par"
        "context"
        "errors"
        "fmt"
@@ -17,6 +12,11 @@ import (
        "os"
        "slices"
 
+       "cmd/go/internal/cfg"
+       "cmd/go/internal/gover"
+       "cmd/go/internal/mvs"
+       "cmd/internal/par"
+
        "golang.org/x/mod/module"
 )
 
@@ -101,7 +101,7 @@ func editRequirements(loaderstate *State, ctx context.Context, rs *Requirements,
                // dependencies, so we need to treat everything in the build list as
                // potentially relevant — that is, as what would be a “root” in a module
                // with graph pruning enabled.
-               mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               mg, err := rs.Graph(loaderstate, ctx)
                if err != nil {
                        // If we couldn't load the graph, we don't know what its requirements were
                        // to begin with, so we can't edit those requirements in a coherent way.
@@ -392,7 +392,7 @@ func editRequirements(loaderstate *State, ctx context.Context, rs *Requirements,
                        // the edit. We want to make sure we consider keeping it as-is,
                        // even if it wouldn't normally be included. (For example, it might
                        // be a pseudo-version or pre-release.)
-                       origMG, _ := orig.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                       origMG, _ := orig.Graph(loaderstate, ctx)
                        origV := origMG.Selected(m.Path)
 
                        if conflict.Err != nil && origV == m.Version {
@@ -610,7 +610,7 @@ func editRequirements(loaderstate *State, ctx context.Context, rs *Requirements,
 // some root to that version.
 func extendGraph(loaderstate *State, ctx context.Context, rootPruning modPruning, roots []module.Version, selectedRoot map[string]string) (mg *ModuleGraph, upgradedRoot map[module.Version]bool, err error) {
        for {
-               mg, err = readModGraph(modfetch.Fetcher_, loaderstate, ctx, rootPruning, roots, upgradedRoot)
+               mg, err = readModGraph(loaderstate, ctx, rootPruning, roots, upgradedRoot)
                // We keep on going even if err is non-nil until we reach a steady state.
                // (Note that readModGraph returns a non-nil *ModuleGraph even in case of
                // errors.) The caller may be able to fix the errors by adjusting versions,
index eb97d5ff78a52fae47a0e81e912695513c7cf6fa..04e95b7a8d928380ff4730bb0c0dabe7a8acd0c6 100644 (file)
@@ -481,7 +481,7 @@ func importFromModules(loaderstate *State, ctx context.Context, path string, rs
                        // of a package in "all", we didn't necessarily load that file
                        // when we read the module graph, so do it now to be sure.
                        if !skipModFile && cfg.BuildMod != "vendor" && mods[0].Path != "" && !loaderstate.MainModules.Contains(mods[0].Path) {
-                               if _, err := goModSummary(modfetch.Fetcher_, loaderstate, mods[0]); err != nil {
+                               if _, err := goModSummary(loaderstate, mods[0]); err != nil {
                                        return module.Version{}, "", "", nil, err
                                }
                        }
@@ -506,7 +506,7 @@ func importFromModules(loaderstate *State, ctx context.Context, path string, rs
 
                // So far we've checked the root dependencies.
                // Load the full module graph and try again.
-               mg, err = rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               mg, err = rs.Graph(loaderstate, ctx)
                if err != nil {
                        // We might be missing one or more transitive (implicit) dependencies from
                        // the module graph, so we can't return an ImportMissingError here — one
@@ -543,7 +543,7 @@ func queryImport(loaderstate *State, ctx context.Context, path string, rs *Requi
                                        mv = module.ZeroPseudoVersion("v0")
                                }
                        }
-                       mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                       mg, err := rs.Graph(loaderstate, ctx)
                        if err != nil {
                                return module.Version{}, err
                        }
@@ -637,7 +637,7 @@ func queryImport(loaderstate *State, ctx context.Context, path string, rs *Requi
        // and return m, dir, ImportMissingError.
        fmt.Fprintf(os.Stderr, "go: finding module for package %s\n", path)
 
-       mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+       mg, err := rs.Graph(loaderstate, ctx)
        if err != nil {
                return module.Version{}, err
        }
@@ -817,11 +817,11 @@ func fetch(loaderstate *State, ctx context.Context, mod module.Version) (dir str
                mod = r
        }
 
-       if mustHaveSums(loaderstate) && !modfetch.HaveSum(modfetch.Fetcher_, mod) {
+       if mustHaveSums(loaderstate) && !modfetch.HaveSum(loaderstate.Fetcher(), mod) {
                return "", false, module.VersionError(mod, &sumMissingError{})
        }
 
-       dir, err = modfetch.Fetcher_.Download(ctx, mod)
+       dir, err = loaderstate.Fetcher().Download(ctx, mod)
        return dir, false, err
 }
 
index f46b96afb6ea6c71370e0864a0f500bfd7c0218b..d78a41d3c6158d171abd1f25baf0df67d12da4bd 100644 (file)
@@ -457,10 +457,14 @@ type State struct {
 
 func NewState() *State {
        s := new(State)
-       s.fetcher = modfetch.NewFetcher()
+       s.fetcher = modfetch.Fetcher_
        return s
 }
 
+func (s *State) Fetcher() *modfetch.Fetcher {
+       return s.fetcher
+}
+
 // 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
@@ -937,9 +941,9 @@ func loadModFile(loaderstate *State, ctx context.Context, opts *PackageOpts) (*R
                }
                for _, modRoot := range loaderstate.modRoots {
                        sumFile := strings.TrimSuffix(modFilePath(modRoot), ".mod") + ".sum"
-                       modfetch.Fetcher_.AddWorkspaceGoSumFile(sumFile)
+                       loaderstate.Fetcher().AddWorkspaceGoSumFile(sumFile)
                }
-               modfetch.Fetcher_.SetGoSumFile(loaderstate.workFilePath + ".sum")
+               loaderstate.Fetcher().SetGoSumFile(loaderstate.workFilePath + ".sum")
        } else if len(loaderstate.modRoots) == 0 {
                // We're in module mode, but not inside a module.
                //
@@ -959,7 +963,7 @@ func loadModFile(loaderstate *State, ctx context.Context, opts *PackageOpts) (*R
                //
                // See golang.org/issue/32027.
        } else {
-               modfetch.Fetcher_.SetGoSumFile(strings.TrimSuffix(modFilePath(loaderstate.modRoots[0]), ".mod") + ".sum")
+               loaderstate.Fetcher().SetGoSumFile(strings.TrimSuffix(modFilePath(loaderstate.modRoots[0]), ".mod") + ".sum")
        }
        if len(loaderstate.modRoots) == 0 {
                // TODO(#49228): Instead of creating a fake module with an empty modroot,
@@ -1965,7 +1969,7 @@ func commitRequirements(loaderstate *State, ctx context.Context, opts WriteOpts)
        if loaderstate.inWorkspaceMode() {
                // go.mod files aren't updated in workspace mode, but we still want to
                // update the go.work.sum file.
-               return modfetch.Fetcher_.WriteGoSum(ctx, keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
+               return loaderstate.Fetcher().WriteGoSum(ctx, keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
        }
        _, updatedGoMod, modFile, err := UpdateGoModFromReqs(loaderstate, ctx, opts)
        if err != nil {
@@ -1989,7 +1993,7 @@ func commitRequirements(loaderstate *State, ctx context.Context, opts WriteOpts)
                // Don't write go.mod, but write go.sum in case we added or trimmed sums.
                // 'go mod init' shouldn't write go.sum, since it will be incomplete.
                if cfg.CmdName != "mod init" {
-                       if err := modfetch.Fetcher_.WriteGoSum(ctx, keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate)); err != nil {
+                       if err := loaderstate.Fetcher().WriteGoSum(ctx, keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate)); err != nil {
                                return err
                        }
                }
@@ -2012,7 +2016,7 @@ func commitRequirements(loaderstate *State, ctx context.Context, opts WriteOpts)
                // 'go mod init' shouldn't write go.sum, since it will be incomplete.
                if cfg.CmdName != "mod init" {
                        if err == nil {
-                               err = modfetch.Fetcher_.WriteGoSum(ctx, keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
+                               err = loaderstate.Fetcher().WriteGoSum(ctx, keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums), mustHaveCompleteRequirements(loaderstate))
                        }
                }
        }()
@@ -2055,7 +2059,7 @@ func commitRequirements(loaderstate *State, ctx context.Context, opts WriteOpts)
 // including any go.mod files needed to reconstruct the MVS result
 // or identify go versions,
 // in addition to the checksums for every module in keepMods.
-func keepSums(fetcher_ *modfetch.Fetcher, loaderstate *State, ctx context.Context, ld *loader, rs *Requirements, which whichSums) map[module.Version]bool {
+func keepSums(loaderstate *State, ctx context.Context, ld *loader, rs *Requirements, which whichSums) map[module.Version]bool {
        // Every module in the full module graph contributes its requirements,
        // so in order to ensure that the build list itself is reproducible,
        // we need sums for every go.mod in the graph (regardless of whether
@@ -2113,7 +2117,7 @@ func keepSums(fetcher_ *modfetch.Fetcher, loaderstate *State, ctx context.Contex
                                }
                        }
 
-                       mg, _ := rs.Graph(fetcher_, loaderstate, ctx)
+                       mg, _ := rs.Graph(loaderstate, ctx)
                        for prefix := pkg.path; prefix != "."; prefix = path.Dir(prefix) {
                                if v := mg.Selected(prefix); v != "none" {
                                        m := module.Version{Path: prefix, Version: v}
@@ -2136,7 +2140,7 @@ func keepSums(fetcher_ *modfetch.Fetcher, loaderstate *State, ctx context.Contex
                        }
                }
        } else {
-               mg, _ := rs.Graph(fetcher_, loaderstate, ctx)
+               mg, _ := rs.Graph(loaderstate, ctx)
                mg.WalkBreadthFirst(func(m module.Version) {
                        if _, ok := mg.RequiredBy(m); ok {
                                // The requirements from m's go.mod file are present in the module graph,
index 2c09cbf5860b88664381a840b4290ee2dfb7e434..bbc81263d5a6f2010eb925f3699a65228cf0a994 100644 (file)
@@ -311,7 +311,7 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
 
                        case strings.Contains(m.Pattern(), "..."):
                                m.Errs = m.Errs[:0]
-                               mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                               mg, err := rs.Graph(loaderstate, ctx)
                                if err != nil {
                                        // The module graph is (or may be) incomplete — perhaps we failed to
                                        // load the requirements of some module. This is an error in matching
@@ -404,7 +404,7 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
 
        if opts.Tidy {
                if cfg.BuildV {
-                       mg, _ := ld.requirements.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                       mg, _ := ld.requirements.Graph(loaderstate, ctx)
                        for _, m := range initialRS.rootModules {
                                var unused bool
                                if ld.requirements.pruning == unpruned {
@@ -425,7 +425,7 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
                        }
                }
 
-               keep := keepSums(modfetch.Fetcher_, loaderstate, ctx, ld, ld.requirements, loadedZipSumsOnly)
+               keep := keepSums(loaderstate, ctx, ld, ld.requirements, loadedZipSumsOnly)
                compatVersion := ld.TidyCompatibleVersion
                goVersion := ld.requirements.GoVersion(loaderstate)
                if compatVersion == "" {
@@ -447,7 +447,7 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
                        compatRS := newRequirements(loaderstate, compatPruning, ld.requirements.rootModules, ld.requirements.direct)
                        ld.checkTidyCompatibility(loaderstate, ctx, compatRS, compatVersion)
 
-                       for m := range keepSums(modfetch.Fetcher_, loaderstate, ctx, ld, compatRS, loadedZipSumsOnly) {
+                       for m := range keepSums(loaderstate, ctx, ld, compatRS, loadedZipSumsOnly) {
                                keep[m] = true
                        }
                }
@@ -466,7 +466,7 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
                        // Dropping compatibility for 1.16 may result in a strictly smaller go.sum.
                        // Update the keep map with only the loaded.requirements.
                        if gover.Compare(compatVersion, "1.16") > 0 {
-                               keep = keepSums(modfetch.Fetcher_, loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums)
+                               keep = keepSums(loaderstate, ctx, loaded, loaderstate.requirements, addBuildListZipSums)
                        }
                        currentGoSum, tidyGoSum := modfetch.TidyGoSum(keep)
                        goSumDiff := diff.Diff("current/go.sum", currentGoSum, "tidy/go.sum", tidyGoSum)
@@ -490,7 +490,7 @@ func LoadPackages(loaderstate *State, ctx context.Context, opts PackageOpts, pat
                        // loaded.requirements, but here we may have also loaded (and want to
                        // preserve checksums for) additional entities from compatRS, which are
                        // only needed for compatibility with ld.TidyCompatibleVersion.
-                       if err := modfetch.Fetcher_.WriteGoSum(ctx, keep, mustHaveCompleteRequirements(loaderstate)); err != nil {
+                       if err := loaderstate.Fetcher().WriteGoSum(ctx, keep, mustHaveCompleteRequirements(loaderstate)); err != nil {
                                base.Fatal(err)
                        }
                }
@@ -747,7 +747,7 @@ func pathInModuleCache(loaderstate *State, ctx context.Context, dir string, rs *
        // versions of root modules may differ from what we already checked above.
        // Re-check those paths too.
 
-       mg, _ := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+       mg, _ := rs.Graph(loaderstate, ctx)
        var importPath string
        for _, m := range mg.BuildList() {
                var found bool
@@ -1253,7 +1253,7 @@ func loadFromRoots(loaderstate *State, ctx context.Context, params loaderParams)
                                // pruning and semantics all along, but there may have been — and may
                                // still be — requirements on higher versions in the graph.
                                tidy := overrideRoots(loaderstate, ctx, rs, []module.Version{{Path: "go", Version: ld.TidyGoVersion}})
-                               mg, err := tidy.Graph(modfetch.Fetcher_, loaderstate, ctx)
+                               mg, err := tidy.Graph(loaderstate, ctx)
                                if err != nil {
                                        ld.error(err)
                                }
@@ -1412,7 +1412,7 @@ func (ld *loader) updateRequirements(loaderstate *State, ctx context.Context) (c
                                        // of the vendor directory anyway.
                                        continue
                                }
-                               if mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx); err != nil {
+                               if mg, err := rs.Graph(loaderstate, ctx); err != nil {
                                        return false, err
                                } else if _, ok := mg.RequiredBy(dep.mod); !ok {
                                        // dep.mod is not an explicit dependency, but needs to be.
@@ -1515,7 +1515,7 @@ func (ld *loader) updateRequirements(loaderstate *State, ctx context.Context) (c
                // The roots of the module graph have changed in some way (not just the
                // "direct" markings). Check whether the changes affected any of the loaded
                // packages.
-               mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               mg, err := rs.Graph(loaderstate, ctx)
                if err != nil {
                        return false, err
                }
@@ -1841,7 +1841,7 @@ func (ld *loader) load(loaderstate *State, ctx context.Context, pkg *loadPkg) {
        var mg *ModuleGraph
        if ld.requirements.pruning == unpruned {
                var err error
-               mg, err = ld.requirements.Graph(modfetch.Fetcher_, loaderstate, ctx)
+               mg, err = ld.requirements.Graph(loaderstate, ctx)
                if err != nil {
                        // We already checked the error from Graph in loadFromRoots and/or
                        // updateRequirements, so we ignored the error on purpose and we should
@@ -2095,7 +2095,7 @@ func (ld *loader) checkTidyCompatibility(loaderstate *State, ctx context.Context
                fmt.Fprintf(os.Stderr, "For information about 'go mod tidy' compatibility, see:\n\thttps://go.dev/ref/mod#graph-pruning\n")
        }
 
-       mg, err := rs.Graph(modfetch.Fetcher_, loaderstate, ctx)
+       mg, err := rs.Graph(loaderstate, ctx)
        if err != nil {
                ld.error(fmt.Errorf("error loading go %s module graph: %w", compatVersion, err))
                ld.switchIfErrors(ctx)
index 4817521cba448d5cfc0bcdcd8e2ed58c53a9484e..1e54a580345466bd1364dd6ae848331f44a9c57a 100644 (file)
@@ -214,7 +214,7 @@ func (s *State) CheckRetractions(ctx context.Context, m module.Version) (err err
        if err != nil {
                return err
        }
-       summary, err := rawGoModSummary(modfetch.Fetcher_, s, rm)
+       summary, err := rawGoModSummary(s, rm)
        if err != nil && !errors.Is(err, gover.ErrTooNew) {
                return err
        }
@@ -322,7 +322,7 @@ func CheckDeprecation(loaderstate *State, ctx context.Context, m module.Version)
        if err != nil {
                return "", err
        }
-       summary, err := rawGoModSummary(modfetch.Fetcher_, loaderstate, latest)
+       summary, err := rawGoModSummary(loaderstate, latest)
        if err != nil && !errors.Is(err, gover.ErrTooNew) {
                return "", err
        }
@@ -573,12 +573,12 @@ type retraction struct {
 // module versions.
 //
 // The caller must not modify the returned summary.
-func goModSummary(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Version) (*modFileSummary, error) {
+func goModSummary(loaderstate *State, m module.Version) (*modFileSummary, error) {
        if m.Version == "" && !loaderstate.inWorkspaceMode() && loaderstate.MainModules.Contains(m.Path) {
                panic("internal error: goModSummary called on a main module")
        }
        if gover.IsToolchain(m.Path) {
-               return rawGoModSummary(fetcher_, loaderstate, m)
+               return rawGoModSummary(loaderstate, m)
        }
 
        if cfg.BuildMod == "vendor" {
@@ -604,12 +604,12 @@ func goModSummary(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Versi
        actual := resolveReplacement(loaderstate, m)
        if mustHaveSums(loaderstate) && actual.Version != "" {
                key := module.Version{Path: actual.Path, Version: actual.Version + "/go.mod"}
-               if !modfetch.HaveSum(fetcher_, key) {
+               if !modfetch.HaveSum(loaderstate.Fetcher(), key) {
                        suggestion := fmt.Sprintf(" for go.mod file; to add it:\n\tgo mod download %s", m.Path)
                        return nil, module.VersionError(actual, &sumMissingError{suggestion: suggestion})
                }
        }
-       summary, err := rawGoModSummary(fetcher_, loaderstate, actual)
+       summary, err := rawGoModSummary(loaderstate, actual)
        if err != nil {
                return nil, err
        }
@@ -676,7 +676,7 @@ func goModSummary(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Versi
 // rawGoModSummary cannot be used on the main module outside of workspace mode.
 // The modFileSummary can still be used for retractions and deprecations
 // even if a TooNewError is returned.
-func rawGoModSummary(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Version) (*modFileSummary, error) {
+func rawGoModSummary(loaderstate *State, m module.Version) (*modFileSummary, error) {
        if gover.IsToolchain(m.Path) {
                if m.Path == "go" && gover.Compare(m.Version, gover.GoStrictVersion) >= 0 {
                        // Declare that go 1.21.3 requires toolchain 1.21.3,
@@ -709,7 +709,7 @@ func rawGoModSummary(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Ve
                }
        }
        return rawGoModSummaryCache.Do(m, func() (*modFileSummary, error) {
-               name, data, err := rawGoModData(fetcher_, loaderstate, m)
+               name, data, err := rawGoModData(loaderstate, m)
                if err != nil {
                        return nil, err
                }
@@ -781,7 +781,7 @@ var rawGoModSummaryCache par.ErrCache[module.Version, *modFileSummary]
 //
 // Unlike rawGoModSummary, rawGoModData does not cache its results in memory.
 // Use rawGoModSummary instead unless you specifically need these bytes.
-func rawGoModData(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Version) (name string, data []byte, err error) {
+func rawGoModData(loaderstate *State, m module.Version) (name string, data []byte, err error) {
        if m.Version == "" {
                dir := m.Path
                if !filepath.IsAbs(dir) {
@@ -810,7 +810,7 @@ func rawGoModData(fetcher_ *modfetch.Fetcher, loaderstate *State, m module.Versi
                        base.Fatalf("go: internal error: %s@%s: unexpected invalid semantic version", m.Path, m.Version)
                }
                name = "go.mod"
-               data, err = fetcher_.GoMod(context.TODO(), m.Path, m.Version)
+               data, err = loaderstate.Fetcher().GoMod(context.TODO(), m.Path, m.Version)
        }
        return name, data, err
 }
index 18cd4345b231bafd6cdbdc25810a59c7a3f71e13..63fedae0f162124a16c0509561a3ceea8ebc342c 100644 (file)
@@ -54,7 +54,7 @@ func (r *mvsReqs) Required(mod module.Version) ([]module.Version, error) {
                return nil, nil
        }
 
-       summary, err := goModSummary(modfetch.Fetcher_, r.loaderstate, mod)
+       summary, err := goModSummary(r.loaderstate, mod)
        if err != nil {
                return nil, err
        }
index 158b672c6f73f313a237b6dd7e12b57e6b00fa6b..b6bf0803c1055e2f7bff10894aa634bf427fff89 100644 (file)
@@ -1099,7 +1099,7 @@ func (e *PackageNotInModuleError) ImportPath() string {
 // we don't need to verify it in go.sum. This makes 'go list -m -u' faster
 // and simpler.
 func versionHasGoMod(loaderstate *State, _ context.Context, m module.Version) (bool, error) {
-       _, data, err := rawGoModData(modfetch.Fetcher_, loaderstate, m)
+       _, data, err := rawGoModData(loaderstate, m)
        if err != nil {
                return false, err
        }
@@ -1124,7 +1124,7 @@ func lookupRepo(loaderstate *State, ctx context.Context, proxy, path string) (re
                err = module.CheckPath(path)
        }
        if err == nil {
-               repo = modfetch.Fetcher_.Lookup(ctx, proxy, path)
+               repo = loaderstate.Fetcher().Lookup(ctx, proxy, path)
        } else {
                repo = emptyRepo{path: path, err: err}
        }
@@ -1150,9 +1150,11 @@ func (er emptyRepo) ModulePath() string { return er.path }
 func (er emptyRepo) CheckReuse(ctx context.Context, old *codehost.Origin) error {
        return fmt.Errorf("empty repo")
 }
+
 func (er emptyRepo) Versions(ctx context.Context, prefix string) (*modfetch.Versions, error) {
        return &modfetch.Versions{}, nil
 }
+
 func (er emptyRepo) Stat(ctx context.Context, rev string) (*modfetch.RevInfo, error) {
        return nil, er.err
 }
index 9a3b7e9dd9d6f9949c4f56be0f734fc6e8594db1..c45808635dbe693af83a8c6b4a71a78d9e0616b6 100644 (file)
@@ -21,7 +21,6 @@ import (
        "cmd/go/internal/fsys"
        "cmd/go/internal/gover"
        "cmd/go/internal/imports"
-       "cmd/go/internal/modfetch"
        "cmd/go/internal/modindex"
        "cmd/go/internal/search"
        "cmd/go/internal/str"
@@ -349,7 +348,7 @@ func parseIgnorePatterns(loaderstate *State, ctx context.Context, treeCanMatch f
                        if err != nil {
                                continue
                        }
-                       summary, err := goModSummary(modfetch.Fetcher_, loaderstate, mod)
+                       summary, err := goModSummary(loaderstate, mod)
                        if err != nil {
                                continue
                        }