diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-11-07 20:29:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-07 20:29:58 +0100 |
commit | 0ff9ef2b44c53e557c78bde0fd9c29847e5f0e23 (patch) | |
tree | b9c7485fe99e6e89fa736ceb0223aeb2ecddb77c /remote.go | |
parent | f6ed7424cbf33c7013332d7e95b4262a4bc4a523 (diff) | |
download | go-git-0ff9ef2b44c53e557c78bde0fd9c29847e5f0e23.tar.gz |
global storage interface refactor (#112)
* core: ObjectStorage, ReferenceStorage renamed to ObjectStorer and
ReferenceStorer
* rebase
* general, changes request by @alcortes
* general, changes request by @alcortes
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 30 |
1 files changed, 14 insertions, 16 deletions
@@ -18,14 +18,14 @@ var NoErrAlreadyUpToDate = errors.New("already up-to-date") // Remote represents a connection to a remote repository type Remote struct { c *config.RemoteConfig - s Storage + s Storer // cache fields, there during the connection is open upSrv common.GitUploadPackService upInfo *common.GitUploadPackInfo } -func newRemote(s Storage, c *config.RemoteConfig) *Remote { +func newRemote(s Storer, c *config.RemoteConfig) *Remote { return &Remote{s: s, c: c} } @@ -95,7 +95,7 @@ func (r *Remote) Fetch(o *FetchOptions) (err error) { return NoErrAlreadyUpToDate } - req, err := r.buildRequest(r.s.ReferenceStorage(), o, refs) + req, err := r.buildRequest(r.s, o, refs) if err != nil { return err } @@ -139,7 +139,7 @@ func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*core.Reference, } } - _, err := r.s.ObjectStorage().Get(core.CommitObject, ref.Hash()) + _, err := r.s.Object(core.CommitObject, ref.Hash()) if err == core.ErrObjectNotFound { refs = append(refs, ref) return nil @@ -150,7 +150,7 @@ func (r *Remote) getWantedReferences(spec []config.RefSpec) ([]*core.Reference, } func (r *Remote) buildRequest( - s core.ReferenceStorage, o *FetchOptions, refs []*core.Reference, + s core.ReferenceStorer, o *FetchOptions, refs []*core.Reference, ) (*common.GitUploadPackRequest, error) { req := &common.GitUploadPackRequest{} req.Depth = o.Depth @@ -159,7 +159,7 @@ func (r *Remote) buildRequest( req.Want(ref.Hash()) } - i, err := s.Iter() + i, err := s.IterReferences() if err != nil { return nil, err } @@ -177,9 +177,8 @@ func (r *Remote) buildRequest( } func (r *Remote) updateObjectStorage(reader io.Reader) error { - s := r.s.ObjectStorage() - if sw, ok := s.(core.ObjectStorageWrite); ok { - w, err := sw.Writer() + if sw, ok := r.s.(core.PackfileWriter); ok { + w, err := sw.PackfileWriter() if err != nil { return err } @@ -190,7 +189,7 @@ func (r *Remote) updateObjectStorage(reader io.Reader) error { } stream := packfile.NewScanner(reader) - d, err := packfile.NewDecoder(stream, s) + d, err := packfile.NewDecoder(stream, r.s) if err != nil { return err } @@ -212,7 +211,7 @@ func (r *Remote) updateLocalReferenceStorage(specs []config.RefSpec, refs []*cor name := spec.Dst(ref.Name()) n := core.NewHashReference(name, ref.Hash()) - if err := r.s.ReferenceStorage().Set(n); err != nil { + if err := r.s.SetReference(n); err != nil { return err } } @@ -227,13 +226,12 @@ func (r *Remote) buildFetchedTags() error { return err } - os := r.s.ObjectStorage() return iter.ForEach(func(ref *core.Reference) error { if !ref.IsTag() { return nil } - _, err := os.Get(core.AnyObject, ref.Hash()) + _, err := r.s.Object(core.AnyObject, ref.Hash()) if err == core.ErrObjectNotFound { return nil } @@ -242,7 +240,7 @@ func (r *Remote) buildFetchedTags() error { return err } - return r.s.ReferenceStorage().Set(ref) + return r.s.SetReference(ref) }) } @@ -257,12 +255,12 @@ func (r *Remote) Ref(name core.ReferenceName, resolved bool) (*core.Reference, e return core.ResolveReference(r.upInfo.Refs, name) } - return r.upInfo.Refs.Get(name) + return r.upInfo.Refs.Reference(name) } // Refs returns a map with all the References func (r *Remote) Refs() (core.ReferenceIter, error) { - return r.upInfo.Refs.Iter() + return r.upInfo.Refs.IterReferences() } // Disconnect from the remote and save the config |