aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol/packp
diff options
context:
space:
mode:
Diffstat (limited to 'plumbing/protocol/packp')
-rw-r--r--plumbing/protocol/packp/uppackreq.go7
-rw-r--r--plumbing/protocol/packp/uppackreq_test.go2
2 files changed, 5 insertions, 4 deletions
diff --git a/plumbing/protocol/packp/uppackreq.go b/plumbing/protocol/packp/uppackreq.go
index 84e2b4e..4bb22d0 100644
--- a/plumbing/protocol/packp/uppackreq.go
+++ b/plumbing/protocol/packp/uppackreq.go
@@ -68,8 +68,9 @@ type UploadHaves struct {
Haves []plumbing.Hash
}
-// Encode encodes the UploadHaves into the Writer.
-func (u *UploadHaves) Encode(w io.Writer) error {
+// Encode encodes the UploadHaves into the Writer. If flush is true, a flush
+// command will be encoded at the end of the writer content.
+func (u *UploadHaves) Encode(w io.Writer, flush bool) error {
e := pktline.NewEncoder(w)
plumbing.HashesSort(u.Haves)
@@ -87,7 +88,7 @@ func (u *UploadHaves) Encode(w io.Writer) error {
last = have
}
- if len(u.Haves) != 0 {
+ if flush && len(u.Haves) != 0 {
if err := e.Flush(); err != nil {
return fmt.Errorf("sending flush-pkt after haves: %s", err)
}
diff --git a/plumbing/protocol/packp/uppackreq_test.go b/plumbing/protocol/packp/uppackreq_test.go
index 273f916..f776c07 100644
--- a/plumbing/protocol/packp/uppackreq_test.go
+++ b/plumbing/protocol/packp/uppackreq_test.go
@@ -58,7 +58,7 @@ func (s *UploadHavesSuite) TestEncode(c *C) {
)
buf := bytes.NewBuffer(nil)
- err := uh.Encode(buf)
+ err := uh.Encode(buf, true)
c.Assert(err, IsNil)
c.Assert(buf.String(), Equals, ""+
"0032have 1111111111111111111111111111111111111111\n"+