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

Commit 49f40d9

Browse files
committed
common: GitUploadPackRequest Want, Have methods
1 parent b7cf99f commit 49f40d9

File tree

5 files changed

+31
-27
lines changed

5 files changed

+31
-27
lines changed

clients/common/common.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,16 @@ func (r *GitUploadPackInfo) Bytes() []byte {
268268
}
269269

270270
type GitUploadPackRequest struct {
271-
Want []core.Hash
272-
Have []core.Hash
271+
Wants []core.Hash
272+
Haves []core.Hash
273+
}
274+
275+
func (r *GitUploadPackRequest) Want(h ...core.Hash) {
276+
r.Wants = append(r.Wants, h...)
277+
}
278+
279+
func (r *GitUploadPackRequest) Have(h ...core.Hash) {
280+
r.Haves = append(r.Haves, h...)
273281
}
274282

275283
func (r *GitUploadPackRequest) String() string {
@@ -279,11 +287,11 @@ func (r *GitUploadPackRequest) String() string {
279287

280288
func (r *GitUploadPackRequest) Reader() *strings.Reader {
281289
e := pktline.NewEncoder()
282-
for _, want := range r.Want {
290+
for _, want := range r.Wants {
283291
e.AddLine(fmt.Sprintf("want %s", want))
284292
}
285293

286-
for _, have := range r.Have {
294+
for _, have := range r.Haves {
287295
e.AddLine(fmt.Sprintf("have %s", have))
288296
}
289297

clients/common/common_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,10 @@ func (s *SuiteCommon) TestGitUploadPackEncode(c *C) {
108108
}
109109

110110
func (s *SuiteCommon) TestGitUploadPackRequest(c *C) {
111-
r := &GitUploadPackRequest{
112-
Want: []core.Hash{
113-
core.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"),
114-
core.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"),
115-
},
116-
Have: []core.Hash{
117-
core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
118-
},
119-
}
111+
r := &GitUploadPackRequest{}
112+
r.Want(core.NewHash("d82f291cde9987322c8a0c81a325e1ba6159684c"))
113+
r.Want(core.NewHash("2b41ef280fdb67a9b250678686a0c3e03b0a9989"))
114+
r.Have(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
120115

121116
c.Assert(r.String(), Equals,
122117
"0032want d82f291cde9987322c8a0c81a325e1ba6159684c\n"+

clients/http/git_upload_pack_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ func (s *SuiteRemote) TestFetch(c *C) {
5858
r := NewGitUploadPackService()
5959
c.Assert(r.Connect(RepositoryFixture), IsNil)
6060

61-
reader, err := r.Fetch(&common.GitUploadPackRequest{
62-
Want: []core.Hash{
63-
core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"),
64-
},
65-
})
61+
req := &common.GitUploadPackRequest{}
62+
req.Want(core.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"))
6663

64+
reader, err := r.Fetch(req)
6765
c.Assert(err, IsNil)
6866

6967
b, err := ioutil.ReadAll(reader)

remote.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ func (r *Remote) FetchDefaultBranch() (io.ReadCloser, error) {
8989
return nil, err
9090
}
9191

92-
return r.Fetch(&common.GitUploadPackRequest{
93-
Want: []core.Hash{ref},
94-
})
92+
req := &common.GitUploadPackRequest{}
93+
req.Want(ref)
94+
95+
return r.Fetch(req)
9596
}
9697

9798
// Ref returns the Hash pointing the given refName

repository.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,19 @@ func (r *Repository) Pull(remoteName, branch string) error {
6666
return err
6767
}
6868

69-
reader, err := remote.Fetch(&common.GitUploadPackRequest{
70-
Want: []core.Hash{ref},
71-
})
72-
73-
pr := packfile.NewReader(reader)
74-
_, err = pr.Read(r.Storage)
69+
req := &common.GitUploadPackRequest{}
70+
req.Want(ref)
7571

72+
reader, err := remote.Fetch(req)
7673
if err != nil {
7774
return err
7875
}
7976

77+
pr := packfile.NewReader(reader)
78+
if _, err = pr.Read(r.Storage); err != nil {
79+
return err
80+
}
81+
8082
return nil
8183
}
8284

0 commit comments

Comments
 (0)