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

Commit d6c4b11

Browse files
authored
Merge pull request #1199 from src-d/clean-up
*: code quality improvements
2 parents b294aa1 + ab19315 commit d6c4b11

28 files changed

+40
-49
lines changed

blame.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (b *blame) fillGraphAndData() error {
193193
// this first commit.
194194
if i == 0 {
195195
for j := 0; j < nLines; j++ {
196-
b.graph[i][j] = (*object.Commit)(b.revs[i])
196+
b.graph[i][j] = b.revs[i]
197197
}
198198
} else {
199199
// if this is not the first commit, then assign to the old
@@ -211,7 +211,7 @@ func (b *blame) sliceGraph(i int) []*object.Commit {
211211
fVs := b.graph[i]
212212
result := make([]*object.Commit, 0, len(fVs))
213213
for _, v := range fVs {
214-
c := object.Commit(*v)
214+
c := *v
215215
result = append(result, &c)
216216
}
217217
return result
@@ -234,7 +234,7 @@ func (b *blame) assignOrigin(c, p int) {
234234
b.graph[c][dl] = b.graph[p][sl]
235235
case hunks[h].Type == 1:
236236
dl++
237-
b.graph[c][dl] = (*object.Commit)(b.revs[c])
237+
b.graph[c][dl] = b.revs[c]
238238
case hunks[h].Type == -1:
239239
sl++
240240
default:

config/branch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (b *Branch) marshal() *format.Subsection {
7272
if b.Rebase == "" {
7373
b.raw.RemoveOption(rebaseKey)
7474
} else {
75-
b.raw.SetOption(rebaseKey, string(b.Rebase))
75+
b.raw.SetOption(rebaseKey, b.Rebase)
7676
}
7777

7878
return b.raw

plumbing/format/commitgraph/encoder.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ func NewEncoder(w io.Writer) *Encoder {
2424

2525
// Encode writes an index into the commit-graph file
2626
func (e *Encoder) Encode(idx Index) error {
27-
var err error
28-
2927
// Get all the hashes in the input index
3028
hashes := idx.Hashes()
3129

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

42-
if err = e.encodeFileHeader(len(chunkSignatures)); err != nil {
40+
if err := e.encodeFileHeader(len(chunkSignatures)); err != nil {
4341
return err
4442
}
45-
if err = e.encodeChunkHeaders(chunkSignatures, chunkSizes); err != nil {
43+
if err := e.encodeChunkHeaders(chunkSignatures, chunkSizes); err != nil {
4644
return err
4745
}
48-
if err = e.encodeFanout(fanout); err != nil {
46+
if err := e.encodeFanout(fanout); err != nil {
4947
return err
5048
}
51-
if err = e.encodeOidLookup(hashes); err != nil {
49+
if err := e.encodeOidLookup(hashes); err != nil {
5250
return err
5351
}
5452
if extraEdges, err := e.encodeCommitData(hashes, hashToIndex, idx); err == nil {
5553
if err = e.encodeExtraEdges(extraEdges); err != nil {
5654
return err
5755
}
58-
}
59-
if err != nil {
56+
} else {
6057
return err
6158
}
59+
6260
return e.encodeChecksum()
6361
}
6462

plumbing/format/commitgraph/file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (fi *fileIndex) getHashesFromIndexes(indexes []int) ([]plumbing.Hash, error
249249
// Hashes returns all the hashes that are available in the index
250250
func (fi *fileIndex) Hashes() []plumbing.Hash {
251251
hashes := make([]plumbing.Hash, fi.fanout[0xff])
252-
for i := 0; i < int(fi.fanout[0xff]); i++ {
252+
for i := 0; i < fi.fanout[0xff]; i++ {
253253
offset := fi.oidLookupOffset + int64(i)*20
254254
if n, err := fi.reader.ReadAt(hashes[i][:], offset); err != nil || n < 20 {
255255
return nil

plumbing/format/commitgraph/memory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (mi *MemoryIndex) GetIndexByHash(h plumbing.Hash) (int, error) {
3131
// GetCommitDataByIndex gets the commit node from the commit graph using index
3232
// obtained from child node, if available
3333
func (mi *MemoryIndex) GetCommitDataByIndex(i int) (*CommitData, error) {
34-
if int(i) >= len(mi.commitData) {
34+
if i >= len(mi.commitData) {
3535
return nil, plumbing.ErrObjectNotFound
3636
}
3737

plumbing/format/diff/unified_encoder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (e *UnifiedEncoder) printMessage(message string) {
9494
isEmpty := message == ""
9595
hasSuffix := strings.HasSuffix(message, "\n")
9696
if !isEmpty && !hasSuffix {
97-
message = message + "\n"
97+
message += "\n"
9898
}
9999

100100
e.buf.WriteString(message)

plumbing/format/gitattributes/pattern.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (p *pattern) Match(path []string) bool {
6666
doublestar = true
6767
}
6868

69-
switch true {
69+
switch {
7070
case strings.Contains(pattern[0], "**"):
7171
return false
7272

plumbing/format/idxfile/decoder.go

-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ func readObjectNames(idx *MemoryIndex, r io.Reader) error {
110110
continue
111111
}
112112

113-
if buckets < 0 {
114-
return ErrMalformedIdxFile
115-
}
116-
117113
idx.FanoutMapping[k] = len(idx.Names)
118114

119115
nameLen := int(buckets * objectIDLength)

plumbing/format/idxfile/writer.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (w *Writer) createIndex() (*MemoryIndex, error) {
147147
idx.Offset32[bucket] = append(idx.Offset32[bucket], buf.Bytes()...)
148148

149149
buf.Truncate(0)
150-
binary.WriteUint32(buf, uint32(o.CRC32))
150+
binary.WriteUint32(buf, o.CRC32)
151151
idx.CRC32[bucket] = append(idx.CRC32[bucket], buf.Bytes()...)
152152
}
153153

plumbing/format/packfile/scanner_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func (s *ScannerSuite) TestReaderReset(c *C) {
140140
p := NewScanner(r)
141141

142142
version, objects, err := p.Header()
143+
c.Assert(err, IsNil)
143144
c.Assert(version, Equals, VersionSupported)
144145
c.Assert(objects, Equals, uint32(31))
145146

plumbing/object/commit_walker_bfs_filtered_test.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ func commitsFromIter(iter CommitIter) ([]*Commit, error) {
2929
func assertHashes(c *C, commits []*Commit, hashes []string) {
3030
if len(commits) != len(hashes) {
3131
var expected []string
32-
for _, c := range hashes {
33-
expected = append(expected, c)
34-
}
32+
expected = append(expected, hashes...)
3533
fmt.Println("expected:", strings.Join(expected, ", "))
3634
var got []string
3735
for _, c := range commits {
@@ -48,11 +46,7 @@ func assertHashes(c *C, commits []*Commit, hashes []string) {
4846

4947
func validIfCommit(ignored plumbing.Hash) CommitFilter {
5048
return func(c *Commit) bool {
51-
if c.Hash == ignored {
52-
return true
53-
}
54-
55-
return false
49+
return c.Hash == ignored
5650
}
5751
}
5852

plumbing/object/merge_base.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func (c *Commit) MergeBase(other *Commit) ([]*Commit, error) {
3232
var res []*Commit
3333
inNewerHistory := isInIndexCommitFilter(newerHistory)
3434
resIter := NewFilterCommitIter(older, &inNewerHistory, &inNewerHistory)
35-
err = resIter.ForEach(func(commit *Commit) error {
35+
_ = resIter.ForEach(func(commit *Commit) error {
3636
res = append(res, commit)
3737
return nil
3838
})

plumbing/object/patch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ func printStat(fileStats []FileStat) string {
278278
var scaleFactor float64
279279
if longestTotalChange > heightOfHistogram {
280280
// Scale down to heightOfHistogram.
281-
scaleFactor = float64(longestTotalChange / heightOfHistogram)
281+
scaleFactor = longestTotalChange / heightOfHistogram
282282
} else {
283283
scaleFactor = 1.0
284284
}

plumbing/object/patch_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func (s *PatchSuite) TestStatsWithSubmodules(c *C) {
1919
fixtures.ByURL("https://github.com/git-fixtures/submodule.git").One().DotGit(), cache.NewObjectLRUDefault())
2020

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

2324
tree, err := commit.Tree()
2425
c.Assert(err, IsNil)

plumbing/object/tree.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func (t *Tree) Encode(o plumbing.EncodedObject) (err error) {
288288
return err
289289
}
290290

291-
if _, err = w.Write([]byte(entry.Hash[:])); err != nil {
291+
if _, err = w.Write(entry.Hash[:]); err != nil {
292292
return err
293293
}
294294
}
@@ -517,4 +517,4 @@ func simpleJoin(parent, child string) string {
517517
return parent + "/" + child
518518
}
519519
return child
520-
}
520+
}

plumbing/protocol/packp/advrefs.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (a *AdvRefs) resolveHead(s storer.ReferenceStorer) error {
107107
return nil
108108
}
109109

110-
ref, err := s.Reference(plumbing.ReferenceName(plumbing.Master))
110+
ref, err := s.Reference(plumbing.Master)
111111

112112
// check first if HEAD is pointing to master
113113
if err == nil {

plumbing/protocol/packp/updreq_decode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ func parseCommand(b []byte) (*Command, error) {
225225
return nil, errInvalidNewObjId(err)
226226
}
227227

228-
return &Command{Old: oh, New: nh, Name: plumbing.ReferenceName(n)}, nil
228+
return &Command{Old: oh, New: nh, Name: n}, nil
229229
}
230230

231231
func parseHash(s string) (plumbing.Hash, error) {

plumbing/transport/server/server.go

-5
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,6 @@ func (s *rpSession) updateReferences(req *packp.ReferenceUpdateRequest) {
286286
continue
287287
}
288288

289-
if err != nil {
290-
s.setStatus(cmd.Name, err)
291-
continue
292-
}
293-
294289
ref := plumbing.NewHashReference(cmd.Name, cmd.New)
295290
err := s.storer.SetReference(ref)
296291
s.setStatus(cmd.Name, err)

plumbing/transport/ssh/auth_method.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (a *KeyboardInteractive) ClientConfig() (*ssh.ClientConfig, error) {
6161
return a.SetHostKeyCallback(&ssh.ClientConfig{
6262
User: a.User,
6363
Auth: []ssh.AuthMethod{
64-
ssh.KeyboardInteractiveChallenge(a.Challenge),
64+
a.Challenge,
6565
},
6666
})
6767
}

prune_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ func (s *PruneSuite) testPrune(c *C, deleteTime time.Time) {
5656
newCount++
5757
return nil
5858
})
59+
c.Assert(err, IsNil)
60+
5961
if deleteTime.IsZero() {
6062
c.Assert(newCount < count, Equals, true)
6163
} else {

remote.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ func (r *Remote) updateLocalReferenceStorage(
937937
updated = true
938938
}
939939

940-
if err == nil && forceNeeded {
940+
if forceNeeded {
941941
err = ErrForceNeeded
942942
}
943943

repository_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -336,12 +336,14 @@ func (s *RepositorySuite) TestCreateBranchUnmarshal(c *C) {
336336
Merge: "refs/heads/foo",
337337
}
338338
err = r.CreateBranch(testBranch1)
339+
c.Assert(err, IsNil)
339340
err = r.CreateBranch(testBranch2)
340-
341341
c.Assert(err, IsNil)
342+
342343
cfg, err := r.Config()
343344
c.Assert(err, IsNil)
344345
marshaled, err := cfg.Marshal()
346+
c.Assert(err, IsNil)
345347
c.Assert(string(expected), Equals, string(marshaled))
346348
}
347349

storage/filesystem/dotgit/dotgit_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ func (s *SuiteDotGit) TestRemoveRefFromReferenceFileAndPackedRefs(c *C) {
226226
"refs/remotes/origin/branch",
227227
"e8d3ffab552895c19b9fcf7aa264d277cde33881",
228228
), nil)
229+
c.Assert(err, IsNil)
229230

230231
// Make sure it only appears once in the refs list.
231232
refs, err := dir.Refs()

utils/merkletrie/difftree_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func newChangesFromString(s string) (changes, error) {
177177

178178
for _, chunk := range strings.Split(s, " ") {
179179
change := change{
180-
path: string(chunk[1:]),
180+
path: chunk[1:],
181181
}
182182

183183
switch chunk[0] {

utils/merkletrie/noder/path_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ func (s *PathSuite) TestCompareMixedDepths(c *C) {
154154
}
155155

156156
func (s *PathSuite) TestCompareNormalization(c *C) {
157-
p1 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKC).String("페")}})
158-
p2 := Path([]Noder{&noderMock{name: norm.Form(norm.NFKD).String("페")}})
157+
p1 := Path([]Noder{&noderMock{name: norm.NFKC.String("페")}})
158+
p2 := Path([]Noder{&noderMock{name: norm.NFKD.String("페")}})
159159
c.Assert(p1.Compare(p2), Equals, 1)
160160
c.Assert(p2.Compare(p1), Equals, -1)
161161
p1 = Path([]Noder{&noderMock{name: "TestAppWithUnicodéPath"}})

worktree_commit_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (s *WorktreeSuite) TestCommitTreeSort(c *C) {
210210
r, err := Init(st, nil)
211211
c.Assert(err, IsNil)
212212

213-
r, err = Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
213+
r, _ = Clone(memory.NewStorage(), memfs.New(), &CloneOptions{
214214
URL: path,
215215
})
216216

worktree_linux.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func init() {
1313
fillSystemInfo = func(e *index.Entry, sys interface{}) {
1414
if os, ok := sys.(*syscall.Stat_t); ok {
15-
e.CreatedAt = time.Unix(int64(os.Ctim.Sec), int64(os.Ctim.Nsec))
15+
e.CreatedAt = time.Unix(os.Ctim.Sec, os.Ctim.Nsec)
1616
e.Dev = uint32(os.Dev)
1717
e.Inode = uint32(os.Ino)
1818
e.GID = os.Gid

worktree_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func (s *WorktreeSuite) TestFilenameNormalization(c *C) {
432432
err = w.Filesystem.Remove(filename)
433433
c.Assert(err, IsNil)
434434

435-
modFilename := norm.Form(norm.NFKD).String(filename)
435+
modFilename := norm.NFKD.String(filename)
436436
writeFile(modFilename)
437437

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

16761676
// Status before cleaning.
16771677
status, err := wt.Status()
1678+
c.Assert(err, IsNil)
16781679
c.Assert(len(status), Equals, 2)
16791680

16801681
err = wt.Clean(&CleanOptions{})

0 commit comments

Comments
 (0)