@@ -114,10 +114,6 @@ type sshSmartSubtransport struct {
114
114
115
115
closedSessions * int32
116
116
117
- con connection
118
- }
119
-
120
- type connection struct {
121
117
client * ssh.Client
122
118
session * ssh.Session
123
119
currentStream * sshSmartSubtransportStream
@@ -155,17 +151,17 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go.
155
151
var cmd string
156
152
switch action {
157
153
case git2go .SmartServiceActionUploadpackLs , git2go .SmartServiceActionUploadpack :
158
- if t .con . currentStream != nil {
154
+ if t .currentStream != nil {
159
155
if t .lastAction == git2go .SmartServiceActionUploadpackLs {
160
- return t .con . currentStream , nil
156
+ return t .currentStream , nil
161
157
}
162
158
}
163
159
cmd = fmt .Sprintf ("git-upload-pack '%s'" , uPath )
164
160
165
161
case git2go .SmartServiceActionReceivepackLs , git2go .SmartServiceActionReceivepack :
166
- if t .con . currentStream != nil {
162
+ if t .currentStream != nil {
167
163
if t .lastAction == git2go .SmartServiceActionReceivepackLs {
168
- return t .con . currentStream , nil
164
+ return t .currentStream , nil
169
165
}
170
166
}
171
167
cmd = fmt .Sprintf ("git-receive-pack '%s'" , uPath )
@@ -212,7 +208,7 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go.
212
208
return nil
213
209
}
214
210
215
- if t .con . connected {
211
+ if t .connected {
216
212
// The connection is no longer shared across actions, so ensures
217
213
// all has been released before starting a new connection.
218
214
_ = t .Close ()
@@ -224,18 +220,18 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go.
224
220
}
225
221
226
222
t .logger .V (logger .TraceLevel ).Info ("creating new ssh session" )
227
- if t .con . session , err = t . con .client .NewSession (); err != nil {
223
+ if t .session , err = t .client .NewSession (); err != nil {
228
224
return nil , err
229
225
}
230
226
231
- if t .stdin , err = t .con . session .StdinPipe (); err != nil {
227
+ if t .stdin , err = t .session .StdinPipe (); err != nil {
232
228
return nil , err
233
229
}
234
230
235
231
var w * io.PipeWriter
236
232
var reader io.Reader
237
233
t .stdout , w = io .Pipe ()
238
- if reader , err = t .con . session .StdoutPipe (); err != nil {
234
+ if reader , err = t .session .StdoutPipe (); err != nil {
239
235
return nil , err
240
236
}
241
237
@@ -284,16 +280,16 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go.
284
280
}()
285
281
286
282
t .logger .V (logger .TraceLevel ).Info ("run on remote" , "cmd" , cmd )
287
- if err := t .con . session .Start (cmd ); err != nil {
283
+ if err := t .session .Start (cmd ); err != nil {
288
284
return nil , err
289
285
}
290
286
291
287
t .lastAction = action
292
- t .con . currentStream = & sshSmartSubtransportStream {
288
+ t .currentStream = & sshSmartSubtransportStream {
293
289
owner : t ,
294
290
}
295
291
296
- return t .con . currentStream , nil
292
+ return t .currentStream , nil
297
293
}
298
294
299
295
func (t * sshSmartSubtransport ) createConn (addr string , sshConfig * ssh.ClientConfig ) error {
@@ -310,8 +306,8 @@ func (t *sshSmartSubtransport) createConn(addr string, sshConfig *ssh.ClientConf
310
306
return err
311
307
}
312
308
313
- t .con . connected = true
314
- t .con . client = ssh .NewClient (c , chans , reqs )
309
+ t .connected = true
310
+ t .client = ssh .NewClient (c , chans , reqs )
315
311
316
312
return nil
317
313
}
@@ -328,25 +324,25 @@ func (t *sshSmartSubtransport) createConn(addr string, sshConfig *ssh.ClientConf
328
324
func (t * sshSmartSubtransport ) Close () error {
329
325
t .logger .V (logger .TraceLevel ).Info ("sshSmartSubtransport.Close()" )
330
326
331
- t .con . currentStream = nil
332
- if t .con . client != nil && t .stdin != nil {
327
+ t .currentStream = nil
328
+ if t .client != nil && t .stdin != nil {
333
329
_ = t .stdin .Close ()
334
330
}
335
331
t .stdin = nil
336
332
337
- if t .con . session != nil {
333
+ if t .session != nil {
338
334
t .logger .V (logger .TraceLevel ).Info ("session.Close()" )
339
- _ = t .con . session .Close ()
335
+ _ = t .session .Close ()
340
336
}
341
- t .con . session = nil
337
+ t .session = nil
342
338
343
- if t .con . client != nil {
344
- _ = t .con . client .Close ()
339
+ if t .client != nil {
340
+ _ = t .client .Close ()
345
341
t .logger .V (logger .TraceLevel ).Info ("close client" )
346
342
}
347
- t .con . client = nil
343
+ t .client = nil
348
344
349
- t .con . connected = false
345
+ t .connected = false
350
346
atomic .AddInt32 (t .closedSessions , 1 )
351
347
352
348
return nil
0 commit comments