Skip to content

Commit c2d1df6

Browse files
author
Jay Conrod
committed
cmd/go: group 'go get' update messages together near the end of output
In module mode, 'go get' prints a message for each version query it resolves. This change groups those messages together near the end of the output so they aren't mixed with other module "finding" and "downloading" messages. They'll still be printed before build-related messages. Fixes #37982 Change-Id: I107a9f2b2f839e896399df906e20d6fc77f280c9 Reviewed-on: https://go-review.googlesource.com/c/go/+/232578 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 6851a55 commit c2d1df6

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

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

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
package modget
77

88
import (
9+
"bytes"
910
"errors"
1011
"fmt"
12+
"io"
1113
"os"
1214
"path/filepath"
1315
"sort"
@@ -702,6 +704,12 @@ func runGet(cmd *base.Command, args []string) {
702704
modload.AllowWriteGoMod()
703705
modload.WriteGoMod()
704706

707+
// Print the changes we made.
708+
// TODO(golang.org/issue/33284): include more information about changes to
709+
// relevant module versions due to MVS upgrades and downgrades. For now,
710+
// the log only contains messages for versions resolved with getQuery.
711+
writeUpdateLog()
712+
705713
// If -d was specified, we're done after the module work.
706714
// We've already downloaded modules by loading packages above.
707715
// Otherwise, we need to build and install the packages matched by
@@ -1034,11 +1042,28 @@ func (r *lostUpgradeReqs) Required(mod module.Version) ([]module.Version, error)
10341042
return r.Reqs.Required(mod)
10351043
}
10361044

1037-
var loggedLines sync.Map
1045+
var updateLog struct {
1046+
mu sync.Mutex
1047+
buf bytes.Buffer
1048+
logged map[string]bool
1049+
}
10381050

10391051
func logOncef(format string, args ...interface{}) {
10401052
msg := fmt.Sprintf(format, args...)
1041-
if _, dup := loggedLines.LoadOrStore(msg, true); !dup {
1042-
fmt.Fprintln(os.Stderr, msg)
1053+
updateLog.mu.Lock()
1054+
defer updateLog.mu.Unlock()
1055+
if updateLog.logged == nil {
1056+
updateLog.logged = make(map[string]bool)
1057+
}
1058+
if updateLog.logged[msg] {
1059+
return
10431060
}
1061+
updateLog.logged[msg] = true
1062+
fmt.Fprintln(&updateLog.buf, msg)
1063+
}
1064+
1065+
func writeUpdateLog() {
1066+
updateLog.mu.Lock()
1067+
defer updateLog.mu.Unlock()
1068+
io.Copy(os.Stderr, &updateLog.buf)
10441069
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Upgrades are reported.
2+
go get -d rsc.io/quote
3+
stderr '^go: rsc.io/quote upgrade => v1.5.2\n\z'
4+
5+
# Downgrades are not reported.
6+
# TODO(golang.org/issue/33284): they should be.
7+
go get -d rsc.io/[email protected]
8+
stderr '^go: downloading.*\n\z'
9+
10+
-- go.mod --
11+
module m
12+
13+
go 1.15
14+
15+
require rsc.io/quote v1.5.0

0 commit comments

Comments
 (0)