]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: add gover.Max and gover.MaxToolchain
authorRuss Cox <rsc@golang.org>
Thu, 1 Jun 2023 18:11:27 +0000 (14:11 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 1 Jun 2023 21:32:58 +0000 (21:32 +0000)
I've inlined these by hand enough times now.

For #57001.

Change-Id: Ia274bd444f12b07ce14eeb2b5a66546880db8f77
Reviewed-on: https://go-review.googlesource.com/c/go/+/499982
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>

src/cmd/go/internal/gover/gover.go
src/cmd/go/internal/modget/get.go

index fbea6122274f4d1b74fd21622e22d11682e1617d..247717125ba26287e806a9c5dddb76424d6e943a 100644 (file)
@@ -55,6 +55,26 @@ func Compare(x, y string) int {
        return 0
 }
 
+// Max returns the maximum of x and y interpreted as toolchain versions,
+// compared using Compare.
+// If x and y compare equal, Max returns x.
+func Max(x, y string) string {
+       if Compare(x, y) < 0 {
+               return y
+       }
+       return x
+}
+
+// Toolchain returns the maximum of x and y interpreted as toolchain names,
+// compared using Compare(FromToolchain(x), FromToolchain(y)).
+// If x and y compare equal, Max returns x.
+func ToolchainMax(x, y string) string {
+       if Compare(FromToolchain(x), FromToolchain(y)) < 0 {
+               return y
+       }
+       return x
+}
+
 // IsLang reports whether v denotes the overall Go language version
 // and not a specific release. Starting with the Go 1.21 release, "1.x" denotes
 // the overall language version; the first release is "1.x.0".
index 0cf3c1dc84315feddab53e9bae76aaacf69569b6..8a8b8dea22e09daedc8b3225e3ad31d8d2287d30 100644 (file)
@@ -1233,8 +1233,8 @@ func (r *resolver) resolveQueries(ctx context.Context, queries []*query) (change
                goVers := ""
                for _, q := range queries {
                        for _, cs := range q.candidates {
-                               if e := (*gover.TooNewError)(nil); errors.As(cs.err, &e) && gover.Compare(goVers, e.GoVersion) < 0 {
-                                       goVers = e.GoVersion
+                               if e := (*gover.TooNewError)(nil); errors.As(cs.err, &e) {
+                                       goVers = gover.Max(goVers, e.GoVersion)
                                }
                        }
                }