aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/modload/modfile.go
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-03-13 16:46:51 -0400
committerBryan C. Mills <bcmills@google.com>2020-08-24 20:22:16 +0000
commit5c76382762cfc34b7a7678668460f127fec4a35b (patch)
tree1b87d124fa5d56eca5ea599bdfbd3346eedf6840 /src/cmd/go/internal/modload/modfile.go
parent94953d3e5928c8a577bad7911aabbf627269ef77 (diff)
downloadgo-5c76382762cfc34b7a7678668460f127fec4a35b.tar.gz
go-5c76382762cfc34b7a7678668460f127fec4a35b.zip
cmd/go/internal/modload: add a "v" prefix to the indexed go version
This allows semver-based comparisons of the version without additional allocations. Also comment on the reason for the loops that iterate over modFile instead. (I was reading the vendor code in order to add the lazy-loading version check, and this section was a bit unclear to me.) For #36460 Change-Id: I11559d81ffb4eba0e4e10e6fa3c01990b11f9180 Reviewed-on: https://go-review.googlesource.com/c/go/+/240622 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/modfile.go')
-rw-r--r--src/cmd/go/internal/modload/modfile.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/cmd/go/internal/modload/modfile.go b/src/cmd/go/internal/modload/modfile.go
index 9f4ec5a49f..9a166cae54 100644
--- a/src/cmd/go/internal/modload/modfile.go
+++ b/src/cmd/go/internal/modload/modfile.go
@@ -20,7 +20,7 @@ type modFileIndex struct {
data []byte
dataNeedsFix bool // true if fixVersion applied a change while parsing data
module module.Version
- goVersion string
+ goVersionV string // GoVersion with "v" prefix
require map[module.Version]requireMeta
replace map[module.Version]module.Version
exclude map[module.Version]bool
@@ -66,9 +66,11 @@ func indexModFile(data []byte, modFile *modfile.File, needsFix bool) *modFileInd
i.module = modFile.Module.Mod
}
- i.goVersion = ""
+ i.goVersionV = ""
if modFile.Go != nil {
- i.goVersion = modFile.Go.Version
+ // We're going to use the semver package to compare Go versions, so go ahead
+ // and add the "v" prefix it expects once instead of every time.
+ i.goVersionV = "v" + modFile.Go.Version
}
i.require = make(map[module.Version]requireMeta, len(modFile.Require))
@@ -114,11 +116,11 @@ func (i *modFileIndex) modFileIsDirty(modFile *modfile.File) bool {
}
if modFile.Go == nil {
- if i.goVersion != "" {
+ if i.goVersionV != "" {
return true
}
- } else if modFile.Go.Version != i.goVersion {
- if i.goVersion == "" && cfg.BuildMod == "readonly" {
+ } else if "v"+modFile.Go.Version != i.goVersionV {
+ if i.goVersionV == "" && cfg.BuildMod == "readonly" {
// go.mod files did not always require a 'go' version, so do not error out
// if one is missing — we may be inside an older module in the module
// cache, and should bias toward providing useful behavior.