aboutsummaryrefslogtreecommitdiffstats
path: root/remote.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-01-04 11:18:41 +0100
committerGitHub <noreply@github.com>2017-01-04 11:18:41 +0100
commit841abfb7dc640755c443432064252907e3e55c95 (patch)
tree8af69dcd3b301a10a3e493e2cd805cdec6dcaecd /remote.go
parent90d67bb648ae32d5b1a0f7b1af011da6dfb24315 (diff)
downloadgo-git-841abfb7dc640755c443432064252907e3e55c95.tar.gz
server: add git server implementation (#190)
* server: add generic server implementation (transport-independent), both for git-upload-pack and git-receive-pack. * server: move internal functions to internal/common. * cli: add git-receive-pack and git-upload-pack implementations. * format/packfile: add UpdateObjectStorage function, extracted from Remote. * transport: implement tranport RPC-like, only with git-upload-pack and git-receive-pack methods. Client renamed to Transport. * storer: add storer.Storer interface. * protocol/packp: add UploadPackResponse constructor with packfile. * protocol/packp: fix UploadPackResponse encoding, add tests. * protocol/packp/capability: implement All.
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go44
1 files changed, 11 insertions, 33 deletions
diff --git a/remote.go b/remote.go
index 102a764..e8d56fc 100644
--- a/remote.go
+++ b/remote.go
@@ -130,7 +130,7 @@ func (r *Remote) fetch(o *FetchOptions) (refs storer.ReferenceStorer, err error)
o.RefSpecs = r.c.Fetch
}
- s, err := newFetchPackSession(r.c.URL)
+ s, err := newUploadPackSession(r.c.URL)
if err != nil {
return nil, err
}
@@ -173,25 +173,25 @@ func (r *Remote) fetch(o *FetchOptions) (refs storer.ReferenceStorer, err error)
return remoteRefs, err
}
-func newFetchPackSession(url string) (transport.FetchPackSession, error) {
+func newUploadPackSession(url string) (transport.UploadPackSession, error) {
c, ep, err := newClient(url)
if err != nil {
return nil, err
}
- return c.NewFetchPackSession(ep)
+ return c.NewUploadPackSession(ep)
}
-func newSendPackSession(url string) (transport.SendPackSession, error) {
+func newSendPackSession(url string) (transport.ReceivePackSession, error) {
c, ep, err := newClient(url)
if err != nil {
return nil, err
}
- return c.NewSendPackSession(ep)
+ return c.NewReceivePackSession(ep)
}
-func newClient(url string) (transport.Client, transport.Endpoint, error) {
+func newClient(url string) (transport.Transport, transport.Endpoint, error) {
ep, err := transport.NewEndpoint(url)
if err != nil {
return nil, transport.Endpoint{}, err
@@ -205,10 +205,10 @@ func newClient(url string) (transport.Client, transport.Endpoint, error) {
return c, ep, err
}
-func (r *Remote) fetchPack(o *FetchOptions, s transport.FetchPackSession,
+func (r *Remote) fetchPack(o *FetchOptions, s transport.UploadPackSession,
req *packp.UploadPackRequest) (err error) {
- reader, err := s.FetchPack(req)
+ reader, err := s.UploadPack(req)
if err != nil {
return err
}
@@ -219,7 +219,7 @@ func (r *Remote) fetchPack(o *FetchOptions, s transport.FetchPackSession,
return err
}
- if err = r.updateObjectStorage(
+ if err = packfile.UpdateObjectStorage(r.s,
buildSidebandIfSupported(req.Capabilities, reader, r.p),
); err != nil {
return err
@@ -406,28 +406,6 @@ func (r *Remote) newUploadPackRequest(o *FetchOptions,
return req, nil
}
-func (r *Remote) updateObjectStorage(reader io.Reader) error {
- if sw, ok := r.s.(storer.PackfileWriter); ok {
- w, err := sw.PackfileWriter()
- if err != nil {
- return err
- }
-
- defer w.Close()
- _, err = io.Copy(w, reader)
- return err
- }
-
- stream := packfile.NewScanner(reader)
- d, err := packfile.NewDecoder(stream, r.s)
- if err != nil {
- return err
- }
-
- _, err = d.Decode()
- return err
-}
-
func buildSidebandIfSupported(l *capability.List, reader io.Reader, p sideband.Progress) io.Reader {
var t sideband.Type
@@ -532,7 +510,7 @@ func referencesToHashes(refs storer.ReferenceStorer) ([]plumbing.Hash, error) {
return hs, nil
}
-func pushHashes(sess transport.SendPackSession, sto storer.EncodedObjectStorer,
+func pushHashes(sess transport.ReceivePackSession, sto storer.EncodedObjectStorer,
req *packp.ReferenceUpdateRequest, hs []plumbing.Hash) (*packp.ReportStatus, error) {
rd, wr := io.Pipe()
@@ -548,7 +526,7 @@ func pushHashes(sess transport.SendPackSession, sto storer.EncodedObjectStorer,
done <- wr.Close()
}()
- rs, err := sess.SendPack(req)
+ rs, err := sess.ReceivePack(req)
if err != nil {
return nil, err
}