mirror of
https://github.com/golang/go
synced 2024-11-23 07:10:05 -07:00
cmd/go/internal/modload: fix sort condition in (*replacementRepo).Versions
In CL 258220 I added replacement versions to the repo versions used in the modload.Query functions. The versions are computed from a map in the modfile index, which has a nondeterministic iteration order. I added a short-circuit condition to skip sorting in the (vastly common) case where no replacement versions are added. However, while cleaning up the change I accidentally deleted the line of code that sets that condition. As a result, the test of that functionality (mod_get_replaced) has been failing nondeterministically. This change fixes the condition by comparing the slices before and after adding versions, rather than by setting a separate variable. The test now passes reliably (tested with -count=200). Updates #41577 Updates #41416 Updates #37438 Updates #26241 Change-Id: I49a66a3a5510da00ef42b47f20a168de66100db6 Reviewed-on: https://go-review.googlesource.com/c/go/+/263266 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
This commit is contained in:
parent
c8f6135d4f
commit
30119bcca9
@ -891,12 +891,12 @@ func (rr *replacementRepo) ModulePath() string { return rr.repo.ModulePath() }
|
||||
// Versions returns the versions from rr.repo augmented with any matching
|
||||
// replacement versions.
|
||||
func (rr *replacementRepo) Versions(prefix string) ([]string, error) {
|
||||
versions, err := rr.repo.Versions(prefix)
|
||||
repoVersions, err := rr.repo.Versions(prefix)
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
added := false
|
||||
versions := repoVersions
|
||||
if index != nil && len(index.replace) > 0 {
|
||||
path := rr.ModulePath()
|
||||
for m, _ := range index.replace {
|
||||
@ -906,7 +906,7 @@ func (rr *replacementRepo) Versions(prefix string) ([]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if !added {
|
||||
if len(versions) == len(repoVersions) { // No replacement versions added.
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ go get -d example.com/x
|
||||
go list -m example.com/x
|
||||
stdout '^example.com/x v0.2.0 '
|
||||
|
||||
go get -d example.com/x@'<v0.2.0'
|
||||
go get -d example.com/x@<v0.2.0
|
||||
go list -m example.com/x
|
||||
stdout '^example.com/x v0.1.0 '
|
||||
|
||||
@ -36,13 +36,14 @@ go list -m example.com/x
|
||||
stdout '^example.com/x v0.0.0-00010101000000-000000000000 '
|
||||
|
||||
# If specific-version replacements exist, the highest matching version should be used.
|
||||
go mod edit -replace=example.com/x@v0.1.0=./x -replace=example.com/x@v0.2.0=./x
|
||||
go mod edit -replace=example.com/x@v0.1.0=./x
|
||||
go mod edit -replace=example.com/x@v0.2.0=./x
|
||||
|
||||
go get -d example.com/x
|
||||
go list -m example.com/x
|
||||
stdout '^example.com/x v0.2.0 '
|
||||
|
||||
go get -d example.com/x@'<v0.2.0'
|
||||
go get -d example.com/x@<v0.2.0
|
||||
go list -m example.com/x
|
||||
stdout '^example.com/x v0.1.0 '
|
||||
|
||||
@ -69,7 +70,7 @@ go get -d rsc.io/quote@v1.3
|
||||
go list -m rsc.io/quote
|
||||
stdout '^rsc.io/quote v1.3.1 '
|
||||
|
||||
go get -d rsc.io/quote@'>v1.3.1'
|
||||
go get -d rsc.io/quote@>v1.3.1
|
||||
go list -m rsc.io/quote
|
||||
stdout '^rsc.io/quote v1.4.0'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user