[prev in list] [next in list] [prev in thread] [next in thread]
List: subversion-cvs
Subject: svn commit: rev 564 - trunk/subversion/bindings/ruby
From: yoshiki () tigris ! org
Date: 2001-11-29 6:49:12
[Download RAW message or body]
Author: yoshiki
Date: 2001-11-29 06:49 GMT
New Revision: 564
Modified:
trunk/subversion/bindings/ruby/client.c
trunk/subversion/bindings/ruby/util.c
trunk/subversion/bindings/ruby/util.h
Log:
Implement Svn::Client.propset, Svn::Client.propget and Svn::Client.proplist.
* util.c (svn_ruby_strbuf_hash): Helper function to convert
char * -> svn_stringbuf_t * apr_hash_t to Ruby hash table.
* util.h (svn_ruby_strbuf_hash): Declare it.
* client.c
(cl_propset): New function.
(cl_propget): New function.
(cl_proplist): New function.
(svn_ruby_init_client): Register propset, propget and proplist methods.
Modified: trunk/subversion/bindings/ruby/util.c
==============================================================================
--- OLD/trunk/subversion/bindings/ruby/util.c Thu Nov 29 00:49:12 2001
+++ NEW/trunk/subversion/bindings/ruby/util.c Thu Nov 29 00:49:12 2001
@@ -99,6 +99,30 @@
return obj;
}
+VALUE
+svn_ruby_strbuf_hash (apr_hash_t *hash, apr_pool_t *pool)
+{
+ VALUE obj;
+ apr_hash_index_t *hi;
+
+ obj = rb_hash_new ();
+
+ for (hi = apr_hash_first (pool, hash); hi; hi = apr_hash_next (hi))
+ {
+ const void *key;
+ void *val;
+ apr_ssize_t key_len;
+ svn_stringbuf_t *value;
+
+ apr_hash_this (hi, &key, &key_len, &val);
+ value = (svn_stringbuf_t *) val;
+ rb_hash_aset (obj, rb_str_new (key, key_len),
+ rb_str_new (value->data, value->len));
+ }
+
+ return obj;
+}
+
void
svn_ruby_init_apr (void)
{
Modified: trunk/subversion/bindings/ruby/client.c
==============================================================================
--- OLD/trunk/subversion/bindings/ruby/client.c Thu Nov 29 00:49:12 2001
+++ NEW/trunk/subversion/bindings/ruby/client.c Thu Nov 29 00:49:12 2001
@@ -596,6 +596,105 @@
return Qnil;
}
+static VALUE
+cl_propset (VALUE class, VALUE name, VALUE val, VALUE aTarget, VALUE recurse)
+{
+ svn_stringbuf_t *propname, *propval, *target;
+ apr_pool_t *pool;
+ svn_error_t *err;
+
+ Check_Type (name, T_STRING);
+ Check_Type (val, T_STRING);
+ Check_Type (aTarget, T_STRING);
+
+ pool = svn_pool_create (NULL);
+ propname = svn_stringbuf_ncreate (StringValuePtr (name),
+ RSTRING (name)->len, pool);
+ propval = svn_stringbuf_ncreate (StringValuePtr (val),
+ RSTRING (val)->len, pool);
+ target = svn_stringbuf_ncreate (StringValuePtr (aTarget),
+ RSTRING (aTarget)->len, pool);
+ err = svn_client_propset (propname, propval, target, RTEST (recurse), pool);
+
+ if (err)
+ {
+ apr_pool_destroy (pool);
+ svn_ruby_raise (err);
+ }
+
+ return Qnil;
+}
+
+static VALUE
+cl_propget (VALUE class, VALUE name, VALUE aTarget, VALUE recurse)
+{
+ apr_hash_t *props;
+ svn_stringbuf_t *propname, *target;
+ apr_pool_t *pool;
+ svn_error_t *err;
+ VALUE obj;
+
+ Check_Type (name, T_STRING);
+ Check_Type (aTarget, T_STRING);
+
+ pool = svn_pool_create (NULL);
+ propname = svn_stringbuf_ncreate (StringValuePtr (name),
+ RSTRING (name)->len, pool);
+ target = svn_stringbuf_ncreate (StringValuePtr (aTarget),
+ RSTRING (aTarget)->len, pool);
+ err = svn_client_propget (&props, propname, target, RTEST (recurse), pool);
+
+ if (err)
+ {
+ apr_pool_destroy (pool);
+ svn_ruby_raise (err);
+ }
+
+ obj = svn_ruby_strbuf_hash (props, pool);
+ apr_pool_destroy (pool);
+ return obj;
+}
+
+static VALUE
+cl_proplist (VALUE class, VALUE aTarget, VALUE recurse)
+{
+ apr_array_header_t *props;
+ svn_stringbuf_t *target;
+ apr_pool_t *pool;
+ svn_error_t *err;
+
+ Check_Type (aTarget, T_STRING);
+
+ pool = svn_pool_create (NULL);
+ target = svn_stringbuf_ncreate (StringValuePtr (aTarget),
+ RSTRING (aTarget)->len, pool);
+ err = svn_client_proplist (&props,target, RTEST (recurse), pool);
+
+ if (err)
+ {
+ apr_pool_destroy (pool);
+ svn_ruby_raise (err);
+ }
+
+ {
+ VALUE obj;
+ int i;
+
+ obj = rb_hash_new ();
+ for (i = 0; i < props->nelts; i++)
+ {
+ svn_client_proplist_item_t *item;
+ item = ((svn_client_proplist_item_t **) props->elts)[i];
+ rb_hash_aset (obj,
+ rb_str_new (item->node_name->data,
+ item->node_name->len),
+ svn_ruby_strbuf_hash (item->prop_hash, pool));
+ }
+ apr_pool_destroy (pool);
+ return obj;
+ }
+}
+
void svn_ruby_init_client (void)
{
VALUE cSvnClient;
@@ -613,4 +712,7 @@
rb_define_singleton_method (cSvnClient, "cleanup", cl_cleanup, 1);
rb_define_singleton_method (cSvnClient, "revert", cl_revert, 2);
rb_define_method (cSvnClient, "copy", cl_copy, -1);
+ rb_define_singleton_method (cSvnClient, "propset", cl_propset, 4);
+ rb_define_singleton_method (cSvnClient, "propget", cl_propget, 3);
+ rb_define_singleton_method (cSvnClient, "proplist", cl_proplist, 2);
}
Modified: trunk/subversion/bindings/ruby/util.h
==============================================================================
--- OLD/trunk/subversion/bindings/ruby/util.h Thu Nov 29 00:49:12 2001
+++ NEW/trunk/subversion/bindings/ruby/util.h Thu Nov 29 00:49:12 2001
@@ -23,6 +23,7 @@
long svn_ruby_get_refcount (apr_pool_t *pool);
VALUE svn_ruby_str_hash (apr_hash_t *hash, apr_pool_t *pool);
+VALUE svn_ruby_strbuf_hash (apr_hash_t *hash, apr_pool_t *pool);
#endif /* UTIL_H */
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic