Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit f2a7dad

Browse files
authored
Merge pull request #987 from bashims/945-push-ref-deltas
remote: use reference deltas on push when the remote server does not …
2 parents 1a2248b + 1618e1c commit f2a7dad

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

remote.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
155155
}
156156
}
157157

158-
rs, err := pushHashes(ctx, s, r.s, req, hashesToPush)
158+
rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar))
159159
if err != nil {
160160
return err
161161
}
@@ -167,6 +167,10 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
167167
return r.updateRemoteReferenceStorage(req, rs)
168168
}
169169

170+
func (r *Remote) useRefDeltas(ar *packp.AdvRefs) bool {
171+
return !ar.Capabilities.Supports(capability.OFSDelta)
172+
}
173+
170174
func (r *Remote) newReferenceUpdateRequest(
171175
o *PushOptions,
172176
localRefs []*plumbing.Reference,
@@ -994,6 +998,7 @@ func pushHashes(
994998
s storage.Storer,
995999
req *packp.ReferenceUpdateRequest,
9961000
hs []plumbing.Hash,
1001+
useRefDeltas bool,
9971002
) (*packp.ReportStatus, error) {
9981003

9991004
rd, wr := io.Pipe()
@@ -1004,7 +1009,7 @@ func pushHashes(
10041009
}
10051010
done := make(chan error)
10061011
go func() {
1007-
e := packfile.NewEncoder(wr, s, false)
1012+
e := packfile.NewEncoder(wr, s, useRefDeltas)
10081013
if _, err := e.Encode(hs, config.Pack.Window); err != nil {
10091014
done <- wr.CloseWithError(err)
10101015
return

remote_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"gopkg.in/src-d/go-git.v4/plumbing"
1212
"gopkg.in/src-d/go-git.v4/plumbing/cache"
1313
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp"
14+
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
1415
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1516
"gopkg.in/src-d/go-git.v4/storage"
1617
"gopkg.in/src-d/go-git.v4/storage/filesystem"
@@ -798,3 +799,25 @@ func (s *RemoteSuite) TestUpdateShallows(c *C) {
798799
c.Assert(shallow, DeepEquals, t.result)
799800
}
800801
}
802+
803+
func (s *RemoteSuite) TestUseRefDeltas(c *C) {
804+
url := c.MkDir()
805+
_, err := PlainInit(url, true)
806+
c.Assert(err, IsNil)
807+
808+
fs := fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit()
809+
sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
810+
811+
r := newRemote(sto, &config.RemoteConfig{
812+
Name: DefaultRemoteName,
813+
URLs: []string{url},
814+
})
815+
816+
ar := packp.NewAdvRefs()
817+
818+
ar.Capabilities.Add(capability.OFSDelta)
819+
c.Assert(r.useRefDeltas(ar), Equals, false)
820+
821+
ar.Capabilities.Delete(capability.OFSDelta)
822+
c.Assert(r.useRefDeltas(ar), Equals, true)
823+
}

0 commit comments

Comments
 (0)