aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol
diff options
context:
space:
mode:
authorferhat elmas <elmas.ferhat@gmail.com>2017-11-29 02:24:31 +0100
committerferhat elmas <elmas.ferhat@gmail.com>2017-11-29 13:01:32 +0100
commit18e6f9daa3899318d36b525b068837f49bc2c1cf (patch)
treea797b79d0a750972ba9809eb52691cb09f9b6383 /plumbing/protocol
parentc07c778ed043429427533e2fd7549a3d54b903f1 (diff)
downloadgo-git-18e6f9daa3899318d36b525b068837f49bc2c1cf.tar.gz
all: simplification
- no length for map initialization - don't check for boolean/error return - don't format string - use string method of bytes buffer instead of converting bytes to string - use `strings.Contains` instead of `strings.Index` - use `bytes.Equal` instead of `bytes.Compare`
Diffstat (limited to 'plumbing/protocol')
-rw-r--r--plumbing/protocol/packp/advrefs_encode.go2
-rw-r--r--plumbing/protocol/packp/shallowupd.go2
-rw-r--r--plumbing/protocol/packp/srvresp.go6
-rw-r--r--plumbing/protocol/packp/ulreq_encode.go4
-rw-r--r--plumbing/protocol/packp/uppackreq.go2
-rw-r--r--plumbing/protocol/packp/uppackresp_test.go4
6 files changed, 10 insertions, 10 deletions
diff --git a/plumbing/protocol/packp/advrefs_encode.go b/plumbing/protocol/packp/advrefs_encode.go
index cb93d46..c23e3fe 100644
--- a/plumbing/protocol/packp/advrefs_encode.go
+++ b/plumbing/protocol/packp/advrefs_encode.go
@@ -133,7 +133,7 @@ func encodeRefs(e *advRefsEncoder) encoderStateFn {
continue
}
- hash, _ := e.data.References[r]
+ hash := e.data.References[r]
if e.err = e.pe.Encodef("%s %s\n", hash.String(), r); e.err != nil {
return nil
}
diff --git a/plumbing/protocol/packp/shallowupd.go b/plumbing/protocol/packp/shallowupd.go
index 40f58e8..fce4e3b 100644
--- a/plumbing/protocol/packp/shallowupd.go
+++ b/plumbing/protocol/packp/shallowupd.go
@@ -32,7 +32,7 @@ func (r *ShallowUpdate) Decode(reader io.Reader) error {
err = r.decodeShallowLine(line)
case bytes.HasPrefix(line, unshallow):
err = r.decodeUnshallowLine(line)
- case bytes.Compare(line, pktline.Flush) == 0:
+ case bytes.Equal(line, pktline.Flush):
return nil
}
diff --git a/plumbing/protocol/packp/srvresp.go b/plumbing/protocol/packp/srvresp.go
index 434e8aa..6a91991 100644
--- a/plumbing/protocol/packp/srvresp.go
+++ b/plumbing/protocol/packp/srvresp.go
@@ -77,7 +77,7 @@ func (r *ServerResponse) stopReading(reader *bufio.Reader) (bool, error) {
func (r *ServerResponse) isValidCommand(b []byte) bool {
commands := [][]byte{ack, nak}
for _, c := range commands {
- if bytes.Compare(b, c) == 0 {
+ if bytes.Equal(b, c) {
return true
}
}
@@ -90,11 +90,11 @@ func (r *ServerResponse) decodeLine(line []byte) error {
return fmt.Errorf("unexpected flush")
}
- if bytes.Compare(line[0:3], ack) == 0 {
+ if bytes.Equal(line[0:3], ack) {
return r.decodeACKLine(line)
}
- if bytes.Compare(line[0:3], nak) == 0 {
+ if bytes.Equal(line[0:3], nak) {
return nil
}
diff --git a/plumbing/protocol/packp/ulreq_encode.go b/plumbing/protocol/packp/ulreq_encode.go
index 4a26e74..89a5986 100644
--- a/plumbing/protocol/packp/ulreq_encode.go
+++ b/plumbing/protocol/packp/ulreq_encode.go
@@ -70,7 +70,7 @@ func (e *ulReqEncoder) encodeFirstWant() stateFn {
func (e *ulReqEncoder) encodeAditionalWants() stateFn {
last := e.data.Wants[0]
for _, w := range e.data.Wants[1:] {
- if bytes.Compare(last[:], w[:]) == 0 {
+ if bytes.Equal(last[:], w[:]) {
continue
}
@@ -90,7 +90,7 @@ func (e *ulReqEncoder) encodeShallows() stateFn {
var last plumbing.Hash
for _, s := range e.data.Shallows {
- if bytes.Compare(last[:], s[:]) == 0 {
+ if bytes.Equal(last[:], s[:]) {
continue
}
diff --git a/plumbing/protocol/packp/uppackreq.go b/plumbing/protocol/packp/uppackreq.go
index 4bb22d0..1144139 100644
--- a/plumbing/protocol/packp/uppackreq.go
+++ b/plumbing/protocol/packp/uppackreq.go
@@ -77,7 +77,7 @@ func (u *UploadHaves) Encode(w io.Writer, flush bool) error {
var last plumbing.Hash
for _, have := range u.Haves {
- if bytes.Compare(last[:], have[:]) == 0 {
+ if bytes.Equal(last[:], have[:]) {
continue
}
diff --git a/plumbing/protocol/packp/uppackresp_test.go b/plumbing/protocol/packp/uppackresp_test.go
index 789444d..0d96ce7 100644
--- a/plumbing/protocol/packp/uppackresp_test.go
+++ b/plumbing/protocol/packp/uppackresp_test.go
@@ -92,7 +92,7 @@ func (s *UploadPackResponseSuite) TestEncodeNAK(c *C) {
c.Assert(res.Encode(b), IsNil)
expected := "0008NAK\n[PACK]"
- c.Assert(string(b.Bytes()), Equals, expected)
+ c.Assert(b.String(), Equals, expected)
}
func (s *UploadPackResponseSuite) TestEncodeDepth(c *C) {
@@ -107,7 +107,7 @@ func (s *UploadPackResponseSuite) TestEncodeDepth(c *C) {
c.Assert(res.Encode(b), IsNil)
expected := "00000008NAK\nPACK"
- c.Assert(string(b.Bytes()), Equals, expected)
+ c.Assert(b.String(), Equals, expected)
}
func (s *UploadPackResponseSuite) TestEncodeMultiACK(c *C) {