aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/transport/fetch_pack.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-25 09:25:49 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2016-11-25 09:25:49 +0100
commit9e34f68d980de57631c588aaa910c9ea95ed7c2e (patch)
treeb1bd9f867b757ca46ada2f349d122723dde3529c /plumbing/transport/fetch_pack.go
parent8966c042795509ed17730e50d352ad69901c3da8 (diff)
downloadgo-git-9e34f68d980de57631c588aaa910c9ea95ed7c2e.tar.gz
plumbing/transport: add common tests and fixes. (#136)
* plumbing/transport: add common tests and fixes. * add common test suite for different transport implementations. * fix different behaviour on error handling for ssh and http. fixes issue #123. * support detecting unexisting repositories with SSH + GitHub/Bitbucket (apparently, there is no standard for all SSH servers). * remove ssh.NewClient (only DefaultClient makes sense at the moment). * make ssh.Client and http.Client private. * utils/ioutil: utilities to work with io interfaces. * * transport: test actual objects fetched, not just packfile size. * * fix doc typo. * * improve UploadPackRequest.IsEmpty
Diffstat (limited to 'plumbing/transport/fetch_pack.go')
-rw-r--r--plumbing/transport/fetch_pack.go24
1 files changed, 23 insertions, 1 deletions
diff --git a/plumbing/transport/fetch_pack.go b/plumbing/transport/fetch_pack.go
index 3b2a39c..5346e9d 100644
--- a/plumbing/transport/fetch_pack.go
+++ b/plumbing/transport/fetch_pack.go
@@ -33,7 +33,7 @@ func (i *UploadPackInfo) Decode(r io.Reader) error {
ar := advrefs.New()
if err := d.Decode(ar); err != nil {
if err == advrefs.ErrEmpty {
- return plumbing.NewPermanentError(err)
+ return err
}
return plumbing.NewUnexpectedError(err)
}
@@ -128,6 +128,28 @@ func (r *UploadPackRequest) Have(h ...plumbing.Hash) {
r.Haves = append(r.Haves, h...)
}
+func (r *UploadPackRequest) IsEmpty() bool {
+ return isSubset(r.Wants, r.Haves)
+}
+
+func isSubset(needle []plumbing.Hash, haystack []plumbing.Hash) bool {
+ for _, h := range needle {
+ found := false
+ for _, oh := range haystack {
+ if h == oh {
+ found = true
+ break
+ }
+ }
+
+ if !found {
+ return false
+ }
+ }
+
+ return true
+}
+
func (r *UploadPackRequest) String() string {
b, _ := ioutil.ReadAll(r.Reader())
return string(b)