aboutsummaryrefslogtreecommitdiffstats
path: root/remote.go
diff options
context:
space:
mode:
Diffstat (limited to 'remote.go')
-rw-r--r--remote.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/remote.go b/remote.go
index 0556b98..de537ce 100644
--- a/remote.go
+++ b/remote.go
@@ -6,8 +6,10 @@ import (
"fmt"
"io"
+ "gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/plumbing"
+ "gopkg.in/src-d/go-git.v4/plumbing/cache"
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
@@ -18,6 +20,7 @@ import (
"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"
+ "gopkg.in/src-d/go-git.v4/storage/filesystem"
"gopkg.in/src-d/go-git.v4/storage/memory"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
@@ -149,13 +152,23 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
var hashesToPush []plumbing.Hash
// Avoid the expensive revlist operation if we're only doing deletes.
if !allDelete {
- hashesToPush, err = revlist.Objects(r.s, objects, haves)
+ if r.c.IsFirstURLLocal() {
+ // If we're are pushing to a local repo, it might be much
+ // faster to use a local storage layer to get the commits
+ // to ignore, when calculating the object revlist.
+ localStorer := filesystem.NewStorage(
+ osfs.New(r.c.URLs[0]), cache.NewObjectLRUDefault())
+ hashesToPush, err = revlist.ObjectsWithStorageForIgnores(
+ r.s, localStorer, objects, haves)
+ } else {
+ hashesToPush, err = revlist.Objects(r.s, objects, haves)
+ }
if err != nil {
return err
}
}
- rs, err := pushHashes(ctx, s, r.s, req, hashesToPush)
+ rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar))
if err != nil {
return err
}
@@ -167,6 +180,10 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
return r.updateRemoteReferenceStorage(req, rs)
}
+func (r *Remote) useRefDeltas(ar *packp.AdvRefs) bool {
+ return !ar.Capabilities.Supports(capability.OFSDelta)
+}
+
func (r *Remote) newReferenceUpdateRequest(
o *PushOptions,
localRefs []*plumbing.Reference,
@@ -994,6 +1011,7 @@ func pushHashes(
s storage.Storer,
req *packp.ReferenceUpdateRequest,
hs []plumbing.Hash,
+ useRefDeltas bool,
) (*packp.ReportStatus, error) {
rd, wr := io.Pipe()
@@ -1004,7 +1022,7 @@ func pushHashes(
}
done := make(chan error)
go func() {
- e := packfile.NewEncoder(wr, s, false)
+ e := packfile.NewEncoder(wr, s, useRefDeltas)
if _, err := e.Encode(hs, config.Pack.Window); err != nil {
done <- wr.CloseWithError(err)
return