Delete dead code kept alive only by its own tests · Entire
Delete dead code kept alive only by its own tests
27caaa5→main· 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
41 unmodified lines
42
43
44
45
45
46
47
903 unmodified lines
951
952
953
955
954
955
956
957
9 unmodified lines
967
968
969
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
970
971
972
41 unmodified lines
formatcfg "github.com/go-git/go-git/v6/plumbing/format/config"
"github.com/go-git/go-git/v6/plumbing/object"
"github.com/go-git/go-git/v6/plumbing/storer"
transporthttp "github.com/go-git/go-git/v6/plumbing/transport/http"
"github.com/go-git/go-git/v6/storage/filesystem"
gitsync "entire.io/entire/git-sync"
903 unmodified lines
SkipTLSVerify: req.SourceAuth.SkipTLSVerify,
}, ep)
httpClient := &http.Client{Transport: gitproto.NewHTTPTransport(req.SourceAuth.SkipTLSVerify)}
conn := gitproto.NewHTTPConnWithClient(ep, "source", normalizeAuth(authMethod), httpClient)
conn.FollowInfoRefsRedirect = req.SourceFollowInfoRefsRedirect
mode := string(req.ProtocolMode)
9 unmodified lines
return conn, svc, refs, nil
}
func normalizeAuth(m auth.Method) gitproto.AuthMethod {
if m == nil {
return nil
}
// auth.Method and gitproto.AuthMethod share the same Authorizer signature.
// Wrap so we can pass either *transporthttp.BasicAuth or *transporthttp.TokenAuth.
if a, ok := m.(*transporthttp.BasicAuth); ok {
return a
}
if a, ok := m.(*transporthttp.TokenAuth); ok {
return a
}
return authAdapter{m: m}
}
type authAdapter struct{ m auth.Method }
func (a authAdapter) Authorizer(req *http.Request) error {
if err := a.m.Authorizer(req); err != nil {
return fmt.Errorf("authorize request: %w", err)
}
return nil
}
// 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
Mcmd/git-sync/internal/sha256convert/sha256convert.go+1/-26
41 unmodified lines
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
48
49
50
41 unmodified lines
return out
}
// 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
}
// PlansToPushCommands converts planner BranchPlans directly to gitproto PushCommands.
// When forceBlind is true, non-delete commands send a zero expected-old so
// receive-pack overwrites regardless of current target value; see SyncPolicy.
Minternal/convert/convert.go-14
3 unmodified lines
4
5
6
7
8
7
8
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
9
10
11
3 unmodified lines
"errors"
"fmt"
"io"
"github.com/go-git/go-git/v6/plumbing"
// 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
}
// PushPlan is a minimal interface for plan-to-command conversion.
type PushPlan struct {
TargetRef plumbing.ReferenceName
TargetHash plumbing.Hash
SourceHash plumbing.Hash
Delete bool
}
// LimitPackReader wraps a ReadCloser with a byte limit. Shared across strategies.
func LimitPackReader(r io.ReadCloser, maxBytes int64) io.ReadCloser {
if maxBytes <= 0 {
Minternal/gitproto/convert.go-26
7 unmodified lines
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
11
12
13
7 unmodified lines
"github.com/go-git/go-git/v6/plumbing"
}
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)
}
}
}
}
}
func TestToPushCommandsMultiple(t *testing.T) {
plans := []PushPlan{
{TargetRef: "refs/heads/a", SourceHash: plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")},
{TargetRef: "refs/heads/b", SourceHash: plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")},
{TargetRef: "refs/heads/c", TargetHash: plumbing.NewHash("cccccccccccccccccccccccccccccccccccccccc"), Delete: true},
}
cmds := ToPushCommands(plans)
if len(cmds) != 3 {
t.Fatalf("expected 3 commands, got %d", len(cmds))
}
}
func TestToPushCommandsEmpty(t *testing.T) {
cmds := ToPushCommands(nil)
if len(cmds) != 0 {
t.Fatalf("expected 0 commands for nil input, got %d", len(cmds))
}
}
func TestLimitPackReaderWithinLimit(t *testing.T) {
data := "hello world"
rc := io.NopCloser(strings.NewReader(data))