Skip to content

Commit 17ea92a

Browse files
committed
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 <[email protected]>
1 parent 5d9007f commit 17ea92a

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

remote.go

+26-10
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,17 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) (err error) {
168168
}
169169
}
170170

171-
rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar))
171+
if len(hashesToPush) == 0 {
172+
allDelete = true
173+
for _, command := range req.Commands {
174+
if command.Action() != packp.Delete {
175+
allDelete = false
176+
break
177+
}
178+
}
179+
}
180+
181+
rs, err := pushHashes(ctx, s, r.s, req, hashesToPush, r.useRefDeltas(ar), allDelete)
172182
if err != nil {
173183
return err
174184
}
@@ -1033,10 +1043,11 @@ func pushHashes(
10331043
req *packp.ReferenceUpdateRequest,
10341044
hs []plumbing.Hash,
10351045
useRefDeltas bool,
1046+
allDelete bool,
10361047
) (*packp.ReportStatus, error) {
10371048

10381049
rd, wr := io.Pipe()
1039-
req.Packfile = rd
1050+
10401051
config, err := s.Config()
10411052
if err != nil {
10421053
return nil, err
@@ -1047,15 +1058,20 @@ func pushHashes(
10471058
// to the channel.
10481059
done := make(chan error, 1)
10491060

1050-
go func() {
1051-
e := packfile.NewEncoder(wr, s, useRefDeltas)
1052-
if _, err := e.Encode(hs, config.Pack.Window); err != nil {
1053-
done <- wr.CloseWithError(err)
1054-
return
1055-
}
1061+
if !allDelete {
1062+
req.Packfile = rd
1063+
go func() {
1064+
e := packfile.NewEncoder(wr, s, useRefDeltas)
1065+
if _, err := e.Encode(hs, config.Pack.Window); err != nil {
1066+
done <- wr.CloseWithError(err)
1067+
return
1068+
}
10561069

1057-
done <- wr.Close()
1058-
}()
1070+
done <- wr.Close()
1071+
}()
1072+
} else {
1073+
close(done)
1074+
}
10591075

10601076
rs, err := sess.ReceivePack(ctx, req)
10611077
if err != nil {

0 commit comments

Comments
 (0)