47
47
func RemoteCallbacks (ctx context.Context , opts * git.AuthOptions ) git2go.RemoteCallbacks {
48
48
if opts != nil {
49
49
return git2go.RemoteCallbacks {
50
- TransferProgressCallback : transferProgressCallback (ctx ),
51
- CredentialsCallback : credentialsCallback (opts ),
52
- CertificateCheckCallback : certificateCallback (opts ),
50
+ SidebandProgressCallback : transportMessageCallback (ctx ),
51
+ TransferProgressCallback : transferProgressCallback (ctx ),
52
+ PushTransferProgressCallback : pushTransferProgressCallback (ctx ),
53
+ CredentialsCallback : credentialsCallback (opts ),
54
+ CertificateCheckCallback : certificateCallback (opts ),
53
55
}
54
56
}
55
57
return git2go.RemoteCallbacks {}
@@ -73,6 +75,38 @@ func transferProgressCallback(ctx context.Context) git2go.TransferProgressCallba
73
75
}
74
76
}
75
77
78
+ // transportMessageCallback constructs TransportMessageCallback which signals
79
+ // libgit2 it should cancel the network operation when the given context is
80
+ // closed.
81
+ func transportMessageCallback (ctx context.Context ) git2go.TransportMessageCallback {
82
+ return func (_ string ) git2go.ErrorCode {
83
+ select {
84
+ case <- ctx .Done ():
85
+ return git2go .ErrorCodeUser
86
+ default :
87
+ return git2go .ErrorCodeOK
88
+ }
89
+ }
90
+ }
91
+
92
+ // pushTransferProgressCallback constructs PushTransferProgressCallback which
93
+ // signals libgit2 it should stop the push transfer when the given context is
94
+ // closed (due to e.g. a timeout).
95
+ func pushTransferProgressCallback (ctx context.Context ) git2go.PushTransferProgressCallback {
96
+ return func (current , total uint32 , _ uint ) git2go.ErrorCode {
97
+ // Early return if current equals total.
98
+ if current == total {
99
+ return git2go .ErrorCodeOK
100
+ }
101
+ select {
102
+ case <- ctx .Done ():
103
+ return git2go .ErrorCodeUser
104
+ default :
105
+ return git2go .ErrorCodeOK
106
+ }
107
+ }
108
+ }
109
+
76
110
// credentialsCallback constructs CredentialsCallbacks with the given options
77
111
// for git.Transport, and returns the result.
78
112
func credentialsCallback (opts * git.AuthOptions ) git2go.CredentialsCallback {
0 commit comments