diff options
-rw-r--r-- | clients/common/common.go | 16 | ||||
-rw-r--r-- | clients/common/common_test.go | 13 | ||||
-rw-r--r-- | clients/http/git_upload_pack_test.go | 8 | ||||
-rw-r--r-- | remote.go | 7 | ||||
-rw-r--r-- | repository.go | 14 |
5 files changed, 31 insertions, 27 deletions
diff --git a/clients/common/common.go b/clients/common/common.go index 460eb10..ef35440 100644 --- a/clients/common/common.go +++ b/clients/common/common.go @@ -268,8 +268,16 @@ func (r *GitUploadPackInfo) Bytes() []byte { } type GitUploadPackRequest struct { - Want []core.Hash - Have []core.Hash + Wants []core.Hash + Haves []core.Hash +} + +func (r *GitUploadPackRequest) Want(h ...core.Hash) { + r.Wants = append(r.Wants, h...) +} + +func (r *GitUploadPackRequest) Have(h ...core.Hash) { + r.Haves = append(r.Haves, h...) } func (r *GitUploadPackRequest) String() string { @@ -279,11 +287,11 @@ func (r *GitUploadPackRequest) String() string { func (r *GitUploadPackRequest) Reader() *strings.Reader { e := pktline.NewEncoder() - for _, want := range r.Want { + for _, want := range r.Wants { e.AddLine(fmt.Sprintf("want %s", want)) } - for _, have := range r.Have { + for _, have := range r.Haves { e.AddLine(fmt.Sprintf("have %s", have)) } diff --git a/clients/common/common_test.go b/clients/common/common_test.go index 5ffb402..dac15b6 100644 --- a/clients/common/common_test.go +++ b/clients/common/common_test.go @@ -108,15 +108,10 @@ func (s *SuiteCommon) TestGitUploadPackEncode(c *C) { } func (s *SuiteCommon) TestGitUploadPackRequest(c *C) { - r := &GitUploadPackRequest{ - Want: []core.Hash{ - core.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"), - core.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"), - }, - Have: []core.Hash{ - core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), - }, - } + r := &GitUploadPackRequest{} + r.Want(core.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c")) + r.Want(core.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989")) + r.Have(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) c.Assert(r.String(), Equals, "0032want d82f291cde9987322c8a0c81a325e1ba6159684c\n"+ diff --git a/clients/http/git_upload_pack_test.go b/clients/http/git_upload_pack_test.go index 02ed37c..f9ec424 100644 --- a/clients/http/git_upload_pack_test.go +++ b/clients/http/git_upload_pack_test.go @@ -58,12 +58,10 @@ func (s *SuiteRemote) TestFetch(c *C) { r := NewGitUploadPackService() c.Assert(r.Connect(RepositoryFixture), IsNil) - reader, err := r.Fetch(&common.GitUploadPackRequest{ - Want: []core.Hash{ - core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), - }, - }) + req := &common.GitUploadPackRequest{} + req.Want(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5")) + reader, err := r.Fetch(req) c.Assert(err, IsNil) b, err := ioutil.ReadAll(reader) @@ -89,9 +89,10 @@ func (r *Remote) FetchDefaultBranch() (io.ReadCloser, error) { return nil, err } - return r.Fetch(&common.GitUploadPackRequest{ - Want: []core.Hash{ref}, - }) + req := &common.GitUploadPackRequest{} + req.Want(ref) + + return r.Fetch(req) } // Ref returns the Hash pointing the given refName diff --git a/repository.go b/repository.go index bf45fdc..32a6fcf 100644 --- a/repository.go +++ b/repository.go @@ -66,17 +66,19 @@ func (r *Repository) Pull(remoteName, branch string) error { return err } - reader, err := remote.Fetch(&common.GitUploadPackRequest{ - Want: []core.Hash{ref}, - }) - - pr := packfile.NewReader(reader) - _, err = pr.Read(r.Storage) + req := &common.GitUploadPackRequest{} + req.Want(ref) + reader, err := remote.Fetch(req) if err != nil { return err } + pr := packfile.NewReader(reader) + if _, err = pr.Read(r.Storage); err != nil { + return err + } + return nil } |