aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--remote.go36
1 files changed, 26 insertions, 10 deletions
diff --git a/remote.go b/remote.go
index 5e607ab..3ed2d0a 100644
--- a/remote.go
+++ b/remote.go
@@ -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 {