aboutsummaryrefslogtreecommitdiffstats
path: root/remote.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-11-28 09:57:38 +0100
committerGitHub <noreply@github.com>2016-11-28 09:57:38 +0100
commit68893edf9ddc3de181431f1552e3b773cb66f080 (patch)
treef45e5fa18e10168a278b7d0ed7dea984ff9969f7 /remote.go
parentf9adb3565b36ba1573102f954d0ee916009efac2 (diff)
downloadgo-git-68893edf9ddc3de181431f1552e3b773cb66f080.tar.gz
remove old types from transport and use packp (#142)
* protocol: move UploadPackRequest to protocol. * UploadPackRequest is now defined as an embedding of UploadRequest and UploadHaves. * Move http encoding specific code from UploadPackRequest to transport/http. * rename UlReq to UploadRequest * packp: move AdvRefs Encoder/Decoder to Encode/Decode methods. * packp: move UploadRequest Encoder/Decoder to Encode/Decode methods. * packp: Remove transport.UploadPackInfo in favor of packp. AdvRefs.
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go56
1 files changed, 34 insertions, 22 deletions
diff --git a/remote.go b/remote.go
index 5b6411d..feab72a 100644
--- a/remote.go
+++ b/remote.go
@@ -12,6 +12,7 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/plumbing/transport"
"gopkg.in/src-d/go-git.v4/plumbing/transport/client"
+ "gopkg.in/src-d/go-git.v4/storage/memory"
)
var NoErrAlreadyUpToDate = errors.New("already up-to-date")
@@ -25,7 +26,8 @@ type Remote struct {
endpoint transport.Endpoint
client transport.Client
fetchSession transport.FetchPackSession
- upInfo *transport.UploadPackInfo
+ advRefs *packp.AdvRefs
+ refs memory.ReferenceStorage
}
func newRemote(s Storer, c *config.RemoteConfig) *Remote {
@@ -49,7 +51,7 @@ func (r *Remote) Connect() error {
return nil
}
- return r.retrieveUpInfo()
+ return r.retrieveAdvertisedReferences()
}
func (r *Remote) initClient() error {
@@ -71,20 +73,25 @@ func (r *Remote) initClient() error {
return nil
}
-func (r *Remote) retrieveUpInfo() error {
+func (r *Remote) retrieveAdvertisedReferences() error {
var err error
- r.upInfo, err = r.fetchSession.AdvertisedReferences()
+ r.advRefs, err = r.fetchSession.AdvertisedReferences()
+ if err != nil {
+ return err
+ }
+
+ r.refs, err = r.advRefs.AllReferences()
return err
}
-// Info returns the git-upload-pack info
-func (r *Remote) Info() *transport.UploadPackInfo {
- return r.upInfo
+// AdvertisedReferences returns the git-upload-pack advertised references.
+func (r *Remote) AdvertisedReferences() *packp.AdvRefs {
+ return r.advRefs
}
// Capabilities returns the remote capabilities
func (r *Remote) Capabilities() *packp.Capabilities {
- return r.upInfo.Capabilities
+ return r.advRefs.Capabilities
}
// Fetch returns a reader using the request
@@ -126,7 +133,7 @@ func (r *Remote) Fetch(o *FetchOptions) (err error) {
func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*plumbing.Reference, error) {
var refs []*plumbing.Reference
- iter, err := r.Refs()
+ iter, err := r.References()
if err != nil {
return refs, err
}
@@ -162,9 +169,9 @@ func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*plumbing.Referen
func (r *Remote) buildRequest(
s storer.ReferenceStorer, o *FetchOptions, refs []*plumbing.Reference,
-) (*transport.UploadPackRequest, error) {
- req := &transport.UploadPackRequest{}
- req.Depth = o.Depth
+) (*packp.UploadPackRequest, error) {
+ req := packp.NewUploadPackRequest()
+ req.Depth = packp.DepthCommits(o.Depth)
for _, ref := range refs {
req.Want(ref.Hash())
@@ -232,7 +239,7 @@ func (r *Remote) updateLocalReferenceStorage(specs []config.RefSpec, refs []*plu
}
func (r *Remote) buildFetchedTags() error {
- iter, err := r.Refs()
+ iter, err := r.References()
if err != nil {
return err
}
@@ -257,26 +264,31 @@ func (r *Remote) buildFetchedTags() error {
// Head returns the Reference of the HEAD
func (r *Remote) Head() *plumbing.Reference {
- return r.upInfo.Head()
+ ref, err := storer.ResolveReference(r.refs, plumbing.HEAD)
+ if err != nil {
+ return nil
+ }
+
+ return ref
}
-// Ref returns the Hash pointing the given refName
-func (r *Remote) Ref(name plumbing.ReferenceName, resolved bool) (*plumbing.Reference, error) {
+// Reference returns a Reference for a ReferenceName.
+func (r *Remote) Reference(name plumbing.ReferenceName, resolved bool) (*plumbing.Reference, error) {
if resolved {
- return storer.ResolveReference(r.upInfo.Refs, name)
+ return storer.ResolveReference(r.refs, name)
}
- return r.upInfo.Refs.Reference(name)
+ return r.refs.Reference(name)
}
-// Refs returns a map with all the References
-func (r *Remote) Refs() (storer.ReferenceIter, error) {
- return r.upInfo.Refs.IterReferences()
+// References returns an iterator for all references.
+func (r *Remote) References() (storer.ReferenceIter, error) {
+ return r.refs.IterReferences()
}
// Disconnect from the remote and save the config
func (r *Remote) Disconnect() error {
- r.upInfo = nil
+ r.advRefs = nil
return r.fetchSession.Close()
}