@@ -109,6 +109,28 @@ static VALUE rb_git_features(VALUE self)
109
109
return ret_arr ;
110
110
}
111
111
112
+ /*
113
+ * call-seq:
114
+ * Rugged.valid_full_oid?(oid) -> true or false
115
+ *
116
+ * Checks to see if a string contains a full 40-character sha1.
117
+ *
118
+ * Rugged.valid_full_oid?('d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f')
119
+ * #=> true
120
+ */
121
+ static VALUE rb_git_valid_full_oid (VALUE self , VALUE hex )
122
+ {
123
+ git_oid oid ;
124
+
125
+ Check_Type (hex , T_STRING );
126
+ int errorcode = git_oid_fromstr (& oid , StringValueCStr (hex ));
127
+ if (errorcode < 0 ) {
128
+ return Qfalse ;
129
+ } else {
130
+ return Qtrue ;
131
+ }
132
+ }
133
+
112
134
/*
113
135
* call-seq:
114
136
* Rugged.hex_to_raw(oid) -> raw_buffer
@@ -421,6 +443,7 @@ void Init_rugged(void)
421
443
422
444
rb_define_module_function (rb_mRugged , "libgit2_version" , rb_git_libgit2_version , 0 );
423
445
rb_define_module_function (rb_mRugged , "features" , rb_git_features , 0 );
446
+ rb_define_module_function (rb_mRugged , "valid_full_oid?" , rb_git_valid_full_oid , 1 );
424
447
rb_define_module_function (rb_mRugged , "hex_to_raw" , rb_git_hex_to_raw , 1 );
425
448
rb_define_module_function (rb_mRugged , "raw_to_hex" , rb_git_raw_to_hex , 1 );
426
449
rb_define_module_function (rb_mRugged , "minimize_oid" , rb_git_minimize_oid , -1 );
0 commit comments