Module: GitSha

Defined in:
ext/gitsha.c

Class Method Summary collapse

Class Method Details

.bruteforce!(commit_data, sha_prefix, sha_prefix_half_hex_dig, ncpus) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'ext/gitsha.c', line 210

static VALUE
bruteforce(VALUE _, VALUE commit_data, VALUE sha_prefix, VALUE sha_prefix_half_hex_dig, VALUE ncpus)
{
    if(TYPE(commit_data) != T_STRING || TYPE(sha_prefix) != T_STRING) {
        rb_raise(rb_eTypeError, "expected commit_data, sha_prefix to be strings");
    }

    if(TYPE(ncpus) != T_FIXNUM) {
        rb_raise(rb_eTypeError, "expected ncpus to be a fixnum");
    }

    if(FIX2INT(ncpus) <= 0) {
        rb_raise(rb_eTypeError, "expected ncpus to be > 0");
    }

    if(RSTRING_LEN(sha_prefix) > 20) {
        rb_raise(rb_eArgError, "expected sha_prefix to be at most 20 bytes long");
    }

    return start_bruteforce(
        RSTRING_PTR(commit_data),
        RSTRING_LEN(commit_data),
        RSTRING_PTR(sha_prefix),
        RSTRING_LEN(sha_prefix),
        RTEST(sha_prefix_half_hex_dig),
        FIX2INT(ncpus));
}