|
6 | 6 | package modget
|
7 | 7 |
|
8 | 8 | import (
|
| 9 | + "bytes" |
9 | 10 | "errors"
|
10 | 11 | "fmt"
|
| 12 | + "io" |
11 | 13 | "os"
|
12 | 14 | "path/filepath"
|
13 | 15 | "sort"
|
@@ -702,6 +704,12 @@ func runGet(cmd *base.Command, args []string) {
|
702 | 704 | modload.AllowWriteGoMod()
|
703 | 705 | modload.WriteGoMod()
|
704 | 706 |
|
| 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 | + |
705 | 713 | // If -d was specified, we're done after the module work.
|
706 | 714 | // We've already downloaded modules by loading packages above.
|
707 | 715 | // 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)
|
1034 | 1042 | return r.Reqs.Required(mod)
|
1035 | 1043 | }
|
1036 | 1044 |
|
1037 |
| -var loggedLines sync.Map |
| 1045 | +var updateLog struct { |
| 1046 | + mu sync.Mutex |
| 1047 | + buf bytes.Buffer |
| 1048 | + logged map[string]bool |
| 1049 | +} |
1038 | 1050 |
|
1039 | 1051 | func logOncef(format string, args ...interface{}) {
|
1040 | 1052 | 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 |
1043 | 1060 | }
|
| 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) |
1044 | 1069 | }
|
0 commit comments