[PATCH v2 30/44] ruby: bind read_sha1_file()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 ruby.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/ruby.c b/ruby.c
index 7496c18..360515f 100644
--- a/ruby.c
+++ b/ruby.c
@@ -265,6 +265,18 @@ static VALUE git_rb_find_unique_abbrev(VALUE self, VALUE sha1, VALUE len)
 	return rb_str_new2(abbrev);
 }
 
+static VALUE git_rb_read_sha1_file(VALUE self, VALUE sha1, VALUE type)
+{
+	enum object_type g_type;
+	void *buffer;
+	unsigned long size;
+
+	buffer = read_sha1_file(str_to_sha1(sha1), &g_type, &size);
+	if (!buffer)
+		return Qnil;
+	return rb_ary_new3(2, rb_str_new(buffer, size), INT2FIX(g_type));
+}
+
 static void git_ruby_init(void)
 {
 	VALUE mod;
@@ -295,6 +307,7 @@ static void git_ruby_init(void)
 	rb_define_global_function("remote_get", git_rb_remote_get, 1);
 	rb_define_global_function("transport_get", git_rb_transport_get, 2);
 	rb_define_global_function("find_unique_abbrev", git_rb_find_unique_abbrev, 2);
+	rb_define_global_function("read_sha1_file", git_rb_read_sha1_file, 1);
 
 	git_rb_object = rb_define_class_under(mod, "Object", rb_cData);
 	rb_define_singleton_method(git_rb_object, "get", git_rb_object_get, 1);
-- 
1.8.4-fc

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]