@@ -109,6 +109,29 @@ 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
+ int errorcode ;
125
+
126
+ Check_Type (hex , T_STRING );
127
+ errorcode = git_oid_fromstr (& oid , StringValueCStr (hex ));
128
+ if (errorcode < 0 ) {
129
+ return Qfalse ;
130
+ } else {
131
+ return Qtrue ;
132
+ }
133
+ }
134
+
112
135
/*
113
136
* call-seq:
114
137
* Rugged.hex_to_raw(oid) -> raw_buffer
@@ -421,6 +444,7 @@ void Init_rugged(void)
421
444
422
445
rb_define_module_function (rb_mRugged , "libgit2_version" , rb_git_libgit2_version , 0 );
423
446
rb_define_module_function (rb_mRugged , "features" , rb_git_features , 0 );
447
+ rb_define_module_function (rb_mRugged , "valid_full_oid?" , rb_git_valid_full_oid , 1 );
424
448
rb_define_module_function (rb_mRugged , "hex_to_raw" , rb_git_hex_to_raw , 1 );
425
449
rb_define_module_function (rb_mRugged , "raw_to_hex" , rb_git_raw_to_hex , 1 );
426
450
rb_define_module_function (rb_mRugged , "minimize_oid" , rb_git_minimize_oid , -1 );
0 commit comments