Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1199 from src-d/clean-up
Browse files Browse the repository at this point in the history
*: code quality improvements
  • Loading branch information
mcuadros authored Jul 29, 2019
2 parents b294aa1 + ab19315 commit d6c4b11
Show file tree
Hide file tree
Showing 28 changed files with 40 additions and 49 deletions.
6 changes: 3 additions & 3 deletions blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (b *blame) fillGraphAndData() error {
// this first commit.
if i == 0 {
for j := 0; j < nLines; j++ {
b.graph[i][j] = (*object.Commit)(b.revs[i])
b.graph[i][j] = b.revs[i]
}
} else {
// if this is not the first commit, then assign to the old
Expand All @@ -211,7 +211,7 @@ func (b *blame) sliceGraph(i int) []*object.Commit {
fVs := b.graph[i]
result := make([]*object.Commit, 0, len(fVs))
for _, v := range fVs {
c := object.Commit(*v)
c := *v
result = append(result, &c)
}
return result
Expand All @@ -234,7 +234,7 @@ func (b *blame) assignOrigin(c, p int) {
b.graph[c][dl] = b.graph[p][sl]
case hunks[h].Type == 1:
dl++
b.graph[c][dl] = (*object.Commit)(b.revs[c])
b.graph[c][dl] = b.revs[c]
case hunks[h].Type == -1:
sl++
default:
Expand Down
2 changes: 1 addition & 1 deletion config/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (b *Branch) marshal() *format.Subsection {
if b.Rebase == "" {
b.raw.RemoveOption(rebaseKey)
} else {
b.raw.SetOption(rebaseKey, string(b.Rebase))
b.raw.SetOption(rebaseKey, b.Rebase)
}

return b.raw
Expand Down
14 changes: 6 additions & 8 deletions plumbing/format/commitgraph/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ func NewEncoder(w io.Writer) *Encoder {

// Encode writes an index into the commit-graph file
func (e *Encoder) Encode(idx Index) error {
var err error

// Get all the hashes in the input index
hashes := idx.Hashes()

Expand All @@ -39,26 +37,26 @@ func (e *Encoder) Encode(idx Index) error {
chunkSizes = append(chunkSizes, uint64(extraEdgesCount)*4)
}

if err = e.encodeFileHeader(len(chunkSignatures)); err != nil {
if err := e.encodeFileHeader(len(chunkSignatures)); err != nil {
return err
}
if err = e.encodeChunkHeaders(chunkSignatures, chunkSizes); err != nil {
if err := e.encodeChunkHeaders(chunkSignatures, chunkSizes); err != nil {
return err
}
if err = e.encodeFanout(fanout); err != nil {
if err := e.encodeFanout(fanout); err != nil {
return err
}
if err = e.encodeOidLookup(hashes); err != nil {
if err := e.encodeOidLookup(hashes); err != nil {
return err
}
if extraEdges, err := e.encodeCommitData(hashes, hashToIndex, idx); err == nil {
if err = e.encodeExtraEdges(extraEdges); err != nil {
return err
}
}
if err != nil {
} else {
return err
}

return e.encodeChecksum()
}

Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/commitgraph/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (fi *fileIndex) getHashesFromIndexes(indexes []int) ([]plumbing.Hash, error
// Hashes returns all the hashes that are available in the index
func (fi *fileIndex) Hashes() []plumbing.Hash {
hashes := make([]plumbing.Hash, fi.fanout[0xff])
for i := 0; i < int(fi.fanout[0xff]); i++ {
for i := 0; i < fi.fanout[0xff]; i++ {
offset := fi.oidLookupOffset + int64(i)*20
if n, err := fi.reader.ReadAt(hashes[i][:], offset); err != nil || n < 20 {
return nil
Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/commitgraph/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (mi *MemoryIndex) GetIndexByHash(h plumbing.Hash) (int, error) {
// GetCommitDataByIndex gets the commit node from the commit graph using index
// obtained from child node, if available
func (mi *MemoryIndex) GetCommitDataByIndex(i int) (*CommitData, error) {
if int(i) >= len(mi.commitData) {
if i >= len(mi.commitData) {
return nil, plumbing.ErrObjectNotFound
}

Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/diff/unified_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (e *UnifiedEncoder) printMessage(message string) {
isEmpty := message == ""
hasSuffix := strings.HasSuffix(message, "\n")
if !isEmpty && !hasSuffix {
message = message + "\n"
message += "\n"
}

e.buf.WriteString(message)
Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/gitattributes/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (p *pattern) Match(path []string) bool {
doublestar = true
}

switch true {
switch {
case strings.Contains(pattern[0], "**"):
return false

Expand Down
4 changes: 0 additions & 4 deletions plumbing/format/idxfile/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ func readObjectNames(idx *MemoryIndex, r io.Reader) error {
continue
}

if buckets < 0 {
return ErrMalformedIdxFile
}

idx.FanoutMapping[k] = len(idx.Names)

nameLen := int(buckets * objectIDLength)
Expand Down
2 changes: 1 addition & 1 deletion plumbing/format/idxfile/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (w *Writer) createIndex() (*MemoryIndex, error) {
idx.Offset32[bucket] = append(idx.Offset32[bucket], buf.Bytes()...)

buf.Truncate(0)
binary.WriteUint32(buf, uint32(o.CRC32))
binary.WriteUint32(buf, o.CRC32)
idx.CRC32[bucket] = append(idx.CRC32[bucket], buf.Bytes()...)
}

Expand Down
1 change: 1 addition & 0 deletions plumbing/format/packfile/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (s *ScannerSuite) TestReaderReset(c *C) {
p := NewScanner(r)

version, objects, err := p.Header()
c.Assert(err, IsNil)
c.Assert(version, Equals, VersionSupported)
c.Assert(objects, Equals, uint32(31))

Expand Down
10 changes: 2 additions & 8 deletions plumbing/object/commit_walker_bfs_filtered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ func commitsFromIter(iter CommitIter) ([]*Commit, error) {
func assertHashes(c *C, commits []*Commit, hashes []string) {
if len(commits) != len(hashes) {
var expected []string
for _, c := range hashes {
expected = append(expected, c)
}
expected = append(expected, hashes...)
fmt.Println("expected:", strings.Join(expected, ", "))
var got []string
for _, c := range commits {
Expand All @@ -48,11 +46,7 @@ func assertHashes(c *C, commits []*Commit, hashes []string) {

func validIfCommit(ignored plumbing.Hash) CommitFilter {
return func(c *Commit) bool {
if c.Hash == ignored {
return true
}

return false
return c.Hash == ignored
}
}

Expand Down
2 changes: 1 addition & 1 deletion plumbing/object/merge_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Commit) MergeBase(other *Commit) ([]*Commit, error) {
var res []*Commit
inNewerHistory := isInIndexCommitFilter(newerHistory)
resIter := NewFilterCommitIter(older, &inNewerHistory, &inNewerHistory)
err = resIter.ForEach(func(commit *Commit) error {
_ = resIter.ForEach(func(commit *Commit) error {
res = append(res, commit)
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion plumbing/object/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func printStat(fileStats []FileStat) string {
var scaleFactor float64
if longestTotalChange > heightOfHistogram {
// Scale down to heightOfHistogram.
scaleFactor = float64(longestTotalChange / heightOfHistogram)
scaleFactor = longestTotalChange / heightOfHistogram
} else {
scaleFactor = 1.0
}
Expand Down
1 change: 1 addition & 0 deletions plumbing/object/patch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (s *PatchSuite) TestStatsWithSubmodules(c *C) {
fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit(), cache.NewObjectLRUDefault())

commit, err := GetCommit(storer, plumbing.NewHash("b685400c1f9316f350965a5993d350bc746b0bf4"))
c.Assert(err, IsNil)

tree, err := commit.Tree()
c.Assert(err, IsNil)
Expand Down
4 changes: 2 additions & 2 deletions plumbing/object/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (t *Tree) Encode(o plumbing.EncodedObject) (err error) {
return err
}

if _, err = w.Write([]byte(entry.Hash[:])); err != nil {
if _, err = w.Write(entry.Hash[:]); err != nil {
return err
}
}
Expand Down Expand Up @@ -517,4 +517,4 @@ func simpleJoin(parent, child string) string {
return parent + "/" + child
}
return child
}
}
2 changes: 1 addition & 1 deletion plumbing/protocol/packp/advrefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (a *AdvRefs) resolveHead(s storer.ReferenceStorer) error {
return nil
}

ref, err := s.Reference(plumbing.ReferenceName(plumbing.Master))
ref, err := s.Reference(plumbing.Master)

// check first if HEAD is pointing to master
if err == nil {
Expand Down
2 changes: 1 addition & 1 deletion plumbing/protocol/packp/updreq_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func parseCommand(b []byte) (*Command, error) {
return nil, errInvalidNewObjId(err)
}

return &Command{Old: oh, New: nh, Name: plumbing.ReferenceName(n)}, nil
return &Command{Old: oh, New: nh, Name: n}, nil
}

func parseHash(s string) (plumbing.Hash, error) {
Expand Down
5 changes: 0 additions & 5 deletions plumbing/transport/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,6 @@ func (s *rpSession) updateReferences(req *packp.ReferenceUpdateRequest) {
continue
}

if err != nil {
s.setStatus(cmd.Name, err)
continue
}

ref := plumbing.NewHashReference(cmd.Name, cmd.New)
err := s.storer.SetReference(ref)
s.setStatus(cmd.Name, err)
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/ssh/auth_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (a *KeyboardInteractive) ClientConfig() (*ssh.ClientConfig, error) {
return a.SetHostKeyCallback(&ssh.ClientConfig{
User: a.User,
Auth: []ssh.AuthMethod{
ssh.KeyboardInteractiveChallenge(a.Challenge),
a.Challenge,
},
})
}
Expand Down
2 changes: 2 additions & 0 deletions prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ func (s *PruneSuite) testPrune(c *C, deleteTime time.Time) {
newCount++
return nil
})
c.Assert(err, IsNil)

if deleteTime.IsZero() {
c.Assert(newCount < count, Equals, true)
} else {
Expand Down
2 changes: 1 addition & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ func (r *Remote) updateLocalReferenceStorage(
updated = true
}

if err == nil && forceNeeded {
if forceNeeded {
err = ErrForceNeeded
}

Expand Down
4 changes: 3 additions & 1 deletion repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,14 @@ func (s *RepositorySuite) TestCreateBranchUnmarshal(c *C) {
Merge: "refs/heads/foo",
}
err = r.CreateBranch(testBranch1)
c.Assert(err, IsNil)
err = r.CreateBranch(testBranch2)

c.Assert(err, IsNil)

cfg, err := r.Config()
c.Assert(err, IsNil)
marshaled, err := cfg.Marshal()
c.Assert(err, IsNil)
c.Assert(string(expected), Equals, string(marshaled))
}

Expand Down
1 change: 1 addition & 0 deletions storage/filesystem/dotgit/dotgit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (s *SuiteDotGit) TestRemoveRefFromReferenceFileAndPackedRefs(c *C) {
"refs/remotes/origin/branch",
"e8d3ffab552895c19b9fcf7aa264d277cde33881",
), nil)
c.Assert(err, IsNil)

// Make sure it only appears once in the refs list.
refs, err := dir.Refs()
Expand Down
2 changes: 1 addition & 1 deletion utils/merkletrie/difftree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func newChangesFromString(s string) (changes, error) {

for _, chunk := range strings.Split(s, " ") {
change := change{
path: string(chunk[1:]),
path: chunk[1:],
}

switch chunk[0] {
Expand Down
4 changes: 2 additions & 2 deletions utils/merkletrie/noder/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func (s *PathSuite) TestCompareMixedDepths(c *C) {
}

func (s *PathSuite) TestCompareNormalization(c *C) {
p1 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKC).String("페")}})
p2 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKD).String("페")}})
p1 := Path([]Noder{&noderMock{name: norm.NFKC.String("페")}})
p2 := Path([]Noder{&noderMock{name: norm.NFKD.String("페")}})
c.Assert(p1.Compare(p2), Equals, 1)
c.Assert(p2.Compare(p1), Equals, -1)
p1 = Path([]Noder{&noderMock{name: "TestAppWithUnicodéPath"}})
Expand Down
2 changes: 1 addition & 1 deletion worktree_commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (s *WorktreeSuite) TestCommitTreeSort(c *C) {
r, err := Init(st, nil)
c.Assert(err, IsNil)

r, err = Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
r, _ = Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
URL: path,
})

Expand Down
2 changes: 1 addition & 1 deletion worktree_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Ctim.Sec), int64(os.Ctim.Nsec))
e.CreatedAt = time.Unix(os.Ctim.Sec, os.Ctim.Nsec)
e.Dev = uint32(os.Dev)
e.Inode = uint32(os.Ino)
e.GID = os.Gid
Expand Down
3 changes: 2 additions & 1 deletion worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (s *WorktreeSuite) TestFilenameNormalization(c *C) {
err = w.Filesystem.Remove(filename)
c.Assert(err, IsNil)

modFilename := norm.Form(norm.NFKD).String(filename)
modFilename := norm.NFKD.String(filename)
writeFile(modFilename)

_, err = w.Add(filename)
Expand Down Expand Up @@ -1675,6 +1675,7 @@ func (s *WorktreeSuite) TestClean(c *C) {

// Status before cleaning.
status, err := wt.Status()
c.Assert(err, IsNil)
c.Assert(len(status), Equals, 2)

err = wt.Clean(&CleanOptions{})
Expand Down

0 comments on commit d6c4b11

Please sign in to comment.