Skip to content

Commit 07a8bcc

Browse files
committed
Remove unused variables/types/functions
[staticcheck](https://staticcheck.io/) reported a number of unused fields, functions, types, and variables across the code. Where possible, use them (assert unchecked errors in tests, for example) and otherwise remove them.
1 parent e4fcd07 commit 07a8bcc

File tree

20 files changed

+12
-85
lines changed

20 files changed

+12
-85
lines changed

common_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/go-git/go-git/v5/plumbing"
88
"github.com/go-git/go-git/v5/plumbing/cache"
99
"github.com/go-git/go-git/v5/plumbing/format/packfile"
10-
"github.com/go-git/go-git/v5/plumbing/transport"
1110
"github.com/go-git/go-git/v5/storage/filesystem"
1211
"github.com/go-git/go-git/v5/storage/memory"
1312

@@ -25,8 +24,7 @@ type BaseSuite struct {
2524
fixtures.Suite
2625
Repository *Repository
2726

28-
backupProtocol transport.Transport
29-
cache map[string]*Repository
27+
cache map[string]*Repository
3028
}
3129

3230
func (s *BaseSuite) SetUpSuite(c *C) {

config/config_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func (s *ConfigSuite) TestRemoveUrlOptions(c *C) {
361361
cfg.Remotes["alt"].URLs = []string{}
362362

363363
buf, err = cfg.Marshal()
364+
c.Assert(err, IsNil)
364365
if strings.Contains(string(buf), "url") {
365366
c.Fatal("conifg should not contain any url sections")
366367
}

plumbing/format/packfile/fsobject.go

-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
// FSObject is an object from the packfile on the filesystem.
1414
type FSObject struct {
1515
hash plumbing.Hash
16-
h *ObjectHeader
1716
offset int64
1817
size int64
1918
typ plumbing.ObjectType
@@ -118,17 +117,3 @@ func (o *FSObject) Type() plumbing.ObjectType {
118117
func (o *FSObject) Writer() (io.WriteCloser, error) {
119118
return nil, nil
120119
}
121-
122-
type objectReader struct {
123-
io.ReadCloser
124-
f billy.File
125-
}
126-
127-
func (r *objectReader) Close() error {
128-
if err := r.ReadCloser.Close(); err != nil {
129-
_ = r.f.Close()
130-
return err
131-
}
132-
133-
return r.f.Close()
134-
}

plumbing/format/packfile/packfile_test.go

-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/go-git/go-git/v5/plumbing"
99
"github.com/go-git/go-git/v5/plumbing/format/idxfile"
1010
"github.com/go-git/go-git/v5/plumbing/format/packfile"
11-
"github.com/go-git/go-git/v5/plumbing/storer"
1211
. "gopkg.in/check.v1"
1312
)
1413

@@ -236,22 +235,6 @@ var expectedHashes = []string{
236235
"7e59600739c96546163833214c36459e324bad0a",
237236
}
238237

239-
func assertObjects(c *C, s storer.EncodedObjectStorer, expects []string) {
240-
i, err := s.IterEncodedObjects(plumbing.AnyObject)
241-
c.Assert(err, IsNil)
242-
243-
var count int
244-
err = i.ForEach(func(plumbing.EncodedObject) error { count++; return nil })
245-
c.Assert(err, IsNil)
246-
c.Assert(count, Equals, len(expects))
247-
248-
for _, exp := range expects {
249-
obt, err := s.EncodedObject(plumbing.AnyObject, plumbing.NewHash(exp))
250-
c.Assert(err, IsNil)
251-
c.Assert(obt.Hash().String(), Equals, exp)
252-
}
253-
}
254-
255238
func getIndexFromIdxFile(r io.Reader) idxfile.Index {
256239
idx := idxfile.NewMemoryIndex()
257240
if err := idxfile.NewDecoder(r).Decode(idx); err != nil {

plumbing/format/packfile/parser.go

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ type Parser struct {
4646
oi []*objectInfo
4747
oiByHash map[plumbing.Hash]*objectInfo
4848
oiByOffset map[int64]*objectInfo
49-
hashOffset map[plumbing.Hash]int64
5049
checksum plumbing.Hash
5150

5251
cache *cache.BufferLRU

plumbing/object/patch.go

-4
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ func filePatchWithContext(ctx context.Context, c *Change) (fdiff.FilePatch, erro
9696

9797
}
9898

99-
func filePatch(c *Change) (fdiff.FilePatch, error) {
100-
return filePatchWithContext(context.Background(), c)
101-
}
102-
10399
func fileContent(f *File) (content string, isBinary bool, err error) {
104100
if f == nil {
105101
return

plumbing/protocol/packp/common.go

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ var (
1919
// common
2020
sp = []byte(" ")
2121
eol = []byte("\n")
22-
eq = []byte{'='}
2322

2423
// advertised-refs
2524
null = []byte("\x00")

plumbing/protocol/packp/updreq_encode.go

-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
"github.com/go-git/go-git/v5/plumbing/protocol/packp/capability"
1010
)
1111

12-
var (
13-
zeroHashString = plumbing.ZeroHash.String()
14-
)
15-
1612
// Encode writes the ReferenceUpdateRequest encoding to the stream.
1713
func (req *ReferenceUpdateRequest) Encode(w io.Writer) error {
1814
if err := req.validate(); err != nil {

plumbing/protocol/packp/uppackresp.go

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ type UploadPackResponse struct {
2424
r io.ReadCloser
2525
isShallow bool
2626
isMultiACK bool
27-
isOk bool
2827
}
2928

3029
// NewUploadPackResponse create a new UploadPackResponse instance, the request

plumbing/revlist/revlist_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ func (s *RevListSuite) SetUpTest(c *C) {
5555
s.Storer = sto
5656
}
5757

58-
func (s *RevListSuite) commit(c *C, h plumbing.Hash) *object.Commit {
59-
commit, err := object.GetCommit(s.Storer, h)
60-
c.Assert(err, IsNil)
61-
return commit
62-
}
63-
6458
func (s *RevListSuite) TestRevListObjects_Submodules(c *C) {
6559
submodules := map[string]bool{
6660
"6ecf0ef2c2dffb796033e5a02219af86ec6584e5": true,

plumbing/transport/client/client_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package client
22

33
import (
4-
"fmt"
54
"net/http"
65
"testing"
76

@@ -68,7 +67,3 @@ func (*dummyClient) NewReceivePackSession(*transport.Endpoint, transport.AuthMet
6867
transport.ReceivePackSession, error) {
6968
return nil, nil
7069
}
71-
72-
func typeAsString(v interface{}) string {
73-
return fmt.Sprintf("%T", v)
74-
}

plumbing/transport/internal/common/common.go

-5
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,6 @@ func isRepoNotFoundError(s string) bool {
428428
return false
429429
}
430430

431-
var (
432-
nak = []byte("NAK")
433-
eol = []byte("\n")
434-
)
435-
436431
// uploadPack implements the git-upload-pack protocol.
437432
func uploadPack(w io.WriteCloser, r io.Reader, req *packp.UploadPackRequest) error {
438433
// TODO support multi_ack mode

plumbing/transport/ssh/common_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/kevinburke/ssh_config"
99
"golang.org/x/crypto/ssh"
10-
stdssh "golang.org/x/crypto/ssh"
1110
. "gopkg.in/check.v1"
1211
)
1312

@@ -99,7 +98,7 @@ func (s *SuiteCommon) TestIssue70(c *C) {
9998
uploadPack.SetUpSuite(c)
10099

101100
config := &ssh.ClientConfig{
102-
HostKeyCallback: stdssh.InsecureIgnoreHostKey(),
101+
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
103102
}
104103
r := &runner{
105104
config: config,

remote.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func (r *Remote) addReachableTags(localRefs []*plumbing.Reference, remoteRefs st
256256
return err
257257
}
258258

259-
for tag, _ := range tags {
259+
for tag := range tags {
260260
tagObject, err := object.GetObject(r.s, tag.Hash())
261261
var tagCommit *object.Commit
262262
if err != nil {

remote_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ func (s *RemoteSuite) TestPushPrune(c *C) {
875875
"refs/remotes/origin/master": ref.Hash().String(),
876876
})
877877

878-
ref, err = server.Reference(plumbing.ReferenceName("refs/tags/v1.0.0"), true)
878+
_, err = server.Reference(plumbing.ReferenceName("refs/tags/v1.0.0"), true)
879879
c.Assert(err, Equals, plumbing.ErrReferenceNotFound)
880880
}
881881

storage/filesystem/dotgit/dotgit_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ func (s *SuiteDotGit) TestObject(c *C) {
653653
fs.MkdirAll(incomingDirPath, os.FileMode(0755))
654654
fs.Create(incomingFilePath)
655655

656-
file, err = dir.Object(plumbing.NewHash(incomingHash))
656+
_, err = dir.Object(plumbing.NewHash(incomingHash))
657657
c.Assert(err, IsNil)
658658
}
659659

storage/filesystem/object_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func (s *FsSuite) TestGetFromObjectFileSharedCache(c *C) {
386386
c.Assert(err, IsNil)
387387
c.Assert(obj.Hash(), Equals, expected)
388388

389-
obj, err = o2.EncodedObject(plumbing.CommitObject, expected)
389+
_, err = o2.EncodedObject(plumbing.CommitObject, expected)
390390
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
391391
}
392392

utils/merkletrie/noder/noder_test.go

-14
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,6 @@ func childrenFixture() []Noder {
5757
return []Noder{c1, c2}
5858
}
5959

60-
// Returns the same as nodersFixture but sorted by name, this is: "1",
61-
// "2" and then "3".
62-
func sortedNodersFixture() []Noder {
63-
n1 := &noderMock{
64-
name: "1",
65-
hash: []byte{0x00, 0x01, 0x02},
66-
isDir: true,
67-
children: childrenFixture(),
68-
}
69-
n2 := &noderMock{name: "2"}
70-
n3 := &noderMock{name: "3"}
71-
return []Noder{n1, n2, n3} // the same as nodersFixture but sorted by name
72-
}
73-
7460
// returns nodersFixture as the path of "1".
7561
func pathFixture() Path {
7662
return Path(nodersFixture())

worktree_commit_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@ func (s *WorktreeSuite) TestCommitTreeSort(c *C) {
212212
defer clean()
213213

214214
st := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
215-
r, err := Init(st, nil)
215+
_, err := Init(st, nil)
216216
c.Assert(err, IsNil)
217217

218-
r, _ = Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
218+
r, _ := Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
219219
URL: fs.Root(),
220220
})
221221

@@ -296,6 +296,7 @@ func (s *WorktreeSuite) TestJustStoreObjectsNotAlreadyStored(c *C) {
296296
All: true,
297297
Author: defaultSignature(),
298298
})
299+
c.Assert(err, IsNil)
299300
c.Assert(hash, Equals, plumbing.NewHash("97c0c5177e6ac57d10e8ea0017f2d39b91e2b364"))
300301

301302
// Step 3: Check

worktree_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *WorktreeSuite) TestPullInSingleBranch(c *C) {
183183
c.Assert(err, IsNil)
184184
c.Assert(branch.Hash().String(), Equals, "6ecf0ef2c2dffb796033e5a02219af86ec6584e5")
185185

186-
branch, err = r.Reference("refs/remotes/foo/branch", false)
186+
_, err = r.Reference("refs/remotes/foo/branch", false)
187187
c.Assert(err, NotNil)
188188

189189
storage := r.Storer.(*memory.Storage)
@@ -555,6 +555,7 @@ func (s *WorktreeSuite) TestCheckoutRelativePathSubmoduleInitialized(c *C) {
555555

556556
// test submodule path
557557
modules, err := w.readGitmodulesFile()
558+
c.Assert(err, IsNil)
558559

559560
c.Assert(modules.Submodules["basic"].URL, Equals, "../basic.git")
560561
c.Assert(modules.Submodules["itself"].URL, Equals, "../submodule.git")

0 commit comments

Comments
 (0)