diff options
author | Jeremy Stribling <strib@alum.mit.edu> | 2017-08-27 09:51:33 -0700 |
---|---|---|
committer | Jeremy Stribling <strib@alum.mit.edu> | 2017-08-28 11:29:08 -0700 |
commit | 467cb2aaa00ac30a8d2b5cc5b93951dad917ceb4 (patch) | |
tree | a50a72a64c3a48ca47778a9579c29a3c94039caf /remote.go | |
parent | bff1d06e40f70566a779880b2edeb53ad1930609 (diff) | |
download | go-git-467cb2aaa00ac30a8d2b5cc5b93951dad917ceb4.tar.gz |
remote: avoid expensive revlist operation when only deleting refs
Diffstat (limited to 'remote.go')
-rw-r--r-- | remote.go | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -92,9 +92,14 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) error { } isDelete := false + allDelete := true for _, rs := range o.RefSpecs { if rs.IsDelete() { isDelete = true + } else { + allDelete = false + } + if isDelete && !allDelete { break } } @@ -132,9 +137,13 @@ func (r *Remote) PushContext(ctx context.Context, o *PushOptions) error { // we are aware. haves = append(haves, stop...) - hashesToPush, err := revlist.Objects(r.s, objects, haves) - if err != nil { - return err + var hashesToPush []plumbing.Hash + // Avoid the expensive revlist operation if we're only doing deletes. + if !allDelete { + hashesToPush, err = revlist.Objects(r.s, objects, haves) + if err != nil { + return err + } } rs, err := pushHashes(ctx, s, r.s, req, hashesToPush) |