]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: group 'go get' update messages together near the end of output
authorJay Conrod <jayconrod@google.com>
Wed, 6 May 2020 16:59:18 +0000 (12:59 -0400)
committerJay Conrod <jayconrod@google.com>
Fri, 29 May 2020 20:55:14 +0000 (20:55 +0000)
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 <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/modget/get.go
src/cmd/go/testdata/script/mod_get_update_log.txt [new file with mode: 0644]

index 4c6982426fb0c4d34685d41ce523c1da55e44ec0..0bf9eb3a0485895567e3d8434d54b54e2e39019b 100644 (file)
@@ -6,8 +6,10 @@
 package modget
 
 import (
+       "bytes"
        "errors"
        "fmt"
+       "io"
        "os"
        "path/filepath"
        "sort"
@@ -702,6 +704,12 @@ func runGet(cmd *base.Command, args []string) {
        modload.AllowWriteGoMod()
        modload.WriteGoMod()
 
+       // Print the changes we made.
+       // TODO(golang.org/issue/33284): include more information about changes to
+       // relevant module versions due to MVS upgrades and downgrades. For now,
+       // the log only contains messages for versions resolved with getQuery.
+       writeUpdateLog()
+
        // If -d was specified, we're done after the module work.
        // We've already downloaded modules by loading packages above.
        // 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)
        return r.Reqs.Required(mod)
 }
 
-var loggedLines sync.Map
+var updateLog struct {
+       mu     sync.Mutex
+       buf    bytes.Buffer
+       logged map[string]bool
+}
 
 func logOncef(format string, args ...interface{}) {
        msg := fmt.Sprintf(format, args...)
-       if _, dup := loggedLines.LoadOrStore(msg, true); !dup {
-               fmt.Fprintln(os.Stderr, msg)
+       updateLog.mu.Lock()
+       defer updateLog.mu.Unlock()
+       if updateLog.logged == nil {
+               updateLog.logged = make(map[string]bool)
+       }
+       if updateLog.logged[msg] {
+               return
        }
+       updateLog.logged[msg] = true
+       fmt.Fprintln(&updateLog.buf, msg)
+}
+
+func writeUpdateLog() {
+       updateLog.mu.Lock()
+       defer updateLog.mu.Unlock()
+       io.Copy(os.Stderr, &updateLog.buf)
 }
diff --git a/src/cmd/go/testdata/script/mod_get_update_log.txt b/src/cmd/go/testdata/script/mod_get_update_log.txt
new file mode 100644 (file)
index 0000000..51f138f
--- /dev/null
@@ -0,0 +1,15 @@
+# Upgrades are reported.
+go get -d rsc.io/quote
+stderr '^go: rsc.io/quote upgrade => v1.5.2\n\z'
+
+# Downgrades are not reported.
+# TODO(golang.org/issue/33284): they should be.
+go get -d rsc.io/quote@v1.5.0
+stderr '^go: downloading.*\n\z'
+
+-- go.mod --
+module m
+
+go 1.15
+
+require rsc.io/quote v1.5.0