From 07a8bcc71afb5814c00c7a7b19c29b0c493a18fd Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Sat, 27 Nov 2021 14:26:38 -0800 Subject: 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. --- storage/filesystem/dotgit/dotgit_test.go | 2 +- storage/filesystem/object_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'storage') diff --git a/storage/filesystem/dotgit/dotgit_test.go b/storage/filesystem/dotgit/dotgit_test.go index 4c2ae94..1db1a04 100644 --- a/storage/filesystem/dotgit/dotgit_test.go +++ b/storage/filesystem/dotgit/dotgit_test.go @@ -653,7 +653,7 @@ func (s *SuiteDotGit) TestObject(c *C) { fs.MkdirAll(incomingDirPath, os.FileMode(0755)) fs.Create(incomingFilePath) - file, err = dir.Object(plumbing.NewHash(incomingHash)) + _, err = dir.Object(plumbing.NewHash(incomingHash)) c.Assert(err, IsNil) } diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go index 59b40d3..9c5e31f 100644 --- a/storage/filesystem/object_test.go +++ b/storage/filesystem/object_test.go @@ -386,7 +386,7 @@ func (s *FsSuite) TestGetFromObjectFileSharedCache(c *C) { c.Assert(err, IsNil) c.Assert(obj.Hash(), Equals, expected) - obj, err = o2.EncodedObject(plumbing.CommitObject, expected) + _, err = o2.EncodedObject(plumbing.CommitObject, expected) c.Assert(err, Equals, plumbing.ErrObjectNotFound) } -- cgit From cde3a0d0318303df384d8441c2cc08ca645f8e6a Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Sat, 27 Nov 2021 16:18:48 -0800 Subject: storage/transactional: Use correct config in test The `cfg` loaded from `cs.Config` was unused. It looks like this assertion intended to validate that, not `temporalCfg`, which was already checked above this block. --- storage/transactional/config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'storage') diff --git a/storage/transactional/config_test.go b/storage/transactional/config_test.go index 1f3a572..34d7763 100644 --- a/storage/transactional/config_test.go +++ b/storage/transactional/config_test.go @@ -54,7 +54,7 @@ func (s *ConfigSuite) TestSetConfigTemporal(c *C) { cfg, err = cs.Config() c.Assert(err, IsNil) - c.Assert(temporalCfg.Core.Worktree, Equals, "bar") + c.Assert(cfg.Core.Worktree, Equals, "bar") } func (s *ConfigSuite) TestCommit(c *C) { -- cgit From 977668a25d210e8985a55ede0f2382a48b8ad2e2 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Sat, 27 Nov 2021 14:32:18 -0800 Subject: transactional/ReferenceStorage: Drop packRefs field The packRefs field is unused. It is assigned to true from the `PackRefs()` method, but because the method is not on the pointer type, the assignment has no effect. var st ReferenceStorage fmt.Println(st.packRefs) // false st.PackRefs() fmt.Println(st.packRefs) // false Delete the unused field. --- storage/transactional/reference.go | 4 ---- 1 file changed, 4 deletions(-) (limited to 'storage') diff --git a/storage/transactional/reference.go b/storage/transactional/reference.go index 3b009e2..1c09307 100644 --- a/storage/transactional/reference.go +++ b/storage/transactional/reference.go @@ -15,9 +15,6 @@ type ReferenceStorage struct { // commit is requested, the entries are added when RemoveReference is called // and deleted if SetReference is called. deleted map[plumbing.ReferenceName]struct{} - // packRefs if true PackRefs is going to be called in the based storer when - // commit is called. - packRefs bool } // NewReferenceStorage returns a new ReferenceStorer based on a base storer and @@ -108,7 +105,6 @@ func (r ReferenceStorage) CountLooseRefs() (int, error) { // PackRefs honors the storer.ReferenceStorer interface. func (r ReferenceStorage) PackRefs() error { - r.packRefs = true return nil } -- cgit From 0dcebfb72bbdaf01554f938402e699d67937c5a0 Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Sat, 4 Dec 2021 15:16:09 -0800 Subject: error strings: Don't capitalize, use periods, or newlines Per [Go Code Review Comments][1], > Error strings should not be capitalized (unless beginning with proper > nouns or acronyms) or end with punctuation staticcheck's [ST1005][2] also complains about these. For example, ``` object_walker.go:63:10: error strings should not be capitalized (ST1005) object_walker.go:101:10: error strings should not be capitalized (ST1005) object_walker.go:101:10: error strings should not end with punctuation or a newline (ST1005) plumbing/format/commitgraph/file.go:17:26: error strings should not be capitalized (ST1005) ``` This fixes all instances of this issue reported by staticcheck. [1]: https://github.com/golang/go/wiki/CodeReviewComments#error-strings [2]: https://staticcheck.io/docs/checks/#ST1005 --- storage/filesystem/dotgit/reader.go | 2 +- storage/memory/storage.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'storage') diff --git a/storage/filesystem/dotgit/reader.go b/storage/filesystem/dotgit/reader.go index a82ac94..975f92a 100644 --- a/storage/filesystem/dotgit/reader.go +++ b/storage/filesystem/dotgit/reader.go @@ -66,7 +66,7 @@ func (e *EncodedObject) Size() int64 { func (e *EncodedObject) SetSize(int64) {} func (e *EncodedObject) Writer() (io.WriteCloser, error) { - return nil, fmt.Errorf("Not supported") + return nil, fmt.Errorf("not supported") } func NewEncodedObject(dir *DotGit, h plumbing.Hash, t plumbing.ObjectType, size int64) *EncodedObject { diff --git a/storage/memory/storage.go b/storage/memory/storage.go index a8e5669..ef6a445 100644 --- a/storage/memory/storage.go +++ b/storage/memory/storage.go @@ -193,7 +193,7 @@ func (o *ObjectStorage) DeleteOldObjectPackAndIndex(plumbing.Hash, time.Time) er return nil } -var errNotSupported = fmt.Errorf("Not supported") +var errNotSupported = fmt.Errorf("not supported") func (o *ObjectStorage) LooseObjectTime(hash plumbing.Hash) (time.Time, error) { return time.Time{}, errNotSupported -- cgit From 1a8f803f55879b5d0cb40e88cb5981d64555c1aa Mon Sep 17 00:00:00 2001 From: Abhinav Gupta Date: Thu, 9 Dec 2021 21:42:38 -0800 Subject: storage: filesystem, switch from os.SEEK_* to io.Seek* (#421) The `os.SEEK_*` constants have been deprecated since Go 1.7. It is now recommended to use the equivalent `io.Seek*` constants. Switch `os.SEEK_CUR` to `io.SeekCurrent`, and `os.SEEK_SET` to `io.SeekStart`. --- storage/filesystem/dotgit/dotgit_test.go | 7 ++++--- storage/filesystem/object_test.go | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'storage') diff --git a/storage/filesystem/dotgit/dotgit_test.go b/storage/filesystem/dotgit/dotgit_test.go index 4c2ae94..1a09fde 100644 --- a/storage/filesystem/dotgit/dotgit_test.go +++ b/storage/filesystem/dotgit/dotgit_test.go @@ -3,6 +3,7 @@ package dotgit import ( "bufio" "encoding/hex" + "io" "io/ioutil" "os" "path/filepath" @@ -510,13 +511,13 @@ func (s *SuiteDotGit) TestObjectPackWithKeepDescriptors(c *C) { c.Assert(filepath.Ext(pack.Name()), Equals, ".pack") // Move to an specific offset - pack.Seek(42, os.SEEK_SET) + pack.Seek(42, io.SeekStart) pack2, err := dir.ObjectPack(plumbing.NewHash(f.PackfileHash)) c.Assert(err, IsNil) // If the file is the same the offset should be the same - offset, err := pack2.Seek(0, os.SEEK_CUR) + offset, err := pack2.Seek(0, io.SeekCurrent) c.Assert(err, IsNil) c.Assert(offset, Equals, int64(42)) @@ -527,7 +528,7 @@ func (s *SuiteDotGit) TestObjectPackWithKeepDescriptors(c *C) { c.Assert(err, IsNil) // If the file is opened again its offset should be 0 - offset, err = pack2.Seek(0, os.SEEK_CUR) + offset, err = pack2.Seek(0, io.SeekCurrent) c.Assert(err, IsNil) c.Assert(offset, Equals, int64(0)) diff --git a/storage/filesystem/object_test.go b/storage/filesystem/object_test.go index 59b40d3..1c3267b 100644 --- a/storage/filesystem/object_test.go +++ b/storage/filesystem/object_test.go @@ -71,7 +71,7 @@ func (s *FsSuite) TestGetFromPackfileKeepDescriptors(c *C) { pack1, err := dg.ObjectPack(packfiles[0]) c.Assert(err, IsNil) - pack1.Seek(42, os.SEEK_SET) + pack1.Seek(42, io.SeekStart) err = o.Close() c.Assert(err, IsNil) @@ -79,7 +79,7 @@ func (s *FsSuite) TestGetFromPackfileKeepDescriptors(c *C) { pack2, err := dg.ObjectPack(packfiles[0]) c.Assert(err, IsNil) - offset, err := pack2.Seek(0, os.SEEK_CUR) + offset, err := pack2.Seek(0, io.SeekCurrent) c.Assert(err, IsNil) c.Assert(offset, Equals, int64(0)) -- cgit