aboutsummaryrefslogtreecommitdiffstats
path: root/clients/http/git_upload_pack.go
diff options
context:
space:
mode:
authorAlberto Cortés <alcortesm@gmail.com>2016-10-18 15:23:01 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-10-18 15:23:01 +0200
commit5f7d34066cc5583ee30a315e0661b5326dc548db (patch)
treec10fdbf1f42d5b51de25c6828ba6573dd28f4536 /clients/http/git_upload_pack.go
parent6c6a37b9128189ba4cdde8128428a36ef75d1a44 (diff)
downloadgo-git-5f7d34066cc5583ee30a315e0661b5326dc548db.tar.gz
Substitute old pktline encoder/decoder with new pktline scanner (#84)
* replace old pktline package with new pktline scanner * remove error checks on pktline.NewFromString * fix deppend bug * reduce memory garbage when pktline.NewFromStrings * improve int to hex conversion to help gc * make intToHex func private * clean function names
Diffstat (limited to 'clients/http/git_upload_pack.go')
-rw-r--r--clients/http/git_upload_pack.go22
1 files changed, 9 insertions, 13 deletions
diff --git a/clients/http/git_upload_pack.go b/clients/http/git_upload_pack.go
index 888d279..eb8db0b 100644
--- a/clients/http/git_upload_pack.go
+++ b/clients/http/git_upload_pack.go
@@ -2,6 +2,7 @@ package http
import (
"bufio"
+ "bytes"
"fmt"
"io"
"net/http"
@@ -9,7 +10,7 @@ import (
"gopkg.in/src-d/go-git.v4/clients/common"
"gopkg.in/src-d/go-git.v4/core"
- "gopkg.in/src-d/go-git.v4/formats/pktline"
+ "gopkg.in/src-d/go-git.v4/formats/packp/pktline"
)
// GitUploadPackService git-upoad-pack service over HTTP
@@ -77,7 +78,7 @@ func (s *GitUploadPackService) Info() (*common.GitUploadPackInfo, error) {
defer res.Body.Close()
i := common.NewGitUploadPackInfo()
- return i, i.Decode(pktline.NewDecoder(res.Body))
+ return i, i.Decode(pktline.NewScanner(res.Body))
}
// Fetch request and returns a reader to a packfile
@@ -101,27 +102,22 @@ func (s *GitUploadPackService) Fetch(r *common.GitUploadPackRequest) (io.ReadClo
return nil, err
}
- if err := s.discardResponseInfo(reader); err != nil {
+ if err := discardResponseInfo(reader); err != nil {
return nil, err
}
return reader, nil
}
-func (s *GitUploadPackService) discardResponseInfo(r io.Reader) error {
- decoder := pktline.NewDecoder(r)
- for {
- line, err := decoder.ReadLine()
- if err != nil {
- break
- }
-
- if line == "NAK\n" {
+func discardResponseInfo(r io.Reader) error {
+ s := pktline.NewScanner(r)
+ for s.Scan() {
+ if bytes.Equal(s.Bytes(), []byte{'N', 'A', 'K', '\n'}) {
break
}
}
- return nil
+ return s.Err()
}
func (s *GitUploadPackService) doRequest(method, url string, content *strings.Reader) (*http.Response, error) {