Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31fdc3e

Browse files
committed
ssh/connection.go: rename SSHTransfer receiver var
In PR git-lfs#4446 we defined a new SSHTransfer structure and a set of methods for it in our ssh/connection.go source file, and used the name "tr" for the receiver variables of those methods. Later, in commit 5dbbf13 of PR git-lfs#5674, we imported our "tr" message translation package into the same source file in order to format and localize an error message generated by the startConnection() function. Because this function is not one of the methods of the SSHTransfer structure there was no conflict with the "tr" receiver variables of those methods. However, in subsequent commits in this PR we expect to revise one of the SSHTransfer structure's methods to output an error message, and will want to use the Get() method of the "tr" package's global Tr variable. We are not able to do this with the current name of the "tr" receiver variable as it masks the "tr" package name within the method's scope. Therefore we now rename all our "tr" receiver variables to "st" in the ssh/connection.go source file, so as to avoid any namespace conflicts with our "tr" package.
1 parent a3cc1fe commit 31fdc3e

1 file changed

Lines changed: 44 additions & 44 deletions

File tree

ssh/connection.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -90,82 +90,82 @@ func startConnection(id int, osEnv config.Environment, gitEnv config.Environment
9090

9191
// Connection returns the nth connection (starting from 0) in this transfer
9292
// instance or nil if there is no such item.
93-
func (tr *SSHTransfer) IsMultiplexingEnabled() bool {
94-
return tr.multiplexing
93+
func (st *SSHTransfer) IsMultiplexingEnabled() bool {
94+
return st.multiplexing
9595
}
9696

9797
// Connection returns the nth connection (starting from 0) in this transfer
9898
// instance if it is initialized and otherwise initializes a new connection and
9999
// saves it in the nth position. In all cases, nil is returned if n is greater
100100
// than the maximum number of connections.
101-
func (tr *SSHTransfer) Connection(n int) (*PktlineConnection, error) {
102-
tr.lock.RLock()
103-
if n >= len(tr.conn) {
104-
tr.lock.RUnlock()
101+
func (st *SSHTransfer) Connection(n int) (*PktlineConnection, error) {
102+
st.lock.RLock()
103+
if n >= len(st.conn) {
104+
st.lock.RUnlock()
105105
return nil, nil
106106
}
107-
if tr.conn[n] != nil {
108-
defer tr.lock.RUnlock()
109-
return tr.conn[n], nil
107+
if st.conn[n] != nil {
108+
defer st.lock.RUnlock()
109+
return st.conn[n], nil
110110
}
111-
tr.lock.RUnlock()
111+
st.lock.RUnlock()
112112

113-
tr.lock.Lock()
114-
defer tr.lock.Unlock()
115-
if tr.conn[n] != nil {
116-
return tr.conn[n], nil
113+
st.lock.Lock()
114+
defer st.lock.Unlock()
115+
if st.conn[n] != nil {
116+
return st.conn[n], nil
117117
}
118-
conn, _, err := tr.spawnConnection(n)
118+
conn, _, err := st.spawnConnection(n)
119119
if err != nil {
120120
return nil, err
121121
}
122-
tr.conn[n] = conn
122+
st.conn[n] = conn
123123
return conn, nil
124124
}
125125

126126
// ConnectionCount returns the number of connections this object has.
127-
func (tr *SSHTransfer) ConnectionCount() int {
128-
tr.lock.RLock()
129-
defer tr.lock.RUnlock()
130-
return len(tr.conn)
127+
func (st *SSHTransfer) ConnectionCount() int {
128+
st.lock.RLock()
129+
defer st.lock.RUnlock()
130+
return len(st.conn)
131131
}
132132

133133
// SetConnectionCount sets the number of connections to the specified number.
134-
func (tr *SSHTransfer) SetConnectionCount(n int) error {
135-
tr.lock.Lock()
136-
defer tr.lock.Unlock()
137-
return tr.setConnectionCount(n)
134+
func (st *SSHTransfer) SetConnectionCount(n int) error {
135+
st.lock.Lock()
136+
defer st.lock.Unlock()
137+
return st.setConnectionCount(n)
138138
}
139139

140140
// SetConnectionCountAtLeast sets the number of connections to be not less than
141141
// the specified number.
142-
func (tr *SSHTransfer) SetConnectionCountAtLeast(n int) error {
143-
tr.lock.Lock()
144-
defer tr.lock.Unlock()
145-
count := len(tr.conn)
142+
func (st *SSHTransfer) SetConnectionCountAtLeast(n int) error {
143+
st.lock.Lock()
144+
defer st.lock.Unlock()
145+
count := len(st.conn)
146146
if n <= count {
147147
return nil
148148
}
149-
return tr.setConnectionCount(n)
149+
return st.setConnectionCount(n)
150150
}
151151

152-
func (tr *SSHTransfer) spawnConnection(n int) (*PktlineConnection, string, error) {
153-
conn, _, controlPath, err := startConnection(n, tr.osEnv, tr.gitEnv, tr.meta, tr.operation, tr.controlPath)
152+
func (st *SSHTransfer) spawnConnection(n int) (*PktlineConnection, string, error) {
153+
conn, _, controlPath, err := startConnection(n, st.osEnv, st.gitEnv, st.meta, st.operation, st.controlPath)
154154
if err != nil {
155155
tracerx.Printf("failed to spawn pure SSH connection (#%d): %s", n, err)
156156
return nil, "", err
157157
}
158158
return conn, controlPath, err
159159
}
160160

161-
func (tr *SSHTransfer) setConnectionCount(n int) error {
162-
count := len(tr.conn)
161+
func (st *SSHTransfer) setConnectionCount(n int) error {
162+
count := len(st.conn)
163163
if n < count {
164164
tn := n
165165
if tn == 0 {
166166
tn = 1
167167
}
168-
for i, item := range tr.conn[tn:count] {
168+
for i, item := range st.conn[tn:count] {
169169
if item == nil {
170170
tracerx.Printf("skipping uninitialized lazy pure SSH connection (#%d) (resetting total from %d to %d)", i, count, n)
171171
continue
@@ -175,33 +175,33 @@ func (tr *SSHTransfer) setConnectionCount(n int) error {
175175
return err
176176
}
177177
}
178-
tr.conn = tr.conn[0:tn]
178+
st.conn = st.conn[0:tn]
179179
} else if n > count {
180180
for i := count; i < n; i++ {
181181
if i == 0 {
182-
conn, controlPath, err := tr.spawnConnection(i)
182+
conn, controlPath, err := st.spawnConnection(i)
183183
if err != nil {
184184
return err
185185
}
186-
tr.conn = append(tr.conn, conn)
187-
tr.controlPath = controlPath
186+
st.conn = append(st.conn, conn)
187+
st.controlPath = controlPath
188188
} else {
189-
tr.conn = append(tr.conn, nil)
189+
st.conn = append(st.conn, nil)
190190
}
191191
}
192192
}
193193
if n == 0 && count > 0 {
194194
tracerx.Printf("terminating pure SSH connection (#0) (resetting total from %d to %d)", count, n)
195-
if err := tr.conn[0].End(); err != nil {
195+
if err := st.conn[0].End(); err != nil {
196196
return err
197197
}
198-
tr.conn = nil
199-
tr.controlPath = ""
198+
st.conn = nil
199+
st.controlPath = ""
200200
}
201201
return nil
202202
}
203203

204-
func (tr *SSHTransfer) Shutdown() error {
204+
func (st *SSHTransfer) Shutdown() error {
205205
tracerx.Printf("shutting down pure SSH connections")
206-
return tr.SetConnectionCount(0)
206+
return st.SetConnectionCount(0)
207207
}

0 commit comments

Comments
 (0)