diff options
author | Stanislav Seletskiy <s.seletskiy@gmail.com> | 2019-07-16 14:57:29 +0300 |
---|---|---|
committer | Stanislav Seletskiy <s.seletskiy@gmail.com> | 2019-07-25 17:16:12 +0300 |
commit | 17ea92a0703c21b744560e6586ee61431dba9ffb (patch) | |
tree | fc9f1dcef1eff32cce3e538c2c414eba10ecb041 | |
parent | 5d9007f27b50c17cefecd13ad160840aa4f86ed1 (diff) | |
download | go-git-17ea92a0703c21b744560e6586ee61431dba9ffb.tar.gz |
send PACK only if non-delete command present
According to:
https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt
> The packfile MUST NOT be sent if the only command used is 'delete'.
Signed-off-by: Stanislav Seletskiy <s.seletskiy@gmail.com>
-rw-r--r-- | remote.go | 36 |
1 files changed, 26 insertions, 10 deletions
@@ -168,7 +168,17 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) { } } - rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar)) + if len(hashesToPush) == 0 { + allDelete = true + for _, command := range req.Commands { + if command.Action() != packp.Delete { + allDelete = false + break + } + } + } + + rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar), allDelete) if err != nil { return err } @@ -1033,10 +1043,11 @@ func pushHashes( req *packp.ReferenceUpdateRequest, hs []plumbing.Hash, useRefDeltas bool, + allDelete bool, ) (*packp.ReportStatus, error) { rd, wr := io.Pipe() - req.Packfile = rd + config, err := s.Config() if err != nil { return nil, err @@ -1047,15 +1058,20 @@ func pushHashes( // to the channel. done := make(chan error, 1) - go func() { - e := packfile.NewEncoder(wr, s, useRefDeltas) - if _, err := e.Encode(hs, config.Pack.Window); err != nil { - done <- wr.CloseWithError(err) - return - } + if !allDelete { + req.Packfile = rd + go func() { + e := packfile.NewEncoder(wr, s, useRefDeltas) + if _, err := e.Encode(hs, config.Pack.Window); err != nil { + done <- wr.CloseWithError(err) + return + } - done <- wr.Close() - }() + done <- wr.Close() + }() + } else { + close(done) + } rs, err := sess.ReceivePack(ctx, req) if err != nil { |