package modget
import (
+ "bytes"
"errors"
"fmt"
+ "io"
"os"
"path/filepath"
"sort"
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
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)
}
--- /dev/null
+# 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