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

Commit 7ced032

Browse files
authored
Merge pull request #667 from ferhatelmas/simplify
all: simplification
2 parents c07c778 + 18e6f9d commit 7ced032

File tree

27 files changed

+56
-118
lines changed

27 files changed

+56
-118
lines changed

blame.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ func (b *blame) fillRevs() error {
147147
var err error
148148

149149
b.revs, err = references(b.fRev, b.path)
150-
if err != nil {
151-
return err
152-
}
153-
return nil
150+
return err
154151
}
155152

156153
// build graph of a file from its revision history
@@ -244,7 +241,7 @@ func (b *blame) GoString() string {
244241

245242
lines := strings.Split(contents, "\n")
246243
// max line number length
247-
mlnl := len(fmt.Sprintf("%s", strconv.Itoa(len(lines))))
244+
mlnl := len(strconv.Itoa(len(lines)))
248245
// max author length
249246
mal := b.maxAuthorLength()
250247
format := fmt.Sprintf("%%s (%%-%ds %%%dd) %%s\n",

common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (s *BaseSuite) SetUpSuite(c *C) {
3030
s.Suite.SetUpSuite(c)
3131
s.buildBasicRepository(c)
3232

33-
s.cache = make(map[string]*Repository, 0)
33+
s.cache = make(map[string]*Repository)
3434
}
3535

3636
func (s *BaseSuite) TearDownSuite(c *C) {

config/config.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ type Config struct {
6565
// NewConfig returns a new empty Config.
6666
func NewConfig() *Config {
6767
return &Config{
68-
Remotes: make(map[string]*RemoteConfig, 0),
69-
Submodules: make(map[string]*Submodule, 0),
68+
Remotes: make(map[string]*RemoteConfig),
69+
Submodules: make(map[string]*Submodule),
7070
Raw: format.New(),
7171
}
7272
}
@@ -290,13 +290,8 @@ func (c *RemoteConfig) unmarshal(s *format.Subsection) error {
290290
fetch = append(fetch, rs)
291291
}
292292

293-
var urls []string
294-
for _, f := range c.raw.Options.GetAll(urlKey) {
295-
urls = append(urls, f)
296-
}
297-
298293
c.Name = c.raw.Name
299-
c.URLs = urls
294+
c.URLs = append([]string(nil), c.raw.Options.GetAll(urlKey)...)
300295
c.Fetch = fetch
301296

302297
return nil

config/modules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Modules struct {
2424
// NewModules returns a new empty Modules
2525
func NewModules() *Modules {
2626
return &Modules{
27-
Submodules: make(map[string]*Submodule, 0),
27+
Submodules: make(map[string]*Submodule),
2828
raw: format.New(),
2929
}
3030
}

config/refspec.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,12 @@ func (s RefSpec) Validate() error {
5151

5252
// IsForceUpdate returns if update is allowed in non fast-forward merges.
5353
func (s RefSpec) IsForceUpdate() bool {
54-
if s[0] == refSpecForce[0] {
55-
return true
56-
}
57-
58-
return false
54+
return s[0] == refSpecForce[0]
5955
}
6056

6157
// IsDelete returns true if the refspec indicates a delete (empty src).
6258
func (s RefSpec) IsDelete() bool {
63-
if s[0] == refSpecSeparator[0] {
64-
return true
65-
}
66-
67-
return false
59+
return s[0] == refSpecSeparator[0]
6860
}
6961

7062
// Src return the src side.
@@ -87,7 +79,7 @@ func (s RefSpec) Match(n plumbing.ReferenceName) bool {
8779

8880
// IsWildcard returns true if the RefSpec contains a wildcard.
8981
func (s RefSpec) IsWildcard() bool {
90-
return strings.Index(string(s), refSpecWildcard) != -1
82+
return strings.Contains(string(s), refSpecWildcard)
9183
}
9284

9385
func (s RefSpec) matchExact(n plumbing.ReferenceName) bool {

plumbing/format/config/encoder.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,13 @@ func (e *Encoder) encodeSubsection(sectionName string, s *Subsection) error {
5353
return err
5454
}
5555

56-
if err := e.encodeOptions(s.Options); err != nil {
57-
return err
58-
}
59-
60-
return nil
56+
return e.encodeOptions(s.Options)
6157
}
6258

6359
func (e *Encoder) encodeOptions(opts Options) error {
6460
for _, o := range opts {
6561
pattern := "\t%s = %s\n"
66-
if strings.Index(o.Value, "\\") != -1 {
62+
if strings.Contains(o.Value, "\\") {
6763
pattern = "\t%s = %q\n"
6864
}
6965

plumbing/format/index/decoder.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,8 @@ func (d *Decoder) padEntry(idx *Index, e *Entry, read int) error {
200200

201201
entrySize := read + len(e.Name)
202202
padLen := 8 - entrySize%8
203-
if _, err := io.CopyN(ioutil.Discard, d.r, int64(padLen)); err != nil {
204-
return err
205-
}
206-
207-
return nil
203+
_, err := io.CopyN(ioutil.Discard, d.r, int64(padLen))
204+
return err
208205
}
209206

210207
func (d *Decoder) readExtensions(idx *Index) error {
@@ -288,7 +285,7 @@ func (d *Decoder) readChecksum(expected []byte, alreadyRead [4]byte) error {
288285
return err
289286
}
290287

291-
if bytes.Compare(h[:], expected) != 0 {
288+
if !bytes.Equal(h[:], expected) {
292289
return ErrInvalidChecksum
293290
}
294291

@@ -407,7 +404,7 @@ func (d *resolveUndoDecoder) Decode(ru *ResolveUndo) error {
407404

408405
func (d *resolveUndoDecoder) readEntry() (*ResolveUndoEntry, error) {
409406
e := &ResolveUndoEntry{
410-
Stages: make(map[Stage]plumbing.Hash, 0),
407+
Stages: make(map[Stage]plumbing.Hash),
411408
}
412409

413410
path, err := binary.ReadUntil(d.r, '\x00')

plumbing/format/objfile/reader.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,5 @@ func (r *Reader) Hash() plumbing.Hash {
110110
// Close releases any resources consumed by the Reader. Calling Close does not
111111
// close the wrapped io.Reader originally passed to NewReader.
112112
func (r *Reader) Close() error {
113-
if err := r.zlib.Close(); err != nil {
114-
return err
115-
}
116-
117-
return nil
113+
return r.zlib.Close()
118114
}

plumbing/format/packfile/decoder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewDecoderForType(s *Scanner, o storer.EncodedObjectStorer,
105105
o: o,
106106

107107
idx: NewIndex(0),
108-
offsetToType: make(map[int64]plumbing.ObjectType, 0),
108+
offsetToType: make(map[int64]plumbing.ObjectType),
109109
decoderType: t,
110110
}, nil
111111
}

plumbing/format/packfile/delta_index.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,10 @@ var len8tab = [256]uint8{
215215
}
216216

217217
func hashBlock(raw []byte, ptr int) int {
218-
var hash uint32
219-
220218
// The first 4 steps collapse out into a 4 byte big-endian decode,
221219
// with a larger right shift as we combined shift lefts together.
222220
//
223-
hash = ((uint32(raw[ptr]) & 0xff) << 24) |
221+
hash := ((uint32(raw[ptr]) & 0xff) << 24) |
224222
((uint32(raw[ptr+1]) & 0xff) << 16) |
225223
((uint32(raw[ptr+2]) & 0xff) << 8) |
226224
(uint32(raw[ptr+3]) & 0xff)

0 commit comments

Comments
 (0)