diff --git a/pkg/git/libgit2/managed/ssh.go b/pkg/git/libgit2/managed/ssh.go index 32553797e..1c11afe86 100644 --- a/pkg/git/libgit2/managed/ssh.go +++ b/pkg/git/libgit2/managed/ssh.go @@ -114,10 +114,6 @@ type sshSmartSubtransport struct { closedSessions *int32 - con connection -} - -type connection struct { client *ssh.Client session *ssh.Session currentStream *sshSmartSubtransportStream @@ -155,17 +151,17 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go. var cmd string switch action { case git2go.SmartServiceActionUploadpackLs, git2go.SmartServiceActionUploadpack: - if t.con.currentStream != nil { + if t.currentStream != nil { if t.lastAction == git2go.SmartServiceActionUploadpackLs { - return t.con.currentStream, nil + return t.currentStream, nil } } cmd = fmt.Sprintf("git-upload-pack '%s'", uPath) case git2go.SmartServiceActionReceivepackLs, git2go.SmartServiceActionReceivepack: - if t.con.currentStream != nil { + if t.currentStream != nil { if t.lastAction == git2go.SmartServiceActionReceivepackLs { - return t.con.currentStream, nil + return t.currentStream, nil } } cmd = fmt.Sprintf("git-receive-pack '%s'", uPath) @@ -212,7 +208,7 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go. return nil } - if t.con.connected { + if t.connected { // The connection is no longer shared across actions, so ensures // all has been released before starting a new connection. _ = t.Close() @@ -224,18 +220,18 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go. } t.logger.V(logger.TraceLevel).Info("creating new ssh session") - if t.con.session, err = t.con.client.NewSession(); err != nil { + if t.session, err = t.client.NewSession(); err != nil { return nil, err } - if t.stdin, err = t.con.session.StdinPipe(); err != nil { + if t.stdin, err = t.session.StdinPipe(); err != nil { return nil, err } var w *io.PipeWriter var reader io.Reader t.stdout, w = io.Pipe() - if reader, err = t.con.session.StdoutPipe(); err != nil { + if reader, err = t.session.StdoutPipe(); err != nil { return nil, err } @@ -284,16 +280,16 @@ func (t *sshSmartSubtransport) Action(transportOptionsURL string, action git2go. }() t.logger.V(logger.TraceLevel).Info("run on remote", "cmd", cmd) - if err := t.con.session.Start(cmd); err != nil { + if err := t.session.Start(cmd); err != nil { return nil, err } t.lastAction = action - t.con.currentStream = &sshSmartSubtransportStream{ + t.currentStream = &sshSmartSubtransportStream{ owner: t, } - return t.con.currentStream, nil + return t.currentStream, nil } func (t *sshSmartSubtransport) createConn(addr string, sshConfig *ssh.ClientConfig) error { @@ -310,8 +306,8 @@ func (t *sshSmartSubtransport) createConn(addr string, sshConfig *ssh.ClientConf return err } - t.con.connected = true - t.con.client = ssh.NewClient(c, chans, reqs) + t.connected = true + t.client = ssh.NewClient(c, chans, reqs) return nil } @@ -328,25 +324,25 @@ func (t *sshSmartSubtransport) createConn(addr string, sshConfig *ssh.ClientConf func (t *sshSmartSubtransport) Close() error { t.logger.V(logger.TraceLevel).Info("sshSmartSubtransport.Close()") - t.con.currentStream = nil - if t.con.client != nil && t.stdin != nil { + t.currentStream = nil + if t.client != nil && t.stdin != nil { _ = t.stdin.Close() } t.stdin = nil - if t.con.session != nil { + if t.session != nil { t.logger.V(logger.TraceLevel).Info("session.Close()") - _ = t.con.session.Close() + _ = t.session.Close() } - t.con.session = nil + t.session = nil - if t.con.client != nil { - _ = t.con.client.Close() + if t.client != nil { + _ = t.client.Close() t.logger.V(logger.TraceLevel).Info("close client") } - t.con.client = nil + t.client = nil - t.con.connected = false + t.connected = false atomic.AddInt32(t.closedSessions, 1) return nil