summaryrefslogtreecommitdiff
path: root/libgo/go/cmd/go/internal/fmtcmd/fmt.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/cmd/go/internal/fmtcmd/fmt.go')
-rw-r--r--libgo/go/cmd/go/internal/fmtcmd/fmt.go36
1 files changed, 18 insertions, 18 deletions
diff --git a/libgo/go/cmd/go/internal/fmtcmd/fmt.go b/libgo/go/cmd/go/internal/fmtcmd/fmt.go
index 8a040087539..19656eab7fc 100644
--- a/libgo/go/cmd/go/internal/fmtcmd/fmt.go
+++ b/libgo/go/cmd/go/internal/fmtcmd/fmt.go
@@ -11,14 +11,12 @@ import (
"fmt"
"os"
"path/filepath"
- "runtime"
- "sync"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
"cmd/go/internal/load"
"cmd/go/internal/modload"
- "cmd/go/internal/str"
+ "cmd/internal/sys"
)
func init() {
@@ -53,18 +51,13 @@ See also: go fix, go vet.
func runFmt(ctx context.Context, cmd *base.Command, args []string) {
printed := false
gofmt := gofmtPath()
- procs := runtime.GOMAXPROCS(0)
- var wg sync.WaitGroup
- wg.Add(procs)
- fileC := make(chan string, 2*procs)
- for i := 0; i < procs; i++ {
- go func() {
- defer wg.Done()
- for file := range fileC {
- base.Run(str.StringList(gofmt, "-l", "-w", file))
- }
- }()
- }
+
+ gofmtArgs := []string{gofmt, "-l", "-w"}
+ gofmtArgLen := len(gofmt) + len(" -l -w")
+
+ baseGofmtArgs := len(gofmtArgs)
+ baseGofmtArgLen := gofmtArgLen
+
for _, pkg := range load.PackagesAndErrors(ctx, load.PackageOpts{}, args) {
if modload.Enabled() && pkg.Module != nil && !pkg.Module.Main {
if !printed {
@@ -89,11 +82,18 @@ func runFmt(ctx context.Context, cmd *base.Command, args []string) {
// not to packages in subdirectories.
files := base.RelPaths(pkg.InternalAllGoFiles())
for _, file := range files {
- fileC <- file
+ gofmtArgs = append(gofmtArgs, file)
+ gofmtArgLen += 1 + len(file) // plus separator
+ if gofmtArgLen >= sys.ExecArgLengthLimit {
+ base.Run(gofmtArgs)
+ gofmtArgs = gofmtArgs[:baseGofmtArgs]
+ gofmtArgLen = baseGofmtArgLen
+ }
}
}
- close(fileC)
- wg.Wait()
+ if len(gofmtArgs) > baseGofmtArgs {
+ base.Run(gofmtArgs)
+ }
}
func gofmtPath() string {