Skip to content

Commit

Permalink
Replace short field names with more descriptive ones.
Browse files Browse the repository at this point in the history
The decision to change the name of these fields came from reading the code
further down in the scope and not being clear what `c.c` means.
  • Loading branch information
matejrisek committed Nov 19, 2023
1 parent c114af0 commit 216899b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
20 changes: 10 additions & 10 deletions plumbing/transport/http/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ func advertisedReferences(ctx context.Context, s *session, serviceName string) (
}

type client struct {
c *http.Client
client *http.Client
transports *lru.Cache
m sync.RWMutex
mutex sync.RWMutex
}

// ClientOptions holds user configurable options for the client.
Expand Down Expand Up @@ -147,7 +147,7 @@ func NewClientWithOptions(c *http.Client, opts *ClientOptions) transport.Transpo
}
}
cl := &client{
c: c,
client: c,
}

if opts != nil {
Expand Down Expand Up @@ -234,10 +234,10 @@ func newSession(c *client, ep *transport.Endpoint, auth transport.AuthMethod) (*
// if the client wasn't configured to have a cache for transports then just configure
// the transport and use it directly, otherwise try to use the cache.
if c.transports == nil {
tr, ok := c.c.Transport.(*http.Transport)
tr, ok := c.client.Transport.(*http.Transport)
if !ok {
return nil, fmt.Errorf("expected underlying client transport to be of type: %s; got: %s",
reflect.TypeOf(transport), reflect.TypeOf(c.c.Transport))
reflect.TypeOf(transport), reflect.TypeOf(c.client.Transport))
}

transport = tr.Clone()
Expand All @@ -258,20 +258,20 @@ func newSession(c *client, ep *transport.Endpoint, auth transport.AuthMethod) (*
transport, found = c.fetchTransport(transportOpts)

if !found {
transport = c.c.Transport.(*http.Transport).Clone()
transport = c.client.Transport.(*http.Transport).Clone()
configureTransport(transport, ep)
c.addTransport(transportOpts, transport)
}
}

httpClient = &http.Client{
Transport: transport,
CheckRedirect: c.c.CheckRedirect,
Jar: c.c.Jar,
Timeout: c.c.Timeout,
CheckRedirect: c.client.CheckRedirect,
Jar: c.client.Jar,
Timeout: c.client.Timeout,
}
} else {
httpClient = c.c
httpClient = c.client
}

s := &session{
Expand Down
2 changes: 1 addition & 1 deletion plumbing/transport/http/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *UploadPackSuite) TestNewClient(c *C) {
cl := &http.Client{Transport: roundTripper}
r, ok := NewClient(cl).(*client)
c.Assert(ok, Equals, true)
c.Assert(r.c, Equals, cl)
c.Assert(r.client, Equals, cl)
}

func (s *ClientSuite) TestNewBasicAuth(c *C) {
Expand Down
12 changes: 6 additions & 6 deletions plumbing/transport/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ type transportOptions struct {
}

func (c *client) addTransport(opts transportOptions, transport *http.Transport) {
c.m.Lock()
c.mutex.Lock()
c.transports.Add(opts, transport)
c.m.Unlock()
c.mutex.Unlock()
}

func (c *client) removeTransport(opts transportOptions) {
c.m.Lock()
c.mutex.Lock()
c.transports.Remove(opts)
c.m.Unlock()
c.mutex.Unlock()
}

func (c *client) fetchTransport(opts transportOptions) (*http.Transport, bool) {
c.m.RLock()
c.mutex.RLock()
t, ok := c.transports.Get(opts)
c.m.RUnlock()
c.mutex.RUnlock()
if !ok {
return nil, false
}
Expand Down

0 comments on commit 216899b

Please sign in to comment.