Delete dead code kept alive only by its own tests · Entire
Delete dead code kept alive only by its own tests
5933369· Soph·2w ago·14 files·+16 added/-555 removed
Remove code with no production callers, verified by repo-wide search:
- planner: DesiredSubset, SingleDesired, SingleHaveMap, and FirstParentChainFromMap (superseded by FirstParentChainFromParents) had no references at all.
- gitproto: PushPlan/ToPushCommands and convert.PlansToPushPlans formed a parallel plan-conversion path; every strategy uses convert.PlansToPushCommands directly. The TestPlansToPushPlans copies in incremental and materialized were identical and tested only this dead path.
- gitproto: FetchCommitGraph was superseded by FetchCommitParents (same wire protocol, lower memory); its capability-guard tests now cover FetchCommitParents, which had no direct tests.
- gitproto: progressWriter (superseded by progressSink) and HashHex were referenced only from tests.
- gitproto: FetchFeatures existed to carry one bit consumed by SupportsBootstrapBatch plus a write-only IncludeTag field; inline the filter check.
- sha256convert: normalizeAuth/authAdapter converted between two structurally identical interfaces (auth.Method and gitproto.AuthMethod); the value is directly assignable and the adapter branch was unreachable since auth.Resolve only returns the two concrete types the switch already passed through.
- syncer: newProbeResult assigned Stats/Measurement twice.
Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Sessions
9c1282a34a36View transcript
Changes
14
cmd/git-sync/internal/sha256convert
Msha256convert.go+1/-26
internal
convert
Mconvert.go-14
gitproto
Mconvert.go-26 - Mconvert_test.go-85 - Mfetch.go+5/-63 - Mfetch_test.go+10/-34 - Mpktline.go-6 - Mpktline_test.go-27 - Mpush.go-10
planner
Mcheckpoint.go-28 - Mtypes.go-37
strategy
incremental
Mincremental_test.go-98
materialized
Mmaterialized_test.go-99
syncer
Msyncer.go-2
// translator walks the SHA1 source store, rewrites object content with // SHA256-mapped hashes, and writes the result into the target bare repo // via SetEncodedObject. The target storer is configured for SHA256 (see
// PlansToPushPlans converts planner BranchPlans to gitproto PushPlans. func PlansToPushPlans(plans []planner.BranchPlan) []gitproto.PushPlan { out := make([]gitproto.PushPlan, len(plans)) for i, p := range plans { out[i] = gitproto.PushPlan{ TargetRef: p.TargetRef, TargetHash: p.TargetHash, SourceHash: p.SourceHash, Delete: p.Action == planner.ActionDelete, } } return out }
// ToPushCommands converts a slice of PushPlans to PushCommands. // Used by all strategy packages to avoid copy-pasting the conversion. func ToPushCommands(plans []PushPlan) []PushCommand { cmds := make([]PushCommand, 0, len(plans)) for _, p := range plans { cmd := PushCommand{Name: p.TargetRef, Old: p.TargetHash} if p.Delete { cmd.Delete = true } else { cmd.New = p.SourceHash } cmds = append(cmds, cmd) } return cmds }
func TestToPushCommands(t *testing.T) { hashA := plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") hashB := plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")
tests := []struct { name string plan PushPlan wantNew plumbing.Hash wantOld plumbing.Hash wantDelete bool }{ { name: "create command", plan: PushPlan{ TargetRef: "refs/heads/main", TargetHash: plumbing.ZeroHash, SourceHash: hashA, }, wantNew: hashA, wantOld: plumbing.ZeroHash, }, { name: "update command", plan: PushPlan{ TargetRef: "refs/heads/main", TargetHash: hashA, SourceHash: hashB, }, wantNew: hashB, wantOld: hashA, }, { name: "delete command", plan: PushPlan{ TargetRef: "refs/heads/old-branch", TargetHash: hashA, Delete: true, }, wantOld: hashA, wantDelete: true, }, }
for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cmds := ToPushCommands([]PushPlan{tt.plan}) if len(cmds) != 1 { t.Fatalf("expected 1 command, got %d", len(cmds)) } cmd := cmds[0] if cmd.Name != tt.plan.TargetRef { t.Errorf("Name = %s, want %s", cmd.Name, tt.plan.TargetRef) } if cmd.Old != tt.wantOld { t.Errorf("Old = %s, want %s", cmd.Old, tt.wantOld) } if cmd.Delete != tt.wantDelete { t.Errorf("Delete = %v, want %v", cmd.Delete, tt.wantDelete) } if !tt.wantDelete && cmd.New != tt.wantNew { t.Errorf("New = %s, want %s", cmd.New, tt.wantNew) } }) } }
// FetchFeatures summarizes negotiated source fetch features used by strategies. func (s *RefService) FetchFeatures() FetchFeatures { if s == nil || s.Protocol != "v2" || s.V2Caps == nil { return FetchFeatures{} } return FetchFeatures{ Filter: s.V2Caps.FetchSupports("filter"), IncludeTag: s.V2Caps.FetchSupports("include-tag"), } } // FetchCommitGraph fetches only the commit graph (tree:0 filter) for a ref. // Requires v2 with filter support.