unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/3] ruby: api updates
@ 2023-03-31 20:53 Felipe Contreras
  2023-03-31 20:53 ` [PATCH 1/3] ruby: add database.revision Felipe Contreras
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Felipe Contreras @ 2023-03-31 20:53 UTC (permalink / raw)
  To: notmuch

These are some API updates I did years ago but didn't send for fear of
distracting from more important patches.

However, I was already butten by db.revision not being available.

So here they are.

If you want I can incrementally check all the API updates and implement them
all in the ruby bindings.

Felipe Contreras (3):
  ruby: add database.revision
  ruby: add directory.delete
  ruby: add db.{set,get}_config

 bindings/ruby/database.c  | 63 +++++++++++++++++++++++++++++++++++++++
 bindings/ruby/defs.h      | 12 ++++++++
 bindings/ruby/directory.c | 19 ++++++++++++
 bindings/ruby/init.c      |  4 +++
 4 files changed, 98 insertions(+)

-- 
2.40.0

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] ruby: add database.revision
  2023-03-31 20:53 [PATCH 0/3] ruby: api updates Felipe Contreras
@ 2023-03-31 20:53 ` Felipe Contreras
  2023-05-29 11:15   ` David Bremner
  2023-03-31 20:53 ` [PATCH 2/3] ruby: add directory.delete Felipe Contreras
  2023-03-31 20:53 ` [PATCH 3/3] ruby: add db.{set,get}_config Felipe Contreras
  2 siblings, 1 reply; 7+ messages in thread
From: Felipe Contreras @ 2023-03-31 20:53 UTC (permalink / raw)
  To: notmuch

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 bindings/ruby/database.c | 18 ++++++++++++++++++
 bindings/ruby/defs.h     |  3 +++
 bindings/ruby/init.c     |  1 +
 3 files changed, 22 insertions(+)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index b6de1254..4372afa1 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -479,3 +479,21 @@ notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self)
 
     return Data_Wrap_Notmuch_Object (notmuch_rb_cQuery, &notmuch_rb_query_type, query);
 }
+
+/*
+ * call-seq: DB.revision => Array
+ *
+ * Returns the commutted database revision and UUID.
+ */
+VALUE
+notmuch_rb_database_revision (VALUE self)
+{
+    notmuch_database_t *db;
+    unsigned long rev;
+    const char *uuid;
+
+    Data_Get_Notmuch_Database (self, db);
+
+    rev = notmuch_database_get_revision (db, &uuid);
+    return rb_ary_new3(2, INT2FIX (rev), rb_str_new2 (uuid));
+}
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index e2541e8f..c4943681 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -208,6 +208,9 @@ notmuch_rb_database_get_all_tags (VALUE self);
 VALUE
 notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self);
 
+VALUE
+notmuch_rb_database_revision (VALUE self);
+
 /* directory.c */
 VALUE
 notmuch_rb_directory_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index cd9f04cd..c78242a0 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -283,6 +283,7 @@ Init_notmuch (void)
 		      notmuch_rb_database_find_message_by_filename, 1); /* in database.c */
     rb_define_method (notmuch_rb_cDatabase, "all_tags", notmuch_rb_database_get_all_tags, 0); /* in database.c */
     rb_define_method (notmuch_rb_cDatabase, "query", notmuch_rb_database_query_create, -1); /* in database.c */
+    rb_define_method (notmuch_rb_cDatabase, "revision", notmuch_rb_database_revision, 0); /* in database.c */
 
     /*
      * Document-class: Notmuch::Directory
-- 
2.40.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] ruby: add directory.delete
  2023-03-31 20:53 [PATCH 0/3] ruby: api updates Felipe Contreras
  2023-03-31 20:53 ` [PATCH 1/3] ruby: add database.revision Felipe Contreras
@ 2023-03-31 20:53 ` Felipe Contreras
  2023-05-29 11:24   ` David Bremner
  2023-03-31 20:53 ` [PATCH 3/3] ruby: add db.{set,get}_config Felipe Contreras
  2 siblings, 1 reply; 7+ messages in thread
From: Felipe Contreras @ 2023-03-31 20:53 UTC (permalink / raw)
  To: notmuch

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 bindings/ruby/defs.h      |  3 +++
 bindings/ruby/directory.c | 19 +++++++++++++++++++
 bindings/ruby/init.c      |  1 +
 3 files changed, 23 insertions(+)

diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index c4943681..3ef228b7 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -227,6 +227,9 @@ notmuch_rb_directory_get_child_files (VALUE self);
 VALUE
 notmuch_rb_directory_get_child_directories (VALUE self);
 
+VALUE
+notmuch_rb_directory_delete (VALUE self);
+
 /* filenames.c */
 VALUE
 notmuch_rb_filenames_destroy (VALUE self);
diff --git a/bindings/ruby/directory.c b/bindings/ruby/directory.c
index 910f0a99..2fb22c70 100644
--- a/bindings/ruby/directory.c
+++ b/bindings/ruby/directory.c
@@ -108,3 +108,22 @@ notmuch_rb_directory_get_child_directories (VALUE self)
 
     return Data_Wrap_Notmuch_Object (notmuch_rb_cFileNames, &notmuch_rb_filenames_type, fnames);
 }
+
+/*
+ * call-seq: DIR.delete => nil
+ *
+ * Delete directory from the database.
+ */
+VALUE
+notmuch_rb_directory_delete (VALUE self)
+{
+    notmuch_directory_t *dir;
+    notmuch_status_t ret;
+
+    Data_Get_Notmuch_Directory (self, dir);
+
+    ret = notmuch_directory_delete (dir);
+    notmuch_rb_status_raise (ret);
+
+    return Qnil;
+}
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index c78242a0..625c6c4d 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -297,6 +297,7 @@ Init_notmuch (void)
     rb_define_method (notmuch_rb_cDirectory, "mtime=", notmuch_rb_directory_set_mtime, 1); /* in directory.c */
     rb_define_method (notmuch_rb_cDirectory, "child_files", notmuch_rb_directory_get_child_files, 0); /* in directory.c */
     rb_define_method (notmuch_rb_cDirectory, "child_directories", notmuch_rb_directory_get_child_directories, 0); /* in directory.c */
+    rb_define_method (notmuch_rb_cDirectory, "delete", notmuch_rb_directory_delete, 0); /* in directory.c */
 
     /*
      * Document-class: Notmuch::FileNames
-- 
2.40.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] ruby: add db.{set,get}_config
  2023-03-31 20:53 [PATCH 0/3] ruby: api updates Felipe Contreras
  2023-03-31 20:53 ` [PATCH 1/3] ruby: add database.revision Felipe Contreras
  2023-03-31 20:53 ` [PATCH 2/3] ruby: add directory.delete Felipe Contreras
@ 2023-03-31 20:53 ` Felipe Contreras
  2023-05-29 11:32   ` David Bremner
  2 siblings, 1 reply; 7+ messages in thread
From: Felipe Contreras @ 2023-03-31 20:53 UTC (permalink / raw)
  To: notmuch

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 bindings/ruby/database.c | 45 ++++++++++++++++++++++++++++++++++++++++
 bindings/ruby/defs.h     |  6 ++++++
 bindings/ruby/init.c     |  2 ++
 3 files changed, 53 insertions(+)

diff --git a/bindings/ruby/database.c b/bindings/ruby/database.c
index 4372afa1..10bdab4e 100644
--- a/bindings/ruby/database.c
+++ b/bindings/ruby/database.c
@@ -497,3 +497,48 @@ notmuch_rb_database_revision (VALUE self)
     rev = notmuch_database_get_revision (db, &uuid);
     return rb_ary_new3(2, INT2FIX (rev), rb_str_new2 (uuid));
 }
+
+/*
+ * call-seq: DB.set_config(key, value) => nil
+ *
+ * Sets configuration key to value.
+ */
+VALUE
+notmuch_rb_database_set_config (VALUE self, VALUE key, VALUE value)
+{
+    notmuch_database_t *db;
+    notmuch_status_t ret;
+    const char *cvalue;
+
+    Data_Get_Notmuch_Database (self, db);
+
+    cvalue = value != Qnil ? RSTRING_PTR (value) : "";
+    ret = notmuch_database_set_config (db, RSTRING_PTR (key), cvalue);
+    notmuch_rb_status_raise (ret);
+
+    return Qnil;
+}
+
+/*
+ * call-seq: DB.get_config(key) => String
+ *
+ * Retrieves a configuration key.
+ */
+VALUE
+notmuch_rb_database_get_config (VALUE self, VALUE key)
+{
+    notmuch_database_t *db;
+    notmuch_status_t ret;
+    char *value;
+    VALUE rvalue;
+
+    Data_Get_Notmuch_Database (self, db);
+
+    ret = notmuch_database_get_config (db, RSTRING_PTR (key), &value);
+    notmuch_rb_status_raise (ret);
+
+    rvalue = rb_str_new2 (value);
+    free (value);
+
+    return rvalue;
+}
diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
index 3ef228b7..352458c8 100644
--- a/bindings/ruby/defs.h
+++ b/bindings/ruby/defs.h
@@ -211,6 +211,12 @@ notmuch_rb_database_query_create (int argc, VALUE *argv, VALUE self);
 VALUE
 notmuch_rb_database_revision (VALUE self);
 
+VALUE
+notmuch_rb_database_set_config (VALUE self, VALUE key, VALUE value);
+
+VALUE
+notmuch_rb_database_get_config (VALUE self, VALUE key);
+
 /* directory.c */
 VALUE
 notmuch_rb_directory_destroy (VALUE self);
diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 625c6c4d..95dc237f 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -284,6 +284,8 @@ Init_notmuch (void)
     rb_define_method (notmuch_rb_cDatabase, "all_tags", notmuch_rb_database_get_all_tags, 0); /* in database.c */
     rb_define_method (notmuch_rb_cDatabase, "query", notmuch_rb_database_query_create, -1); /* in database.c */
     rb_define_method (notmuch_rb_cDatabase, "revision", notmuch_rb_database_revision, 0); /* in database.c */
+    rb_define_method (notmuch_rb_cDatabase, "set_config", notmuch_rb_database_set_config, 2); /* in database.c */
+    rb_define_method (notmuch_rb_cDatabase, "get_config", notmuch_rb_database_get_config, 1); /* in database.c */
 
     /*
      * Document-class: Notmuch::Directory
-- 
2.40.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] ruby: add database.revision
  2023-03-31 20:53 ` [PATCH 1/3] ruby: add database.revision Felipe Contreras
@ 2023-05-29 11:15   ` David Bremner
  0 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2023-05-29 11:15 UTC (permalink / raw)
  To: Felipe Contreras, notmuch

Felipe Contreras <felipe.contreras@gmail.com> writes:

> +
> +/*
> + * call-seq: DB.revision => Array
> + *
> + * Returns the commutted database revision and UUID.

typo.

> + */
> +VALUE
> +notmuch_rb_database_revision (VALUE self)
> +{
> +    notmuch_database_t *db;
> +    unsigned long rev;
> +    const char *uuid;
> +
> +    Data_Get_Notmuch_Database (self, db);
> +
> +    rev = notmuch_database_get_revision (db, &uuid);
> +    return rb_ary_new3(2, INT2FIX (rev), rb_str_new2 (uuid));
> +}

It _looks_ fine, but can we get a test in T395-ruby.sh to confirm?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] ruby: add directory.delete
  2023-03-31 20:53 ` [PATCH 2/3] ruby: add directory.delete Felipe Contreras
@ 2023-05-29 11:24   ` David Bremner
  0 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2023-05-29 11:24 UTC (permalink / raw)
  To: Felipe Contreras, notmuch

Felipe Contreras <felipe.contreras@gmail.com> writes:

> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  bindings/ruby/defs.h      |  3 +++
>  bindings/ruby/directory.c | 19 +++++++++++++++++++
>  bindings/ruby/init.c      |  1 +
>  3 files changed, 23 insertions(+)
>
> diff --git a/bindings/ruby/defs.h b/bindings/ruby/defs.h
> index c4943681..3ef228b7 100644
> --- a/bindings/ruby/defs.h
> +++ b/bindings/ruby/defs.h
> @@ -227,6 +227,9 @@ notmuch_rb_directory_get_child_files (VALUE self);
>  VALUE
>  notmuch_rb_directory_get_child_directories (VALUE self);
>  
> +VALUE
> +notmuch_rb_directory_delete (VALUE self);
> +
>  /* filenames.c */
>  VALUE
>  notmuch_rb_filenames_destroy (VALUE self);
> diff --git a/bindings/ruby/directory.c b/bindings/ruby/directory.c
> index 910f0a99..2fb22c70 100644
> --- a/bindings/ruby/directory.c
> +++ b/bindings/ruby/directory.c
> @@ -108,3 +108,22 @@ notmuch_rb_directory_get_child_directories (VALUE self)
>  
>      return Data_Wrap_Notmuch_Object (notmuch_rb_cFileNames, &notmuch_rb_filenames_type, fnames);
>  }
> +
> +/*
> + * call-seq: DIR.delete => nil
> + *
> + * Delete directory from the database.
> + */
> +VALUE
> +notmuch_rb_directory_delete (VALUE self)
> +{
> +    notmuch_directory_t *dir;
> +    notmuch_status_t ret;
> +
> +    Data_Get_Notmuch_Directory (self, dir);
> +
> +    ret = notmuch_directory_delete (dir);
> +    notmuch_rb_status_raise (ret);
> +
> +    return Qnil;
> +}

I don't mind if tests come in later patches or in the patch that
introduces new API, but please add a test every time the ruby bindings
API grows.

d

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] ruby: add db.{set,get}_config
  2023-03-31 20:53 ` [PATCH 3/3] ruby: add db.{set,get}_config Felipe Contreras
@ 2023-05-29 11:32   ` David Bremner
  0 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2023-05-29 11:32 UTC (permalink / raw)
  To: Felipe Contreras, notmuch

Felipe Contreras <felipe.contreras@gmail.com> writes:

> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---
>  bindings/ruby/database.c | 45 ++++++++++++++++++++++++++++++++++++++++
>  bindings/ruby/defs.h     |  6 ++++++
>  bindings/ruby/init.c     |  2 ++
>  3 files changed, 53 insertions(+)

So, usual request about tests...


> +/*
> + * call-seq: DB.get_config(key) => String
> + *
> + * Retrieves a configuration key.
> + */
> +VALUE
> +notmuch_rb_database_get_config (VALUE self, VALUE key)
> +{
> +    notmuch_database_t *db;
> +    notmuch_status_t ret;
> +    char *value;
> +    VALUE rvalue;
> +
> +    Data_Get_Notmuch_Database (self, db);
> +
> +    ret = notmuch_database_get_config (db, RSTRING_PTR (key), &value);
> +    notmuch_rb_status_raise (ret);
> +
> +    rvalue = rb_str_new2 (value);
> +    free (value);
> +
> +    return rvalue;
> +}

Just to be clear, there are (confusingly) two APIs for reading
configuration. The one you are binding is in some sense the most low
level and general but it might be good to encourage use of
notmuch_config_get, since the use of an enum makes it less error-prone
for well-known configuration values.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-05-29 11:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-31 20:53 [PATCH 0/3] ruby: api updates Felipe Contreras
2023-03-31 20:53 ` [PATCH 1/3] ruby: add database.revision Felipe Contreras
2023-05-29 11:15   ` David Bremner
2023-03-31 20:53 ` [PATCH 2/3] ruby: add directory.delete Felipe Contreras
2023-05-29 11:24   ` David Bremner
2023-03-31 20:53 ` [PATCH 3/3] ruby: add db.{set,get}_config Felipe Contreras
2023-05-29 11:32   ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).