Fix golangci-lint findings · Entire
Fix golangci-lint findings
3744c8a→main
Soph·2mo ago·3 files·+25 added/-19 removed
Address errcheck, goconst, and ineffassign warnings surfaced by golangci-lint. Also picks up incidental gofmt realignment in bootstrap.go's Params struct.
Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com
Changes
3
internal
gitproto
Mfetch_test.go+6/-4
Mrefs_test.go+6/-2
strategy/bootstrap
Mbootstrap.go+13/-13
19 unmodified lines
20
21
22
23
24
25
26
27
202 unmodified lines
230
231
232
231
232
233
234
235
236
237
19 unmodified lines
257
258
259
258
260
261
262
261
263
264
265
266
19 unmodified lines
"github.com/stretchr/testify/require"
)
const refsHeadsMain = "refs/heads/main"
func TestCapabilities(t *testing.T) {
// v2 protocol
v2Caps := &V2Capabilities{
202 unmodified lines
if len(refs) != 2 {
t.Fatalf("expected 2 refs, got %d", len(refs))
}
if refs[0].Name().String() != "refs/heads/main" {
t.Errorf("refs[0].Name() = %q, want %q", refs[0].Name(), "refs/heads/main")
}
if refs[0].Name().String() != refsHeadsMain {
t.Errorf("refs[0].Name() = %q, want %q", refs[0].Name(), refsHeadsMain)
}
if refs[0].Hash().String() != "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" {
t.Errorf("refs[0].Hash() = %q", refs[0].Hash())
}
19 unmodified lines
if len(refs) != 1 {
t.Fatalf("expected 1 ref (HEAD filtered), got %d", len(refs))
}
if refs[0].Name().String() != "refs/heads/main" {
if refs[0].Name().String() != refsHeadsMain {
t.Errorf("refs[0].Name() = %q, want refs/heads/main", refs[0].Name())
}
if head.String() != "refs/heads/main" {
if head.String() != refsHeadsMain {
t.Errorf("head target = %q, want refs/heads/main", head)
}
}
Minternal/gitproto/fetch_test.go+6/-4
49 unmodified lines
50
51
52
53
53
54
55
56
57
58
59
60
61
60
62
63
64
65
66
67
49 unmodified lines
}
adv := packp.NewAdvRefs()
_ = adv.Capabilities.Add(capability.SymRef, "HEAD:refs/heads/main")
if err := adv.Capabilities.Add(capability.SymRef, "HEAD:refs/heads/main"); err != nil {
t.Fatalf("Capabilities.Add: %v", err)
}
if got := headTargetFromAdv(adv); got.String() != "refs/heads/main" {
t.Errorf("headTargetFromAdv = %q, want refs/heads/main", got)
}
// Symref pointing at something other than HEAD is ignored.
adv = packp.NewAdvRefs()
_ = adv.Capabilities.Add(capability.SymRef, "refs/remotes/origin/HEAD:refs/heads/main")
if err := adv.Capabilities.Add(capability.SymRef, "refs/remotes/origin/HEAD:refs/heads/main"); err != nil {
t.Fatalf("Capabilities.Add: %v", err)
}
if got := headTargetFromAdv(adv); got != "" {
t.Errorf("headTargetFromAdv ignored non-HEAD symref = %q, want empty", got)
}
Minternal/gitproto/refs_test.go+6/-2
49 unmodified lines
50
51
52
53
54
53
54
55
56
57
58
59
60
61
62
59
60
61
62
63
64
65
516 unmodified lines
582
583
584
585
585
586
587
588
589
23 unmodified lines
613
614
615
615
616
617
618
618
619
620
621
622
623
624
3 unmodified lines
628
629
630
628
629
630
631
631
632
633
634
49 unmodified lines
PushPack(ctx context.Context, cmds []gitproto.PushCommand, pack io.ReadCloser) error
PushCommands(ctx context.Context, cmds []gitproto.PushCommand) error
}
DesiredRefs map[plumbing.ReferenceName]planner.DesiredRef
TargetRefs map[plumbing.ReferenceName]plumbing.Hash
DesiredRefs map[plumbing.ReferenceName]planner.DesiredRef
TargetRefs map[plumbing.ReferenceName]plumbing.Hash
// SourceHeadTarget is the source ref that HEAD points to, when advertised.
// Empty if unknown. When set, batched bootstrap plans this branch first and
// uses its commit-graph reachability as a cutoff for subsequent branches.
SourceHeadTarget plumbing.ReferenceName
MaxPackBytes int64
TargetMaxPack int64
Verbose bool
Logger *slog.Logger
MaxPackBytes int64
TargetMaxPack int64
Verbose bool
Logger *slog.Logger
}
// Result holds the outcome of the bootstrap strategy.
516 unmodified lines
// their stop set. We only need the keys — ~8 bytes per commit, so the
// linux ancestry set is ~11 MB vs the store's ~4.6 GB.
ancestors := collectCommitHashes(graphStore)
graphStore = nil // allow GC to reclaim the commit graph store
// graphStore is unused beyond this point; runtime.GC reclaims its
// transient allocations before we move on to the next branch.
runtime.GC()
if len(chain) == 0 {
23 unmodified lines
}
defer iter.Close()
out := map[plumbing.Hash]struct{}{}
_ = iter.ForEach(func(obj plumbing.EncodedObject) error {
if err := iter.ForEach(func(obj plumbing.EncodedObject) error {
out[obj.Hash()] = struct{}{}
return nil
}){if err != nil {
return nil
}
return out
}
}
3 unmodified lines
}
estimated := chainLen * estimatedBytesPerCommit
n := int((estimated + batchMaxPack - 1) / batchMaxPack)
if n < 1 {
n = 1
}
return n
return max(n, 1)
// estimatedBytesPerObject is a conservative average for compressed git objects