Skip to content

Commit

Permalink
Merge pull request src-d#987 from bashims/945-push-ref-deltas
Browse files Browse the repository at this point in the history
remote: use reference deltas on push when the remote server does not …
  • Loading branch information
mcuadros authored Oct 17, 2018
2 parents 1a2248b + 1618e1c commit f2a7dad
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
9 changes: 7 additions & 2 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
}
}

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
}
Expand All @@ -167,6 +167,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,
Expand Down Expand Up @@ -994,6 +998,7 @@ func pushHashes(
s storage.Storer,
req *packp.ReferenceUpdateRequest,
hs []plumbing.Hash,
useRefDeltas bool,
) (*packp.ReportStatus, error) {

rd, wr := io.Pipe()
Expand All @@ -1004,7 +1009,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
Expand Down
23 changes: 23 additions & 0 deletions remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"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/protocol/packp"
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/capability"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage"
"gopkg.in/src-d/go-git.v4/storage/filesystem"
Expand Down Expand Up @@ -798,3 +799,25 @@ func (s *RemoteSuite) TestUpdateShallows(c *C) {
c.Assert(shallow, DeepEquals, t.result)
}
}

func (s *RemoteSuite) TestUseRefDeltas(c *C) {
url := c.MkDir()
_, err := PlainInit(url, true)
c.Assert(err, IsNil)

fs := fixtures.ByURL("https://github.com/git-fixtures/tags.git").One().DotGit()
sto := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())

r := newRemote(sto, &config.RemoteConfig{
Name: DefaultRemoteName,
URLs: []string{url},
})

ar := packp.NewAdvRefs()

ar.Capabilities.Add(capability.OFSDelta)
c.Assert(r.useRefDeltas(ar), Equals, false)

ar.Capabilities.Delete(capability.OFSDelta)
c.Assert(r.useRefDeltas(ar), Equals, true)
}

0 comments on commit f2a7dad

Please sign in to comment.