Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: remote, add support for a configurable timeout. #753

Merged
merged 1 commit into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
andrewpollock marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -1258,7 +1258,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
andrewpollock marked this conversation as resolved.
Show resolved Hide resolved
// 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