Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Toggle raw types for signatures

  • Loading branch information...
commit 2c1654b88d3d6934e067b85a24b7597cf962b32f 1 parent fe34936
@vmg vmg authored
View
24 ext/rugged/rugged.c
@@ -50,6 +50,27 @@ VALUE rb_eRuggedErrors[RUGGED_ERROR_COUNT];
static VALUE rb_mShutdownHook;
+/* Enable or disable the generation of raw types instead of
+ * complex types. This is useful when running Ruby in a high
+ * performance setting.
+ *
+ * The following types are affected:
+ *
+ * - `time` on signatures will be returned as an integer
+ * instead of a Time object.
+ */
+int rugged_raw_types = 0;
+
+static VALUE rb_rugged_raw_types_get(VALUE self)
+{
+ return rugged_raw_types ? Qtrue : Qfalse;
+}
+
+static VALUE rb_rugged_raw_types_set(VALUE self, VALUE val)
+{
+ rugged_raw_types = rugged_parse_bool(val);
+}
+
/*
* call-seq:
* Rugged.libgit2_version -> version
@@ -340,6 +361,9 @@ void Init_rugged()
rb_define_const(rb_mRugged, "SORT_TOPO", INT2FIX(1));
rb_define_const(rb_mRugged, "SORT_DATE", INT2FIX(2));
rb_define_const(rb_mRugged, "SORT_REVERSE", INT2FIX(4));
+
+ rb_define_singleton_method(rb_mRugged, "raw_types", rb_rugged_raw_types_get, 0);
+ rb_define_singleton_method(rb_mRugged, "raw_types=", rb_rugged_raw_types_set, 1);
/* Initialize libgit2 */
git_threads_init();
View
2  ext/rugged/rugged.h
@@ -60,6 +60,8 @@ void Init_rugged_remote();
void Init_rugged_notes();
void Init_rugged_settings();
+extern int rugged_raw_types;
+
VALUE rb_git_object_init(git_otype type, int argc, VALUE *argv, VALUE self);
VALUE rugged_raw_read(git_repository *repo, const git_oid *oid);
View
33 ext/rugged/rugged_signature.c
@@ -37,21 +37,16 @@ VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name)
rb_sig = rb_hash_new();
-#if RUBY_API_VERSION_MINOR >= 9
- /* Allocate the time with a the given timezone */
- rb_time = rb_funcall(
- rb_time_new(sig->when.time, 0),
- rb_intern("getlocal"), 1,
- INT2FIX(sig->when.offset * 60)
- );
-#else
- rb_time = rb_time_new(sig->when.time, 0);
- rb_hash_aset(rb_sig, CSTR2SYM("time_offset"), INT2FIX(sig->when.offset * 60));
-#endif
+ if (rugged_raw_types) {
+ rb_time = LONG2NUM(sig->when.time);
+ } else {
+ rb_time = rb_time_new(sig->when.time, 0);
+ }
rb_hash_aset(rb_sig, CSTR2SYM("name"), rugged_str_new2(sig->name, encoding));
rb_hash_aset(rb_sig, CSTR2SYM("email"), rugged_str_new2(sig->email, encoding));
rb_hash_aset(rb_sig, CSTR2SYM("time"), rb_time);
+ rb_hash_aset(rb_sig, CSTR2SYM("time_offset"), INT2FIX(sig->when.offset * 60));
return rb_sig;
}
@@ -71,15 +66,21 @@ git_signature *rugged_signature_get(VALUE rb_sig)
Check_Type(rb_name, T_STRING);
Check_Type(rb_email, T_STRING);
- if (!rb_obj_is_kind_of(rb_time, rb_cTime))
- rb_raise(rb_eTypeError, "expected Time object");
- rb_unix_t = rb_funcall(rb_time, rb_intern("tv_sec"), 0);
+ if (rb_obj_is_kind_of(rb_time, rb_cTime)) {
+ rb_unix_t = rb_funcall(rb_time, rb_intern("tv_sec"), 0);
- if (NIL_P(rb_time_offset)) {
- rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0);
+ if (NIL_P(rb_time_offset)) {
+ rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0);
+ } else {
+ Check_Type(rb_time_offset, T_FIXNUM);
+ rb_offset = rb_time_offset;
+ }
} else {
+ Check_Type(rb_time, T_FIXNUM);
Check_Type(rb_time_offset, T_FIXNUM);
+
+ rb_unix_t = rb_time;
rb_offset = rb_time_offset;
}
Please sign in to comment.
Something went wrong with that request. Please try again.