From 79039acb3f869e04947fcb9451e6489f60431624 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Mon, 5 Oct 2026 15:22:12 -0400 Subject: [PATCH] Expose server_connect_timeout and server_timeout settings Wire GIT_OPT_SET/GET_SERVER_CONNECT_TIMEOUT and GIT_OPT_SET/GET_SERVER_TIMEOUT through Rugged::Settings, following the existing pattern for mwindow_size. Rugged::Settings["server_connect_timeout"] = 30_000 Rugged::Settings["server_timeout"] = 30_000 Both options were added to libgit2 in 1.7.0. --- ext/rugged/rugged_settings.c | 26 ++++++++++++++++++++++++++ test/lib_test.rb | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/ext/rugged/rugged_settings.c b/ext/rugged/rugged_settings.c index abab82ded..d53953b5e 100644 --- a/ext/rugged/rugged_settings.c +++ b/ext/rugged/rugged_settings.c @@ -96,6 +96,20 @@ static VALUE rb_git_set_option(VALUE self, VALUE option, VALUE value) git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, validation); } + else if (strcmp(opt, "server_connect_timeout") == 0) { + int val; + Check_Type(value, T_FIXNUM); + val = NUM2INT(value); + git_libgit2_opts(GIT_OPT_SET_SERVER_CONNECT_TIMEOUT, val); + } + + else if (strcmp(opt, "server_timeout") == 0) { + int val; + Check_Type(value, T_FIXNUM); + val = NUM2INT(value); + git_libgit2_opts(GIT_OPT_SET_SERVER_TIMEOUT, val); + } + else { rb_raise(rb_eArgError, "Unknown option specified"); } @@ -146,6 +160,18 @@ static VALUE rb_git_get_option(VALUE self, VALUE option) return validation ? Qtrue : Qfalse; } + else if (strcmp(opt, "server_connect_timeout") == 0) { + int val; + git_libgit2_opts(GIT_OPT_GET_SERVER_CONNECT_TIMEOUT, &val); + return INT2NUM(val); + } + + else if (strcmp(opt, "server_timeout") == 0) { + int val; + git_libgit2_opts(GIT_OPT_GET_SERVER_TIMEOUT, &val); + return INT2NUM(val); + } + else { rb_raise(rb_eArgError, "Unknown option specified"); } diff --git a/test/lib_test.rb b/test/lib_test.rb index 34f128cc4..5c62ad1ef 100644 --- a/test/lib_test.rb +++ b/test/lib_test.rb @@ -54,6 +54,28 @@ def test_owner_validation end end + def test_server_connect_timeout + before = Rugged::Settings['server_connect_timeout'] + + begin + Rugged::Settings['server_connect_timeout'] = 300_000 + assert_equal 300_000, Rugged::Settings['server_connect_timeout'] + ensure + Rugged::Settings['server_connect_timeout'] = before + end + end + + def test_server_timeout + before = Rugged::Settings['server_timeout'] + + begin + Rugged::Settings['server_timeout'] = 300_000 + assert_equal 300_000, Rugged::Settings['server_timeout'] + ensure + Rugged::Settings['server_timeout'] = before + end + end + def test_search_path paths = [['search_path_global', '/tmp/global'], ['search_path_xdg', '/tmp/xdg'],