Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add getters to them options

  • Loading branch information...
commit db522cce9ccd73ef77de281fd52283cd4cdbb2ca 1 parent 3e84d3f
@vmg vmg authored
Showing with 46 additions and 11 deletions.
  1. +43 −10 ext/rugged/rugged_settings.c
  2. +2 −0  test/lib_test.rb
  3. +1 −1  vendor/libgit2
View
53 ext/rugged/rugged_settings.c
@@ -27,14 +27,14 @@
#if !defined(NUM2SIZET)
# if SIZEOF_SIZE_T == SIZEOF_LONG
# define NUM2SIZET(n) ((size_t)NUM2ULONG(n))
+# define SIZET2NUM(n) ((size_t)ULONG2NUM(n))
# else
# define NUM2SIZET(n) ((size_t)NUM2ULL(n))
+# define SIZET2NUM(n) ((size_t)ULL2NUM(n))
# endif
#endif /* ! defined(NUM2SIZET) */
-
extern VALUE rb_mRugged;
-VALUE rb_cRuggedSettings;
/*
* call-seq:
@@ -45,33 +45,66 @@ VALUE rb_cRuggedSettings;
*/
static VALUE rb_git_set_option(VALUE self, VALUE option, VALUE value)
{
- char *opt;
+ const char *opt;
Check_Type(option, T_STRING);
- opt = RSTRING_PTR(option);
+ opt = StringValueCStr(option);
if (strcmp(opt, "mwindow_size") == 0) {
size_t val;
Check_Type(value, T_FIXNUM);
val = NUM2SIZET(value);
-
- git_libgit2_opts(GIT_OPT_MWINDOW_SIZE, val);
- } else if (strcmp(opt, "mwindow_mapped_limit") == 0) {
+ git_libgit2_opts(GIT_OPT_SET_MWINDOW_SIZE, val);
+ }
+
+ else if (strcmp(opt, "mwindow_mapped_limit") == 0) {
size_t val;
Check_Type(value, T_FIXNUM);
val = NUM2SIZET(value);
+ git_libgit2_opts(GIT_OPT_SET_MWINDOW_MAPPED_LIMIT, val);
+ }
- git_libgit2_opts(GIT_OPT_MWINDOW_MAPPED_LIMIT, val);
- } else {
+ else {
rb_raise(rb_eArgError, "Unknown option specified");
}
return Qnil;
}
+/*
+ * call-seq:
+ * val = Rugged.Settings[option]
+ *
+ * Gets the value of a libgit2 library option
+ *
+ */
+static VALUE rb_git_get_option(VALUE self, VALUE option)
+{
+ const char *opt;
+
+ Check_Type(option, T_STRING);
+ opt = StringValueCStr(option);
+
+ if (strcmp(opt, "mwindow_size") == 0) {
+ size_t val;
+ git_libgit2_opts(GIT_OPT_GET_MWINDOW_SIZE, &val);
+ return SIZET2NUM(val);
+ }
+
+ else if (strcmp(opt, "mwindow_mapped_limit") == 0) {
+ size_t val;
+ git_libgit2_opts(GIT_OPT_GET_MWINDOW_MAPPED_LIMIT, &val);
+ return SIZET2NUM(val);
+ }
+
+ else {
+ rb_raise(rb_eArgError, "Unknown option specified");
+ }
+}
void Init_rugged_settings()
{
- rb_cRuggedSettings = rb_define_class_under(rb_mRugged, "Settings", rb_cObject);
+ VALUE rb_cRuggedSettings = rb_define_class_under(rb_mRugged, "Settings", rb_cObject);
rb_define_module_function(rb_cRuggedSettings, "[]=", rb_git_set_option, 2);
+ rb_define_module_function(rb_cRuggedSettings, "[]", rb_git_get_option, 1);
}
View
2  test/lib_test.rb
@@ -22,6 +22,8 @@ def test_options
Rugged::Settings['mwindow_size'] = 8 * 1024 * 1024
Rugged::Settings['mwindow_mapped_limit'] = 8 * 1024 * 1024
+ assert_equal 8 * 1024 * 1024, Rugged::Settings['mwindow_size']
+
assert_raises(TypeError) { Rugged::Settings['mwindow_mapped_limit'] = 'asdf' }
assert_raises(TypeError) { Rugged::Settings['mwindow_size'] = nil }
end
2  vendor/libgit2
@@ -1 +1 @@
-Subproject commit b101fbf9a403f38556ed9e6d3b293c73733465e2
+Subproject commit 0d52cb4aea2e0af1b8a4a8557e26c9edf85c96db
Please sign in to comment.
Something went wrong with that request. Please try again.