Skip to content

Commit

Permalink
Merge pull request #753 from andrewpollock/add_list_timeout
Browse files Browse the repository at this point in the history
git: remote, add support for a configurable timeout.
  • Loading branch information
pjbgf committed May 20, 2023
2 parents 4ff2213 + f47bb2d commit ce08ae0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ type ListOptions struct {
PeelingOption PeelingOption
// ProxyOptions provides info required for connecting to a proxy.
ProxyOptions transport.ProxyOptions
// Timeout specifies the timeout in seconds for list operations
Timeout int
}

// PeelingOption represents the different ways to handle peeled references.
Expand Down
10 changes: 9 additions & 1 deletion remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,15 @@ func (r *Remote) ListContext(ctx context.Context, o *ListOptions) (rfs []*plumbi
}

func (r *Remote) List(o *ListOptions) (rfs []*plumbing.Reference, err error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
timeout := o.Timeout
// Default to the old hardcoded 10s value if a timeout is not explicitly set.
if timeout == 0 {
timeout = 10
}
if timeout < 0 {
return nil, fmt.Errorf("invalid timeout: %d", timeout)
}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Second)
defer cancel()
return r.ListContext(ctx, o)
}
Expand Down

0 comments on commit ce08ae0

Please sign in to comment.