aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStanislav Seletskiy <s.seletskiy@gmail.com>2019-07-16 14:57:29 +0300
committerStanislav Seletskiy <s.seletskiy@gmail.com>2019-07-25 17:16:12 +0300
commit17ea92a0703c21b744560e6586ee61431dba9ffb (patch)
treefc9f1dcef1eff32cce3e538c2c414eba10ecb041
parent5d9007f27b50c17cefecd13ad160840aa4f86ed1 (diff)
downloadgo-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.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 {