[PATCH v2 13/44] ruby: bind setup_git_directory()

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

 



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

diff --git a/ruby.c b/ruby.c
index 339e376..c2ef72e 100644
--- a/ruby.c
+++ b/ruby.c
@@ -12,6 +12,21 @@ static inline VALUE sha1_to_str(const unsigned char *sha1)
 	return rb_str_new((const char *)sha1, 20);
 }
 
+static inline VALUE cstr_to_str(const char *str)
+{
+	if (str == NULL)
+		return Qnil;
+	return rb_str_new2(str);
+}
+
+static VALUE git_rb_setup_git_directory(VALUE self)
+{
+	int nongit_ok;
+	const char *prefix;
+	prefix = setup_git_directory_gently(&nongit_ok);
+	return rb_ary_new3(2, cstr_to_str(prefix), INT2FIX(nongit_ok));
+}
+
 static int for_each_ref_fn(const char *refname, const unsigned char *sha1, int flags, void *cb_data)
 {
 	VALUE r;
@@ -28,6 +43,7 @@ static VALUE git_rb_for_each_ref(void)
 
 static void git_ruby_init(void)
 {
+	rb_define_global_function("setup_git_directory", git_rb_setup_git_directory, 0);
 	rb_define_global_function("for_each_ref", git_rb_for_each_ref, 0);
 }
 
diff --git a/t/t10000-ruby.sh b/t/t10000-ruby.sh
index eb03706..2098e29 100755
--- a/t/t10000-ruby.sh
+++ b/t/t10000-ruby.sh
@@ -39,4 +39,17 @@ test_expect_success 'test for_each_ref()' '
 	test_cmp expected actual
 '
 
+test_expect_success 'test setup_git_directory()' '
+	mkdir t &&
+	(
+	cd t &&
+	git ruby > ../actual <<-EOF
+	prefix, nongit_ok = setup_git_directory()
+	puts prefix
+	EOF
+	) &&
+	echo "t/" > 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]