Class: Rugged::Blob
- Inherits:
-
RuggedObject
- Object
- RuggedObject
- Rugged::Blob
- Defined in:
- ext/rugged/rugged_blob.c
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.create(*args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'ext/rugged/rugged_blob.c', line 64
static VALUE rb_git_blob_create(int argc, VALUE *argv, VALUE self)
{
int error;
git_oid oid;
git_repository *repo;
VALUE rb_buffer, rb_repo, rb_is_buffer = Qfalse;
rb_scan_args(argc, argv, "21", &rb_repo, &rb_buffer, &rb_is_buffer);
Check_Type(rb_buffer, T_STRING);
if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
Data_Get_Struct(rb_repo, git_repository, repo);
if (rugged_parse_bool(rb_is_buffer)) {
error = git_blob_create_frombuffer(&oid, repo, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
} else {
error = git_blob_create_fromfile(&oid, repo, StringValueCStr(rb_buffer));
}
rugged_exception_check(error);
return rugged_create_oid(&oid);
}
|
Instance Method Details
#content ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'ext/rugged/rugged_blob.c', line 33
static VALUE rb_git_blob_content_GET(VALUE self)
{
git_blob *blob;
size_t size;
Data_Get_Struct(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);
}
|
#size ⇒ Object
56 57 58 59 60 61 62 |
# File 'ext/rugged/rugged_blob.c', line 56
static VALUE rb_git_blob_rawsize(VALUE self)
{
git_blob *blob;
Data_Get_Struct(self, git_blob, blob);
return INT2FIX(git_blob_rawsize(blob));
}
|