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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

0 commit comments

Comments
 (0)