[PATCH v2 19/44] ruby: bind get_sha1()

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

 



Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 ruby.c           | 11 +++++++++++
 t/t10000-ruby.sh |  8 ++++++++
 2 files changed, 19 insertions(+)

diff --git a/ruby.c b/ruby.c
index 92c636c..45111e6 100644
--- a/ruby.c
+++ b/ruby.c
@@ -81,6 +81,16 @@ static VALUE git_rb_peel_ref(VALUE self, VALUE refname)
 	return sha1_to_str(sha1);
 }
 
+static VALUE git_rb_get_sha1(VALUE self, VALUE name)
+{
+	unsigned char buf[20];
+	int r;
+	r = get_sha1(RSTRING_PTR(name), buf);
+	if (r)
+		return Qnil;
+	return sha1_to_str(buf);
+}
+
 static void git_ruby_init(void)
 {
 	rb_define_global_function("setup_git_directory", git_rb_setup_git_directory, 0);
@@ -89,6 +99,7 @@ static void git_ruby_init(void)
 	rb_define_global_function("git_config", git_rb_git_config, 0);
 	rb_define_global_function("read_ref", git_rb_read_ref, 1);
 	rb_define_global_function("peel_ref", git_rb_peel_ref, 1);
+	rb_define_global_function("get_sha1", git_rb_get_sha1, 1);
 }
 
 static int run_ruby_command(const char *cmd, int argc, const char **argv)
diff --git a/t/t10000-ruby.sh b/t/t10000-ruby.sh
index cdbf5d8..849a615 100755
--- a/t/t10000-ruby.sh
+++ b/t/t10000-ruby.sh
@@ -73,4 +73,12 @@ test_expect_success 'test git_config()' '
 	test_cmp expected actual
 '
 
+test_expect_success 'test get_sha1()' '
+	git ruby > actual <<-EOF &&
+	puts sha1_to_hex(get_sha1("HEAD"))
+	EOF
+	git rev-parse -q --verify HEAD > expected &&
+	test_cmp expected actual
+'
+
 test_done
-- 
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]