libgit2: Add early return to transferProgressCallback

In transferProgressCallback(), if the received objects is equal to the
total objects, return early with OK.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
This commit is contained in:
Sunny 2021-11-02 02:06:04 +05:30
parent afa82bbc7a
commit d407c824d6
1 changed files with 5 additions and 1 deletions

View File

@ -59,7 +59,11 @@ func RemoteCallbacks(ctx context.Context, opts *git.AuthOptions) git2go.RemoteCa
// libgit2 it should stop the transfer when the given context is closed (due to // libgit2 it should stop the transfer when the given context is closed (due to
// e.g. a timeout). // e.g. a timeout).
func transferProgressCallback(ctx context.Context) git2go.TransferProgressCallback { func transferProgressCallback(ctx context.Context) git2go.TransferProgressCallback {
return func(_ git2go.TransferProgress) git2go.ErrorCode { return func(p git2go.TransferProgress) git2go.ErrorCode {
// Early return if all the objects have been received.
if p.ReceivedObjects == p.TotalObjects {
return git2go.ErrorCodeOK
}
select { select {
case <-ctx.Done(): case <-ctx.Done():
return git2go.ErrorCodeUser return git2go.ErrorCodeUser