static VALUE rb_git_hex_to_raw(VALUE self, VALUE hex) { git_oid oid; Check_Type(hex, T_STRING); rugged_exception_check(git_oid_mkstr(&oid, RSTRING_PTR(hex))); return rugged_str_ascii(oid.id, 20); }
static VALUE rb_git_blob_content_GET(VALUE self) { git_blob *blob; int size; RUGGED_OBJ_UNWRAP(self, git_blob, blob); size = git_blob_rawsize(blob); if (size == 0) return rugged_str_ascii("", 0); /* * since we don't really ever know the encoding of a blob * lets default to the binary encoding (ascii-8bit) * If there is a way to tell, we should just pass 0/null here instead * * we're skipping the use of STR_NEW because we don't want our string to * eventually end up converted to Encoding.default_internal because this * string could very well be binary data */ return rugged_str_ascii(git_blob_rawcontent(blob), size); }
/* * call-seq: * blob.content(max_bytes=-1) -> String * * Return up to +max_bytes+ from the contents of a blob as bytes +String+. * If max_bytes is less than 0, the full string is returned. * * In Ruby 1.9.x, this string is tagged with the ASCII-8BIT encoding: the * bytes are returned as-is, since Git is encoding agnostic. */ static VALUE rb_git_blob_content_GET(int argc, VALUE *argv, VALUE self) { git_blob *blob; size_t size; const char *content; VALUE rb_max_bytes; Data_Get_Struct(self, git_blob, blob); rb_scan_args(argc, argv, "01", &rb_max_bytes); content = git_blob_rawcontent(blob); size = git_blob_rawsize(blob); if (!NIL_P(rb_max_bytes)) { int maxbytes; Check_Type(rb_max_bytes, T_FIXNUM); maxbytes = FIX2INT(rb_max_bytes); if (maxbytes >= 0 && (size_t)maxbytes < size) size = (size_t)maxbytes; } if (size == 0) return rugged_str_ascii("", 0); /* * since we don't really ever know the encoding of a blob * lets default to the binary encoding (ascii-8bit) * If there is a way to tell, we should just pass 0/null here instead * * we're skipping the use of STR_NEW because we don't want our string to * eventually end up converted to Encoding.default_internal because this * string could very well be binary data */ return rugged_str_ascii(content, size); }