ext/rugged/rugged_signature.c in rugged-0.19.0 vs ext/rugged/rugged_signature.c in rugged-0.21.0
- old
+ new
@@ -1,9 +1,9 @@
/*
* The MIT License
*
- * Copyright (c) 2013 GitHub, Inc
+ * Copyright (c) 2014 GitHub, Inc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -50,43 +50,57 @@
rb_hash_aset(rb_sig, CSTR2SYM("time"), rb_time);
return rb_sig;
}
-git_signature *rugged_signature_get(VALUE rb_sig)
+git_signature *rugged_signature_get(VALUE rb_sig, git_repository *repo)
{
int error;
VALUE rb_time, rb_unix_t, rb_offset, rb_name, rb_email, rb_time_offset;
git_signature *sig;
+ if (NIL_P(rb_sig)) {
+ rugged_exception_check(
+ git_signature_default(&sig, repo)
+ );
+ return sig;
+ }
+
Check_Type(rb_sig, T_HASH);
rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name"));
rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email"));
rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time"));
rb_time_offset = rb_hash_aref(rb_sig, CSTR2SYM("time_offset"));
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 (NIL_P(rb_time_offset)) {
- rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0);
+ if (NIL_P(rb_time)) {
+ error = git_signature_now(&sig,
+ StringValueCStr(rb_name),
+ StringValueCStr(rb_email));
} else {
- Check_Type(rb_time_offset, T_FIXNUM);
- rb_offset = rb_time_offset;
- }
+ if (!rb_obj_is_kind_of(rb_time, rb_cTime))
+ rb_raise(rb_eTypeError, "expected Time object");
- error = git_signature_new(&sig,
- StringValueCStr(rb_name),
- StringValueCStr(rb_email),
- NUM2LONG(rb_unix_t),
- FIX2INT(rb_offset) / 60);
+ 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);
+ } else {
+ Check_Type(rb_time_offset, T_FIXNUM);
+ rb_offset = rb_time_offset;
+ }
+
+ error = git_signature_new(&sig,
+ StringValueCStr(rb_name),
+ StringValueCStr(rb_email),
+ NUM2LONG(rb_unix_t),
+ FIX2INT(rb_offset) / 60);
+ }
+
rugged_exception_check(error);
return sig;
}
-