From 195447b77ff5fc37e184d2d0e7aae99aec250d8c Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 6 Mar 2026 13:11:56 +0800 Subject: *: go fix ./... --- format/commitgraph/read/read_test.go | 10 ++-------- format/pack/ingest/stream.go | 5 +---- internal/compress/flate/example_test.go | 12 ++++-------- internal/testgit/repo_make_many_objects_history.go | 2 +- 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/format/commitgraph/read/read_test.go b/format/commitgraph/read/read_test.go index 0efd67ca..80091c5b 100644 --- a/format/commitgraph/read/read_test.go +++ b/format/commitgraph/read/read_test.go @@ -76,10 +76,7 @@ func TestReadSingleMatchesGit(t *testing.T) { } } - step := len(allIDs) / 24 - if step < 1 { - step = 1 - } + step := max(len(allIDs)/24, 1) for i, id := range allIDs { if i%step != 0 && i != len(allIDs)-1 { @@ -117,10 +114,7 @@ func TestReadChainMatchesGit(t *testing.T) { t.Fatalf("NumCommits() = %d, want %d", got, len(allIDs)) } - step := len(allIDs) / 20 - if step < 1 { - step = 1 - } + step := max(len(allIDs)/20, 1) for i, id := range allIDs { pos, err := reader.Lookup(id) diff --git a/format/pack/ingest/stream.go b/format/pack/ingest/stream.go index 66a6fc5f..a403087a 100644 --- a/format/pack/ingest/stream.go +++ b/format/pack/ingest/stream.go @@ -69,10 +69,7 @@ func (scanner *streamScanner) Read(dst []byte) (int, error) { return 0, io.EOF } - n := len(dst) - if n > unread { - n = unread - } + n := min(len(dst), unread) copy(dst, scanner.buf[scanner.off:scanner.off+n]) diff --git a/internal/compress/flate/example_test.go b/internal/compress/flate/example_test.go index d541e0e1..ead6d090 100644 --- a/internal/compress/flate/example_test.go +++ b/internal/compress/flate/example_test.go @@ -166,9 +166,7 @@ func Example_synchronization() { rp, wp := io.Pipe() // Start a goroutine to act as the transmitter. - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { defer wp.Close() zw, err := flate.NewWriter(wp, flate.BestSpeed) @@ -195,12 +193,10 @@ func Example_synchronization() { if err := zw.Close(); err != nil { log.Fatal(err) } - }() + }) // Start a goroutine to act as the receiver. - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { zr := flate.NewReader(rp) @@ -229,7 +225,7 @@ func Example_synchronization() { if err := zr.Close(); err != nil { log.Fatal(err) } - }() + }) // Output: // Received 1 bytes: A diff --git a/internal/testgit/repo_make_many_objects_history.go b/internal/testgit/repo_make_many_objects_history.go index 17cce1ad..970d1992 100644 --- a/internal/testgit/repo_make_many_objects_history.go +++ b/internal/testgit/repo_make_many_objects_history.go @@ -74,7 +74,7 @@ func (testRepo *TestRepo) makeManyObjectsTree(tb testing.TB, prefix string, i in lines := make([]string, 0, files) for j := range files { - body := []byte(fmt.Sprintf("%s-%04d-%02d\n%s\n", prefix, i, j, strings.Repeat("x", 160+(i+j)%96))) + body := fmt.Appendf(nil, "%s-%04d-%02d\n%s\n", prefix, i, j, strings.Repeat("x", 160+(i+j)%96)) blobID := testRepo.HashObject(tb, "blob", body) lines = append(lines, fmt.Sprintf("100644 blob %s\t%s_%04d_%02d.txt\n", blobID.String(), prefix, i, j)) } -- cgit v1.3.1-10-gc9f91