From 8ed263c6dd1eebed28e8bf0a84d11d382b4c8ca0 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Wed, 22 Jul 2026 22:25:56 +0200 Subject: [PATCH] Apply go fix -minmax ./... --- cmd/restic/cmd_stats.go | 5 +---- helpers/build-release-binaries/main.go | 5 +---- internal/filter/filter.go | 6 +----- internal/repository/pack/pack_internal_test.go | 5 +---- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/cmd/restic/cmd_stats.go b/cmd/restic/cmd_stats.go index a4e2175c1..bac1e11f5 100644 --- a/cmd/restic/cmd_stats.go +++ b/cmd/restic/cmd_stats.go @@ -446,10 +446,7 @@ func newSizeHistogram(sizeLimit uint64) *sizeHistogram { growthFactor := uint64(10) for lowerBound < sizeLimit { - upperBound := lowerBound*growthFactor - 1 - if upperBound > sizeLimit { - upperBound = sizeLimit - } + upperBound := min(lowerBound*growthFactor-1, sizeLimit) h.buckets = append(h.buckets, sizeClass{lowerBound, upperBound, 0}) lowerBound *= growthFactor } diff --git a/helpers/build-release-binaries/main.go b/helpers/build-release-binaries/main.go index 0a1358c31..f2468145d 100644 --- a/helpers/build-release-binaries/main.go +++ b/helpers/build-release-binaries/main.go @@ -207,10 +207,7 @@ func buildForTarget(sourceDir, outputDir, goos, goarch string) (filename string) func buildTargets(sourceDir, outputDir string, targets map[string][]string) { start := time.Now() // the go compiler is already parallelized, thus reduce the concurrency a bit - workers := runtime.GOMAXPROCS(0) / 4 - if workers < 1 { - workers = 1 - } + workers := max(runtime.GOMAXPROCS(0)/4, 1) msg("building with %d workers", workers) type Job struct{ GOOS, GOARCH string } diff --git a/internal/filter/filter.go b/internal/filter/filter.go index c2b5f98ce..266ca5a98 100644 --- a/internal/filter/filter.go +++ b/internal/filter/filter.go @@ -131,11 +131,7 @@ func childMatch(pattern Pattern, strs []string) (matched bool, err error) { // match path against absolute pattern prefix l := 0 - if len(strs) > len(pattern.parts) { - l = len(pattern.parts) - } else { - l = len(strs) - } + l = min(len(strs), len(pattern.parts)) return match(Pattern{pattern.original, pattern.parts[0:l], pattern.isNegated}, strs) } diff --git a/internal/repository/pack/pack_internal_test.go b/internal/repository/pack/pack_internal_test.go index 8c4c37b9c..bbac5352a 100644 --- a/internal/repository/pack/pack_internal_test.go +++ b/internal/repository/pack/pack_internal_test.go @@ -132,10 +132,7 @@ func TestReadRecords(t *testing.T) { testReadRecords := func(dataSize, entryCount, totalRecords int) { totalHeader := rtest.Random(0, totalRecords*int(entrySize)+crypto.Extension) bufSize := entryCount*int(entrySize) + crypto.Extension - off := len(totalHeader) - bufSize - if off < 0 { - off = 0 - } + off := max(len(totalHeader)-bufSize, 0) expectedHeader := totalHeader[off:] buf := &bytes.Buffer{}