From a99446e290f038900b893e21362c6ff766c30f5e Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Mon, 6 Jul 2020 17:40:53 +0200 Subject: Minor linter fixes --- internal/revision/parser.go | 6 +++--- plumbing/filemode/filemode.go | 2 +- plumbing/format/index/decoder.go | 2 +- plumbing/object/change.go | 2 +- plumbing/protocol/packp/capability/list.go | 5 +---- remote.go | 9 +++------ repository.go | 12 ++++++------ repository_test.go | 2 +- storage/transactional/reference.go | 2 +- worktree_bsd.go | 2 +- 10 files changed, 19 insertions(+), 25 deletions(-) diff --git a/internal/revision/parser.go b/internal/revision/parser.go index 61de386..432ffd1 100644 --- a/internal/revision/parser.go +++ b/internal/revision/parser.go @@ -297,7 +297,7 @@ func (p *Parser) parseAt() (Revisioner, error) { } if t != cbrace { - return nil, &ErrInvalidRevision{fmt.Sprintf(`missing "}" in @{-n} structure`)} + return nil, &ErrInvalidRevision{s: `missing "}" in @{-n} structure`} } return AtCheckout{n}, nil @@ -419,7 +419,7 @@ func (p *Parser) parseCaretBraces() (Revisioner, error) { case re == "" && tok == emark && nextTok == minus: negate = true case re == "" && tok == emark: - return nil, &ErrInvalidRevision{fmt.Sprintf(`revision suffix brace component sequences starting with "/!" others than those defined are reserved`)} + return nil, &ErrInvalidRevision{s: `revision suffix brace component sequences starting with "/!" others than those defined are reserved`} case re == "" && tok == slash: p.unscan() case tok != slash && start: @@ -490,7 +490,7 @@ func (p *Parser) parseColonSlash() (Revisioner, error) { case re == "" && tok == emark && nextTok == minus: negate = true case re == "" && tok == emark: - return nil, &ErrInvalidRevision{fmt.Sprintf(`revision suffix brace component sequences starting with "/!" others than those defined are reserved`)} + return nil, &ErrInvalidRevision{s: `revision suffix brace component sequences starting with "/!" others than those defined are reserved`} case tok == eof: p.unscan() reg, err := regexp.Compile(re) diff --git a/plumbing/filemode/filemode.go b/plumbing/filemode/filemode.go index 594984f..b848a97 100644 --- a/plumbing/filemode/filemode.go +++ b/plumbing/filemode/filemode.go @@ -118,7 +118,7 @@ func isSetSymLink(m os.FileMode) bool { func (m FileMode) Bytes() []byte { ret := make([]byte, 4) binary.LittleEndian.PutUint32(ret, uint32(m)) - return ret[:] + return ret } // IsMalformed returns if the FileMode should not appear in a git packfile, diff --git a/plumbing/format/index/decoder.go b/plumbing/format/index/decoder.go index d341d59..036b636 100644 --- a/plumbing/format/index/decoder.go +++ b/plumbing/format/index/decoder.go @@ -188,7 +188,7 @@ func (d *Decoder) doReadEntryNameV4() (string, error) { func (d *Decoder) doReadEntryName(len uint16) (string, error) { name := make([]byte, len) - _, err := io.ReadFull(d.r, name[:]) + _, err := io.ReadFull(d.r, name) return string(name), err } diff --git a/plumbing/object/change.go b/plumbing/object/change.go index c9d1615..8b119bc 100644 --- a/plumbing/object/change.go +++ b/plumbing/object/change.go @@ -75,7 +75,7 @@ func (c *Change) Files() (from, to *File, err error) { func (c *Change) String() string { action, err := c.Action() if err != nil { - return fmt.Sprintf("malformed change") + return "malformed change" } return fmt.Sprintf("", action, c.name()) diff --git a/plumbing/protocol/packp/capability/list.go b/plumbing/protocol/packp/capability/list.go index 9609211..f41ec79 100644 --- a/plumbing/protocol/packp/capability/list.go +++ b/plumbing/protocol/packp/capability/list.go @@ -86,10 +86,7 @@ func (l *List) Get(capability Capability) []string { // Set sets a capability removing the previous values func (l *List) Set(capability Capability, values ...string) error { - if _, ok := l.m[capability]; ok { - delete(l.m, capability) - } - + delete(l.m, capability) return l.Add(capability, values...) } diff --git a/remote.go b/remote.go index e642c57..bc370e6 100644 --- a/remote.go +++ b/remote.go @@ -498,10 +498,8 @@ func (r *Remote) deleteReferences(rs config.RefSpec, if _, ok := refsDict[rs.Dst(ref.Name()).String()]; ok { return nil } - } else { - if rs.Dst("") != ref.Name() { - return nil - } + } else if rs.Dst("") != ref.Name() { + return nil } cmd := &packp.Command{ @@ -1046,12 +1044,11 @@ func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) { } func objectsToPush(commands []*packp.Command) []plumbing.Hash { - var objects []plumbing.Hash + objects := make([]plumbing.Hash, len(commands)) for _, cmd := range commands { if cmd.New == plumbing.ZeroHash { continue } - objects = append(objects, cmd.New) } return objects diff --git a/repository.go b/repository.go index 1f6de76..065f087 100644 --- a/repository.go +++ b/repository.go @@ -1439,9 +1439,9 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err var commit *object.Commit for _, item := range items { - switch item.(type) { + switch item := item.(type) { case revision.Ref: - revisionRef := item.(revision.Ref) + revisionRef := item var tryHashes []plumbing.Hash @@ -1494,7 +1494,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err } case revision.CaretPath: - depth := item.(revision.CaretPath).Depth + depth := item.Depth if depth == 0 { break @@ -1522,7 +1522,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err commit = c case revision.TildePath: - for i := 0; i < item.(revision.TildePath).Depth; i++ { + for i := 0; i < item.Depth; i++ { c, err := commit.Parents().Next() if err != nil { @@ -1534,8 +1534,8 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err case revision.CaretReg: history := object.NewCommitPreorderIter(commit, nil, nil) - re := item.(revision.CaretReg).Regexp - negate := item.(revision.CaretReg).Negate + re := item.Regexp + negate := item.Negate var c *object.Commit diff --git a/repository_test.go b/repository_test.go index bbed604..2541cca 100644 --- a/repository_test.go +++ b/repository_test.go @@ -713,7 +713,7 @@ func (s *RepositorySuite) TestPlainCloneContextNonExistentWithNotEmptyDir(c *C) c.Assert(err, IsNil) dummyFile := filepath.Join(repoDirPath, "dummyFile") - err = ioutil.WriteFile(dummyFile, []byte(fmt.Sprint("dummyContent")), 0644) + err = ioutil.WriteFile(dummyFile, []byte("dummyContent"), 0644) c.Assert(err, IsNil) r, err := PlainCloneContext(ctx, repoDirPath, false, &CloneOptions{ diff --git a/storage/transactional/reference.go b/storage/transactional/reference.go index c3a727c..3b009e2 100644 --- a/storage/transactional/reference.go +++ b/storage/transactional/reference.go @@ -27,7 +27,7 @@ func NewReferenceStorage(base, temporal storer.ReferenceStorer) *ReferenceStorag ReferenceStorer: base, temporal: temporal, - deleted: make(map[plumbing.ReferenceName]struct{}, 0), + deleted: make(map[plumbing.ReferenceName]struct{}), } } diff --git a/worktree_bsd.go b/worktree_bsd.go index d4ea327..0f8716d 100644 --- a/worktree_bsd.go +++ b/worktree_bsd.go @@ -12,7 +12,7 @@ import ( func init() { fillSystemInfo = func(e *index.Entry, sys interface{}) { if os, ok := sys.(*syscall.Stat_t); ok { - e.CreatedAt = time.Unix(int64(os.Atimespec.Sec), int64(os.Atimespec.Nsec)) + e.CreatedAt = time.Unix(os.Atimespec.Sec, os.Atimespec.Nsec) e.Dev = uint32(os.Dev) e.Inode = uint32(os.Ino) e.GID = os.Gid -- cgit