aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/protocol/packp/uppackreq.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-12-05 15:44:50 +0100
committerGitHub <noreply@github.com>2016-12-05 15:44:50 +0100
commit11735c3b3aaa8f789dc10739a4de7ad438196000 (patch)
treec83fa6ddf9748fd0e4e4edb4d0e2692994145ace /plumbing/protocol/packp/uppackreq.go
parent0042bb031676a20ffc789f94e332a6da70e2756d (diff)
downloadgo-git-11735c3b3aaa8f789dc10739a4de7ad438196000.tar.gz
plumbing/protocol: paktp avoid duplication of haves, wants and shallow (#158)
Diffstat (limited to 'plumbing/protocol/packp/uppackreq.go')
-rw-r--r--plumbing/protocol/packp/uppackreq.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/plumbing/protocol/packp/uppackreq.go b/plumbing/protocol/packp/uppackreq.go
index 2b1cb84..887d27a 100644
--- a/plumbing/protocol/packp/uppackreq.go
+++ b/plumbing/protocol/packp/uppackreq.go
@@ -1,6 +1,7 @@
package packp
import (
+ "bytes"
"fmt"
"io"
@@ -68,10 +69,20 @@ type UploadHaves struct {
// Encode encodes the UploadHaves into the Writer.
func (u *UploadHaves) Encode(w io.Writer) error {
e := pktline.NewEncoder(w)
+
+ plumbing.HashesSort(u.Haves)
+
+ var last plumbing.Hash
for _, have := range u.Haves {
+ if bytes.Compare(last[:], have[:]) == 0 {
+ continue
+ }
+
if err := e.Encodef("have %s\n", have); err != nil {
return fmt.Errorf("sending haves for %q: %s", have, err)
}
+
+ last = have
}
if len(u.Haves) != 0 {