aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Pollock <apollock@google.com>2023-05-02 21:05:24 +1000
committerAndrew Pollock <apollock@google.com>2023-05-12 10:32:08 +1000
commitf47bb2d633347913d5575a42e25872c38569a4a3 (patch)
tree49d2a6929657cbacac898619a4c3b31e46a26119
parentdc2b346ed149080199d578f0190f3ac1156480c2 (diff)
downloadgo-git-f47bb2d633347913d5575a42e25872c38569a4a3.tar.gz
git: remote, add support for a configurable timeout.
The previous hard-coded 10 second value is too short for listing large repositories like https://gitlab.com/gitlab-org/gitlab Return an error on nonsensical subzero timeout values
-rw-r--r--options.go2
-rw-r--r--remote.go10
2 files changed, 11 insertions, 1 deletions
diff --git a/options.go b/options.go
index 3d75e03..d607b30 100644
--- a/options.go
+++ b/options.go
@@ -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.
diff --git a/remote.go b/remote.go
index df26491..7d44c5b 100644
--- a/remote.go
+++ b/remote.go
@@ -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
+ // 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)
}