diff options
author | Bryan C. Mills <bcmills@google.com> | 2020-10-16 21:57:46 -0400 |
---|---|---|
committer | Daniel Martà <mvdan@mvdan.cc> | 2020-10-17 19:22:49 +0000 |
commit | 30119bcca997d154e4ab200b01afa7007b088994 (patch) | |
tree | 590e2718b15f3130444a196ef393dd3697b46cf0 /src/cmd/go/internal/modload/query.go | |
parent | c8f6135d4fd0be14bfc63c2bbb911cc9647e00a6 (diff) | |
download | go-30119bcca997d154e4ab200b01afa7007b088994.tar.gz go-30119bcca997d154e4ab200b01afa7007b088994.zip |
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>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r-- | src/cmd/go/internal/modload/query.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go index d16a247f72..3b27e66d01 100644 --- a/src/cmd/go/internal/modload/query.go +++ b/src/cmd/go/internal/modload/query.go @@ -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 } |